feat: Add account pages
Signed-off-by: Florian BOUILLON <f.bouillon@aptatio.com>
This commit is contained in:
parent
eac88b2ec3
commit
dc80dec6a8
@ -1,6 +1,4 @@
|
|||||||
---
|
---
|
||||||
const json = JSON.stringify(Astro.props)
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* note: you MUST only pass simple items that can go in JSON format natively
|
* note: you MUST only pass simple items that can go in JSON format natively
|
||||||
*/
|
*/
|
||||||
@ -12,5 +10,6 @@ export function load<T extends {} = {}>(): T {
|
|||||||
return JSON.parse(tag.innerText)
|
return JSON.parse(tag.innerText)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const json = JSON.stringify(Astro.props)
|
||||||
---
|
---
|
||||||
<script id="ASTRO_DATA" is:inline type="application/json" set:html={json}></script>
|
<script id="ASTRO_DATA" is:inline type="application/json" set:html={json}></script>
|
||||||
|
47
src/pages/account/login.astro
Normal file
47
src/pages/account/login.astro
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
---
|
||||||
|
import URLManager from '@dzeio/url-manager'
|
||||||
|
import Layout from '../../layouts/Layout.astro'
|
||||||
|
import DaoFactory from '../../models/DaoFactory'
|
||||||
|
import { comparePassword } from '../../libs/AuthUtils'
|
||||||
|
|
||||||
|
const logout = new URLManager(Astro.url).query('logout')
|
||||||
|
|
||||||
|
if (typeof logout === 'string') {
|
||||||
|
DaoFactory.get('session').removeSession(Astro.response)
|
||||||
|
}
|
||||||
|
|
||||||
|
// DaoFactory.get('session').removeSession(Astro.response)
|
||||||
|
|
||||||
|
if (Astro.request.method === 'POST') {
|
||||||
|
const form = await Astro.request.formData()
|
||||||
|
const email = form.get('email') as string
|
||||||
|
const password = form.get('password') as string
|
||||||
|
|
||||||
|
const account = await DaoFactory.get('user').findOne({
|
||||||
|
email
|
||||||
|
})
|
||||||
|
|
||||||
|
if (!account) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const valid = await comparePassword(password, account.password)
|
||||||
|
if (!valid) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
DaoFactory.get('session').setSession({
|
||||||
|
userId: account.id
|
||||||
|
}, Astro.response)
|
||||||
|
}
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
<Layout title="Welcome to Astro.">
|
||||||
|
<main>
|
||||||
|
<form>
|
||||||
|
<input type="email" name="email" />
|
||||||
|
<input type="password" name="password" />
|
||||||
|
<button>Connect</button>
|
||||||
|
<button></button>
|
||||||
|
</form>
|
||||||
|
</main>
|
||||||
|
</Layout>
|
4
src/pages/account/logout.astro
Normal file
4
src/pages/account/logout.astro
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
---
|
||||||
|
return Astro.redirect('/account/login?logout')
|
||||||
|
|
||||||
|
---
|
45
src/pages/account/register.astro
Normal file
45
src/pages/account/register.astro
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
---
|
||||||
|
import Layout from '../../layouts/Layout.astro'
|
||||||
|
import { hashPassword } from '../../libs/AuthUtils'
|
||||||
|
import DaoFactory from '../../models/DaoFactory'
|
||||||
|
|
||||||
|
let errorMessage: string | undefined
|
||||||
|
|
||||||
|
if (Astro.request.method === 'POST') {
|
||||||
|
const form = await Astro.request.formData()
|
||||||
|
const email = form.get('email') as string
|
||||||
|
const password = form.get('password') as string
|
||||||
|
|
||||||
|
const user = await DaoFactory.get('user').create({
|
||||||
|
email: email,
|
||||||
|
password: await hashPassword(password)
|
||||||
|
})
|
||||||
|
|
||||||
|
if (!user) {
|
||||||
|
errorMessage = 'User already exists'
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
DaoFactory.get('session').setSession({
|
||||||
|
userId: user.id
|
||||||
|
}, Astro.response)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
<Layout title="Welcome to Astro.">
|
||||||
|
<main>
|
||||||
|
{errorMessage && (
|
||||||
|
<div>
|
||||||
|
{errorMessage}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
<form method="post">
|
||||||
|
<input type="email" name="email" id="email"/>
|
||||||
|
<input type="password" name="password" id="password" />
|
||||||
|
<input type="password" name="repeat-password" id="repeat-password">
|
||||||
|
<button>Register</button>
|
||||||
|
</form>
|
||||||
|
</main>
|
||||||
|
</Layout>
|
Loading…
x
Reference in New Issue
Block a user