diff --git a/app/Controllers/Http/AuthController.ts b/app/Controllers/Http/AuthController.ts index e5815cdc..d010fbb6 100644 --- a/app/Controllers/Http/AuthController.ts +++ b/app/Controllers/Http/AuthController.ts @@ -21,6 +21,7 @@ export default class AuthController { response.redirect().toRoute('login') } } + async signup({ view }: HttpContextContract) { return view.render('auth/signup') @@ -31,4 +32,10 @@ export default class AuthController { await User.create(playload) return response.redirect().toRoute('home') } + + + async logout({ auth, response }:HttpContextContract) { + await auth.logout() + return response.redirect().back() + } } diff --git a/app/Controllers/Http/CompteController.ts b/app/Controllers/Http/CompteController.ts new file mode 100644 index 00000000..a1a6ab9f --- /dev/null +++ b/app/Controllers/Http/CompteController.ts @@ -0,0 +1,33 @@ +import type { HttpContextContract } from '@ioc:Adonis/Core/HttpContext' +import ModifPseudoValidator from 'App/Validators/ModifPseudoValidator' +import ModifEmailValidator from 'App/Validators/ModifEmailValidator' + +export default class CompteController { + + async index({ view }: HttpContextContract) { + return view.render('compte') + } + + async modifpseudo({ request, auth, session, response }: HttpContextContract) { + const user = auth.user + + await request.validate(ModifPseudoValidator) + + user!.pseudo = request.input('pseudo') + await user!.save() + session.flash({success: "Username updated successfully"}) + response.redirect().back() + } + + async modifemail({ request, auth, session, response }: HttpContextContract) { + const user = auth.user + + await request.validate(ModifEmailValidator) + + user!.email = request.input('email') + await user!.save() + session.flash({success: "Email updated successfully"}) + response.redirect().back() + } + +} diff --git a/app/Validators/ModifEmailValidator.ts b/app/Validators/ModifEmailValidator.ts new file mode 100644 index 00000000..564a70bd --- /dev/null +++ b/app/Validators/ModifEmailValidator.ts @@ -0,0 +1,46 @@ +import { schema, CustomMessages, rules } from '@ioc:Adonis/Core/Validator' +import type { HttpContextContract } from '@ioc:Adonis/Core/HttpContext' + +export default class ModifEmailValidator { + constructor(protected ctx: HttpContextContract) {} + + /* + * Define schema to validate the "shape", "type", "formatting" and "integrity" of data. + * + * For example: + * 1. The username must be of data type string. But then also, it should + * not contain special characters or numbers. + * ``` + * schema.string([ rules.alpha() ]) + * ``` + * + * 2. The email must be of data type string, formatted as a valid + * email. But also, not used by any other user. + * ``` + * schema.string([ + * rules.email(), + * rules.unique({ table: 'users', column: 'email' }), + * ]) + * ``` + */ + public schema = schema.create({ + email: schema.string({}, [rules.email(), rules.unique({ table: 'users', column: 'email' }) ]) + }) + + /** + * Custom messages for validation failures. You can make use of dot notation `(.)` + * for targeting nested fields and array expressions `(*)` for targeting all + * children of an array. For example: + * + * { + * 'profile.username.required': 'Username is required', + * 'scores.*.number': 'Define scores as valid numbers' + * } + * + */ + public messages: CustomMessages = { + required: 'The {{ field }} is required to modifie email', + 'email.email': 'You must enter an email in the email field', + 'email.unique': 'Email is already in use' + } +} diff --git a/app/Validators/ModifPseudoValidator.ts b/app/Validators/ModifPseudoValidator.ts new file mode 100644 index 00000000..5249f82f --- /dev/null +++ b/app/Validators/ModifPseudoValidator.ts @@ -0,0 +1,45 @@ +import { schema, CustomMessages, rules } from '@ioc:Adonis/Core/Validator' +import type { HttpContextContract } from '@ioc:Adonis/Core/HttpContext' + +export default class ModifPseudoValidator { + constructor(protected ctx: HttpContextContract) {} + + /* + * Define schema to validate the "shape", "type", "formatting" and "integrity" of data. + * + * For example: + * 1. The username must be of data type string. But then also, it should + * not contain special characters or numbers. + * ``` + * schema.string([ rules.alpha() ]) + * ``` + * + * 2. The email must be of data type string, formatted as a valid + * email. But also, not used by any other user. + * ``` + * schema.string([ + * rules.email(), + * rules.unique({ table: 'users', column: 'email' }), + * ]) + * ``` + */ + public schema = schema.create({ + pseudo: schema.string({}, [rules.minLength(3)]) + }) + + /** + * Custom messages for validation failures. You can make use of dot notation `(.)` + * for targeting nested fields and array expressions `(*)` for targeting all + * children of an array. For example: + * + * { + * 'profile.username.required': 'Username is required', + * 'scores.*.number': 'Define scores as valid numbers' + * } + * + */ + public messages: CustomMessages = { + required: 'The {{ field }} is required to modifie pseudo', + 'pseudo.minLength': 'The pseudo must be at least 3 characters long' + } +} diff --git a/resources/views/components/form/form.edge b/resources/views/components/form/form.edge index 1f91dda3..5409bd2e 100644 --- a/resources/views/components/form/form.edge +++ b/resources/views/components/form/form.edge @@ -1,4 +1,7 @@
- @!component('components/flash') + @if(flash) + @else + @!component('components/flash') + @end {{{ await $slots.main() }}}
\ No newline at end of file diff --git a/resources/views/components/select_theme.edge b/resources/views/components/select_theme.edge index 5f3ecec2..753b3d9c 100644 --- a/resources/views/components/select_theme.edge +++ b/resources/views/components/select_theme.edge @@ -22,7 +22,7 @@ + viewBox="0 0 24 24" fill="none" class="w-6 h-6 "> @@ -36,7 +36,7 @@ + class="w-6 h-6"> + + @!component('components/flash') + +

