Compare commits
10 Commits
fix-SSR-wi
...
f863a918bf
Author | SHA1 | Date | |
---|---|---|---|
f863a918bf | |||
56345d9933 | |||
564a18ea28 | |||
362b0e7af7 | |||
f53f19dc93 | |||
9a4357394a | |||
41ed285326 | |||
2b11a223cd | |||
9116a1544e | |||
5f642a6aa0 |
30
bruno/OpenData datatourisme/Google API.bru
Normal file
30
bruno/OpenData datatourisme/Google API.bru
Normal file
@ -0,0 +1,30 @@
|
||||
meta {
|
||||
name: Google API
|
||||
type: http
|
||||
seq: 3
|
||||
}
|
||||
|
||||
post {
|
||||
url: https://places.googleapis.com/v1/places:searchNearby
|
||||
body: json
|
||||
auth: none
|
||||
}
|
||||
|
||||
headers {
|
||||
X-Goog-Api-Key: {{GOOGLE_API_KEY}}
|
||||
}
|
||||
|
||||
body:json {
|
||||
{
|
||||
"includedTypes": ["restaurant"],
|
||||
"maxResultCount": 10,
|
||||
"locationRestriction": {
|
||||
"circle": {
|
||||
"center": {
|
||||
"latitude": 37.7937,
|
||||
"longitude": -122.3965},
|
||||
"radius": 500.0
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,3 +1,4 @@
|
||||
vars:secret [
|
||||
app_key
|
||||
app_key,
|
||||
GOOGLE_API_KEY
|
||||
]
|
||||
|
11
bruno/OpenData datatourisme/list oaut methode.bru
Normal file
11
bruno/OpenData datatourisme/list oaut methode.bru
Normal file
@ -0,0 +1,11 @@
|
||||
meta {
|
||||
name: list oaut methode
|
||||
type: http
|
||||
seq: 5
|
||||
}
|
||||
|
||||
get {
|
||||
url: https://pb-tweb.cb85.fr/api/collections/users/auth-methods
|
||||
body: none
|
||||
auth: none
|
||||
}
|
18
bruno/OpenData datatourisme/oauth test.bru
Normal file
18
bruno/OpenData datatourisme/oauth test.bru
Normal file
@ -0,0 +1,18 @@
|
||||
meta {
|
||||
name: oauth test
|
||||
type: http
|
||||
seq: 4
|
||||
}
|
||||
|
||||
post {
|
||||
url: https://pb-tweb.cb85.fr/api/collections/users/auth-with-oauth2
|
||||
body: json
|
||||
auth: none
|
||||
}
|
||||
|
||||
body:json {
|
||||
{
|
||||
provider: "google"
|
||||
|
||||
}
|
||||
}
|
1479
front/package-lock.json
generated
1479
front/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -19,6 +19,7 @@
|
||||
"@types/react": "^18.2.79",
|
||||
"@types/react-dom": "^18.2.25",
|
||||
"astro": "4.5.12",
|
||||
"cross-fetch": "^4.0.0",
|
||||
"leaflet": "^1.9.4",
|
||||
"lucide-astro": "^0.372.0",
|
||||
"pocketbase": "^0.21.1",
|
||||
@ -39,6 +40,7 @@
|
||||
"@vitest/coverage-v8": "^1",
|
||||
"eslint": "^8.57.0",
|
||||
"eslint-plugin-astro": "^0.31.4",
|
||||
"eslint-plugin-jsx-a11y": "^6.8.0",
|
||||
"typescript": "^5",
|
||||
"vitest": "^1"
|
||||
}
|
||||
|
19
front/src/env.d.ts
vendored
19
front/src/env.d.ts
vendored
@ -16,10 +16,17 @@ interface ImportMeta {
|
||||
}
|
||||
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-namespace
|
||||
declare namespace App {
|
||||
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
||||
export interface Locals {
|
||||
pb: PocketBase
|
||||
}
|
||||
// declare namespace App {
|
||||
// interface Locals {
|
||||
// pb: PocketBase
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
declare global {
|
||||
namespace App {
|
||||
interface Locals {
|
||||
pb: PocketBase
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,107 +0,0 @@
|
||||
import type { AstroCookies } from 'astro'
|
||||
import type UserObj from 'models/User'
|
||||
import PocketBase from 'pocketbase'
|
||||
import { getEnv } from 'libs/Env'
|
||||
|
||||
|
||||
const pb = new PocketBase(getEnv('POCKETBASE_URL','https://pb-tweb.cb85.fr')) // XXX: 'https://pb-tweb.cb85.fr'
|
||||
|
||||
export async function clearUser(cookies: AstroCookies): Promise<void> {
|
||||
const sessionID = cookies.get('session')?.value
|
||||
|
||||
if(!sessionID){
|
||||
return
|
||||
}
|
||||
|
||||
cookies.delete('session',{
|
||||
path: '/'
|
||||
})
|
||||
}
|
||||
|
||||
export async function login(cookies: AstroCookies, user: {user: string, password: string}): Promise<boolean> {
|
||||
|
||||
const authData = await pb.collection('users').authWithPassword(user.user, user.password)
|
||||
|
||||
let secure = true
|
||||
|
||||
if (getEnv('NODE_ENV', 'production') !== 'production') {
|
||||
secure = false
|
||||
}
|
||||
|
||||
if(authData){
|
||||
cookies.set('session', authData.token,{
|
||||
httpOnly: true,
|
||||
path: '/',
|
||||
secure: secure,
|
||||
sameSite: 'strict',
|
||||
maxAge: 365000,
|
||||
})
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
export async function getUser(cookies: AstroCookies): Promise<UserObj | null> {
|
||||
const sessionID = cookies.get('session')?.value
|
||||
|
||||
const bpAuth = pb.authStore
|
||||
|
||||
if(!sessionID){
|
||||
return null
|
||||
}
|
||||
if(!bpAuth.isValid){
|
||||
return null
|
||||
}
|
||||
if(!bpAuth){
|
||||
return null
|
||||
}
|
||||
|
||||
console.log(bpAuth.model)
|
||||
|
||||
if(!bpAuth.model){
|
||||
return null
|
||||
}
|
||||
|
||||
const output: UserObj = {
|
||||
id: bpAuth.model.id as string,
|
||||
collectionId: bpAuth.model.collectionId as string,
|
||||
collectionName: bpAuth.model.collectionName as string,
|
||||
created: bpAuth.model.created as string,
|
||||
updated: bpAuth.model.updated as string,
|
||||
avatar: bpAuth.model.avatar as string,
|
||||
username: bpAuth.model.username as string,
|
||||
email: bpAuth.model.email as string,
|
||||
emailVisibility: false,
|
||||
name: bpAuth.model.name as string,
|
||||
password: undefined,
|
||||
passwordConfirm: undefined,
|
||||
}
|
||||
|
||||
return output
|
||||
|
||||
}
|
||||
|
||||
export async function setUser(cookies: AstroCookies, user: UserObj): Promise<void>{
|
||||
|
||||
const record = await pb.collection('users').create(user)
|
||||
|
||||
console.log(record)
|
||||
|
||||
const session = pb.authStore.token
|
||||
|
||||
console.log(session)
|
||||
|
||||
let secure = true
|
||||
|
||||
if (getEnv('NODE_ENV', 'production') !== 'production') {
|
||||
secure = false
|
||||
}
|
||||
|
||||
cookies.set('session', session,{
|
||||
httpOnly: true,
|
||||
path: '/',
|
||||
secure: secure,
|
||||
sameSite: 'strict',
|
||||
maxAge: 365000,
|
||||
})
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
|
||||
|
||||
export interface PBData{
|
||||
id?: string | null
|
||||
collectionId?: string | null
|
||||
collectionName?: string | null
|
||||
created?: string | null // TODO: passé ca en date auto
|
||||
updated?: string | null // TODO: passé ca en date auto
|
||||
}
|
||||
|
||||
export default interface UserObj extends PBData{
|
||||
avatar?: string | null
|
||||
username: string
|
||||
email: string
|
||||
emailVisibility?: boolean
|
||||
password?: string | undefined
|
||||
passwordConfirm?: string | undefined
|
||||
name: string | null
|
||||
}
|
@ -3,7 +3,7 @@ import Layout from 'layouts/Layout.astro'
|
||||
import PocketBase from 'pocketbase'
|
||||
|
||||
|
||||
const pb = Astro.locals.pb as PocketBase
|
||||
const pb = Astro.locals.pb
|
||||
const auth = pb.authStore
|
||||
const user = auth.model
|
||||
|
||||
@ -15,4 +15,7 @@ if(!auth.isValid){
|
||||
|
||||
<Layout title="Account setting">
|
||||
<h1>Bonjour {user!.name}</h1>
|
||||
<div>
|
||||
<a href="/account/logout">deconnexion</a>
|
||||
</div>
|
||||
</Layout>
|
||||
|
@ -4,7 +4,7 @@ import AstroUtils from "libs/AstroUtils";
|
||||
import PocketBase from 'pocketbase'
|
||||
|
||||
|
||||
const pb = Astro.locals.pb as PocketBase
|
||||
const pb = Astro.locals.pb
|
||||
|
||||
if(pb.authStore.isValid){
|
||||
return Astro.redirect("/account")
|
||||
@ -13,10 +13,7 @@ if(pb.authStore.isValid){
|
||||
const res = await AstroUtils.wrap(async () => {
|
||||
if (Astro.request.method !== 'POST') {
|
||||
return
|
||||
}
|
||||
// FIXME checké si utilisateur deja connecté
|
||||
const locals = Astro.locals
|
||||
|
||||
}
|
||||
const form = await Astro.request.formData();
|
||||
const request = {
|
||||
user: form.get("username") as string,
|
||||
@ -24,13 +21,13 @@ const res = await AstroUtils.wrap(async () => {
|
||||
}
|
||||
|
||||
try {
|
||||
await locals.pb.collection('users').authWithPassword(request.user,request.password);
|
||||
await pb.collection('users').authWithPassword(request.user,request.password);
|
||||
return Astro.redirect("/account")
|
||||
} catch (error) {
|
||||
console.log(error)
|
||||
console.warn('user password is incorrect')
|
||||
return Astro.redirect("/account/login");// route('/account/login', {message: 'Compte invalide, valider les identifiants'})) //XXX: comprendre comment le system de route fonctionne
|
||||
}
|
||||
|
||||
return Astro.redirect("/account")
|
||||
|
||||
})
|
||||
---
|
||||
|
||||
|
13
front/src/pages/account/logout.astro
Normal file
13
front/src/pages/account/logout.astro
Normal file
@ -0,0 +1,13 @@
|
||||
---
|
||||
import PocketBase from 'pocketbase'
|
||||
|
||||
|
||||
const pb = Astro.locals.pb
|
||||
|
||||
if(pb.authStore.isValid){
|
||||
pb.authStore.clear()
|
||||
}
|
||||
|
||||
return Astro.redirect('/account/login')
|
||||
|
||||
---
|
@ -1,10 +1,10 @@
|
||||
---
|
||||
import Layout from 'layouts/Layout.astro';
|
||||
import AstroUtils from 'libs/AstroUtils';
|
||||
import PocketBase from 'pocketbase'
|
||||
|
||||
const pb = Astro.locals.pb
|
||||
|
||||
const pb = Astro.locals.pb as PocketBase
|
||||
const oauths = await pb.collection('users').listAuthMethods();
|
||||
|
||||
if(pb.authStore.isValid){
|
||||
return Astro.redirect("/account")
|
||||
@ -15,24 +15,34 @@ await AstroUtils.wrap(async () => {
|
||||
return
|
||||
}
|
||||
const form = await Astro.request.formData()
|
||||
const request = {
|
||||
username: form.get("username") as string,
|
||||
name: form.get("name") as string,
|
||||
email: form.get("email") as string,
|
||||
password: form.get("password") as string,
|
||||
passwordConfirm: form.get("passwordConfirm") as string,
|
||||
}
|
||||
try{
|
||||
await pb.collection('users').create(request)
|
||||
return Astro.redirect('account/login')
|
||||
}catch(e){
|
||||
console.log(e);
|
||||
if(form.get("type") == "userPassword"){
|
||||
const request = {
|
||||
username: form.get("username") as string,
|
||||
name: form.get("name") as string,
|
||||
email: form.get("email") as string,
|
||||
password: form.get("password") as string,
|
||||
passwordConfirm: form.get("passwordConfirm") as string,
|
||||
}
|
||||
try{
|
||||
await pb.collection('users').create(request)
|
||||
return Astro.redirect('/account/login')
|
||||
}catch(e){
|
||||
console.log(e);
|
||||
}
|
||||
}else if (form.get("type") == "discord2FA") {
|
||||
// console.log("pouet")
|
||||
// await pb.collection('user').authWithOAuth2({provider: 'discord'})
|
||||
// console.log("pouetF");
|
||||
|
||||
}else{
|
||||
Astro.redirect("/404")
|
||||
}
|
||||
})
|
||||
---
|
||||
|
||||
<Layout title="register">
|
||||
<form id="account-creation" method="post" enctype="multipart/form-data">
|
||||
<input type="hidden" name="type" value="userPassword">
|
||||
<input required name="name" placeholder="Prénom Nom"/>
|
||||
<input required name="username" placeholder="Pseudo"/>
|
||||
<input required name="email" type="email" placeholder="Renseignez votre email" />
|
||||
@ -40,4 +50,26 @@ await AstroUtils.wrap(async () => {
|
||||
<input required name="passwordConfirm" type="password" placeholder="Confirmer votre mot de passe" />
|
||||
<button>Créer un compte</button>
|
||||
</form>
|
||||
</Layout>
|
||||
|
||||
<button id="OauthDiscord">connexion avec discord</button>
|
||||
<form method="post" enctype="multipart/form-data">
|
||||
<input type="hidden" name="type" value="discord2FA">
|
||||
</form>
|
||||
<a href={oauths.authProviders[1].authUrl + "https%3A%2F%2Fpb-tweb.cb85.fr%2Fapi%2Foauth2-redirect"}>discord?</a>
|
||||
</Layout>
|
||||
|
||||
<script>
|
||||
import 'cross-fetch/polyfill';
|
||||
import PocketBase from "pocketbase"
|
||||
import type { OAuth2UrlCallback } from "pocketbase"
|
||||
const pb = new PocketBase("https://pb-tweb.cb85.fr/")
|
||||
const discordBtn = document.querySelector<HTMLButtonElement>("#OauthDiscord")
|
||||
|
||||
if (discordBtn) {
|
||||
discordBtn.addEventListener('click', async () =>{
|
||||
const result = await pb.collection('users').listAuthMethods();
|
||||
fetch(result.authProviders[0].authUrl)
|
||||
console.log(result);
|
||||
})
|
||||
}
|
||||
</script>
|
Reference in New Issue
Block a user