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