Welcome {{ auth.user.pseudo }}

+ + return to home page + +
+

Here is your personal information:

+

pseudo : {{ auth.user.pseudo }}

+

email : {{ auth.user.email }}

+

created at : {{ auth.user.createdAt }}

+
+ +
+

You can modify your personal information:

+ + @component('components/form/form', { + 'action': 'modifpseudo', + 'method': 'post', + 'flash': 'not', + }) + @!component('components/form/field', { + 'label': 'Pseudo :', + 'name': 'pseudo', + 'type': 'text', + 'required': true, + 'placeholder': 'new pseudo', + }) + @!component('components/form/button', { + 'type': 'submit', + 'text': 'Envoyer', + }) + @end + +
+ + @component('components/form/form', { + 'action': 'modifemail', + 'method': 'post', + 'flash': 'not', + }) + @!component('components/form/field', { + 'label': 'Email :', + 'name': 'email', + 'type': 'text', + 'required': true, + 'placeholder': 'new email', + }) + @!component('components/form/button', { + 'type': 'submit', + 'text': 'Envoyer', + }) + @end +
+ + + +@end \ No newline at end of file diff --git a/resources/views/home.edge b/resources/views/home.edge index 2d64c280..c03a8675 100644 --- a/resources/views/home.edge +++ b/resources/views/home.edge @@ -14,4 +14,4 @@ @include('partials/footer') -@end +@end \ No newline at end of file diff --git a/resources/views/partials/header.edge b/resources/views/partials/header.edge index 1e0f0ab7..cd615633 100644 --- a/resources/views/partials/header.edge +++ b/resources/views/partials/header.edge @@ -1,4 +1,4 @@ -
+

Hi! 👋🏻
I'm Arthur.

Founder

diff --git a/resources/views/partials/main/about.edge b/resources/views/partials/main/about.edge index 8cf75828..9727e757 100644 --- a/resources/views/partials/main/about.edge +++ b/resources/views/partials/main/about.edge @@ -1,4 +1,4 @@ -
+

About

Hi ! I'm Arthur, a passionate developer based in France. My journey in the world of development is an inspiring adventure. Every line of code I write is a step toward creating unique and engaging experiences. I am driven by the desire to bring ideas to life and shape them into innovative designs.

diff --git a/resources/views/partials/main/contact.edge b/resources/views/partials/main/contact.edge index ebb7ae97..5f9ffe8f 100644 --- a/resources/views/partials/main/contact.edge +++ b/resources/views/partials/main/contact.edge @@ -1,4 +1,4 @@ -
+

Contact

@component('components/form/form', { @@ -10,14 +10,14 @@ 'name': 'nom', 'type': 'text', 'required': true, - 'placeholder': 'Votre nom', + 'placeholder': 'nom', }) @!component('components/form/field', { 'label': 'E-mail :', 'name': 'email', 'type': 'email', 'required': true, - 'placeholder': 'prenom.nom@mail.com', + 'placeholder': 'exemple@mail.com', }) @!component('components/form/field', { 'label': 'Message :', diff --git a/resources/views/partials/main/projects.edge b/resources/views/partials/main/projects.edge index 3462a0c9..a0e0547d 100644 --- a/resources/views/partials/main/projects.edge +++ b/resources/views/partials/main/projects.edge @@ -1,4 +1,4 @@ -
+

Projects

diff --git a/resources/views/partials/nav.edge b/resources/views/partials/nav.edge index 18cc6578..44c0d3f2 100644 --- a/resources/views/partials/nav.edge +++ b/resources/views/partials/nav.edge @@ -53,15 +53,14 @@
@else - {{ auth.user }} - Login - Signup + Login + Signup @end
diff --git a/start/routes.ts b/start/routes.ts index b4f0662d..2bc6fe5f 100644 --- a/start/routes.ts +++ b/start/routes.ts @@ -31,4 +31,10 @@ Route.get('/terms', async ({ view }) => { Route.get('/auth/login', 'AuthController.login').as('login') Route.post('/auth/login', 'AuthController.doLogin') Route.get('/auth/signup', 'AuthController.signup').as('signup') -Route.post('/auth/signup', 'AuthController.doSignup') \ No newline at end of file +Route.post('/auth/signup', 'AuthController.doSignup') + +Route.get('/compte', 'CompteController.index').as('compte') +Route.post('/modifpseudo', 'CompteController.modifpseudo') +Route.post('/modifemail', 'CompteController.modifemail') + +Route.get('/auth/logout', 'AuthController.logout').as('logout') diff --git a/tmp/db.sqlite3 b/tmp/db.sqlite3 index 88f3732c..f1f831bf 100644 Binary files a/tmp/db.sqlite3 and b/tmp/db.sqlite3 differ