diff options
Diffstat (limited to 'app/Controllers/Http/Dashboard/ForgotPasswordController.ts')
-rw-r--r-- | app/Controllers/Http/Dashboard/ForgotPasswordController.ts | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/app/Controllers/Http/Dashboard/ForgotPasswordController.ts b/app/Controllers/Http/Dashboard/ForgotPasswordController.ts new file mode 100644 index 0000000..da05bbd --- /dev/null +++ b/app/Controllers/Http/Dashboard/ForgotPasswordController.ts | |||
@@ -0,0 +1,41 @@ | |||
1 | import type { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'; | ||
2 | import { schema, rules, validator } from '@ioc:Adonis/Core/Validator'; | ||
3 | import User from 'App/Models/User'; | ||
4 | |||
5 | export default class ForgotPasswordController { | ||
6 | /** | ||
7 | * Display the forgot password form | ||
8 | */ | ||
9 | public async show({ view }: HttpContextContract) { | ||
10 | return view.render('dashboard/forgotPassword'); | ||
11 | } | ||
12 | |||
13 | /** | ||
14 | * Send forget password email to user | ||
15 | */ | ||
16 | public async forgotPassword({ view, request }: HttpContextContract) { | ||
17 | try { | ||
18 | await validator.validate({ | ||
19 | schema: schema.create({ | ||
20 | mail: schema.string([rules.email(), rules.required()]), | ||
21 | }), | ||
22 | data: request.only(['mail']), | ||
23 | }); | ||
24 | } catch { | ||
25 | return view.render('others/message', { | ||
26 | heading: 'Cannot reset your password', | ||
27 | text: 'Please enter a valid email address', | ||
28 | }); | ||
29 | } | ||
30 | |||
31 | try { | ||
32 | const user = await User.findByOrFail('email', request.input('mail')); | ||
33 | await user.forgotPassword(); | ||
34 | } catch {} | ||
35 | |||
36 | return view.render('others/message', { | ||
37 | heading: 'Reset password', | ||
38 | text: 'If your provided E-Mail address is linked to an account, we have just sent an E-Mail to that address.', | ||
39 | }); | ||
40 | } | ||
41 | } | ||