diff options
Diffstat (limited to 'app/Controllers/Http/DashboardController.js')
-rw-r--r-- | app/Controllers/Http/DashboardController.js | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/app/Controllers/Http/DashboardController.js b/app/Controllers/Http/DashboardController.js index a47beb6..3de4816 100644 --- a/app/Controllers/Http/DashboardController.js +++ b/app/Controllers/Http/DashboardController.js | |||
@@ -5,6 +5,7 @@ const { | |||
5 | 5 | ||
6 | const Service = use('App/Models/Service'); | 6 | const Service = use('App/Models/Service'); |
7 | const Workspace = use('App/Models/Workspace'); | 7 | const Workspace = use('App/Models/Workspace'); |
8 | const Persona = use('Persona'); | ||
8 | 9 | ||
9 | const crypto = require('crypto'); | 10 | const crypto = require('crypto'); |
10 | const uuid = require('uuid/v4'); | 11 | const uuid = require('uuid/v4'); |
@@ -47,6 +48,66 @@ class DashboardController { | |||
47 | return response.redirect('/user/account'); | 48 | return response.redirect('/user/account'); |
48 | } | 49 | } |
49 | 50 | ||
51 | async forgotPassword({ | ||
52 | request, | ||
53 | view, | ||
54 | }) { | ||
55 | const validation = await validateAll(request.all(), { | ||
56 | mail: 'required|email', | ||
57 | }); | ||
58 | if (validation.fails()) { | ||
59 | return view.render('others.message', { | ||
60 | heading: 'Cannot reset your password', | ||
61 | text: 'If your provided E-Mail address is linked to an account, we have just sent an E-Mail to that address.', | ||
62 | }); | ||
63 | } | ||
64 | try { | ||
65 | await Persona.forgotPassword(request.input('mail')); | ||
66 | } catch(e) {} | ||
67 | |||
68 | return view.render('others.message', { | ||
69 | heading: 'Reset password', | ||
70 | text: 'If your provided E-Mail address is linked to an account, we have just sent an E-Mail to that address.', | ||
71 | }); | ||
72 | } | ||
73 | |||
74 | async resetPassword({ | ||
75 | request, | ||
76 | view, | ||
77 | }) { | ||
78 | const validation = await validateAll(request.all(), { | ||
79 | password: 'required', | ||
80 | password_confirmation: 'required', | ||
81 | token: 'required', | ||
82 | }); | ||
83 | if (validation.fails()) { | ||
84 | session.withErrors({ | ||
85 | type: 'danger', | ||
86 | message: 'Passwords do not match', | ||
87 | }); | ||
88 | return response.redirect('back'); | ||
89 | } | ||
90 | |||
91 | const payload = { | ||
92 | password: crypto.createHash('sha256').update(request.input('password')).digest('base64'), | ||
93 | password_confirmation: crypto.createHash('sha256').update(request.input('password_confirmation')).digest('base64'), | ||
94 | } | ||
95 | |||
96 | try { | ||
97 | await Persona.updatePasswordByToken(request.input('token'), payload); | ||
98 | } catch(e) { | ||
99 | return view.render('others.message', { | ||
100 | heading: 'Cannot reset your password', | ||
101 | text: 'Please make sure you are using a valid and recent link to reset your password and that your passwords entered match.', | ||
102 | }); | ||
103 | } | ||
104 | |||
105 | return view.render('others.message', { | ||
106 | heading: 'Reset password', | ||
107 | text: 'Successfully reset your password. You can now login to your account using your new password.', | ||
108 | }); | ||
109 | } | ||
110 | |||
50 | async account({ | 111 | async account({ |
51 | auth, | 112 | auth, |
52 | view, | 113 | view, |