aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorLibravatar vantezzen <hello@vantezzen.io>2020-04-02 17:09:11 +0200
committerLibravatar vantezzen <hello@vantezzen.io>2020-04-02 17:09:11 +0200
commit6ed9da44690d5f68a5bb4e398c0a4ad4083ed6fa (patch)
tree77778897d7411d7c273d1b1bdf7caf7ba75f85e2 /app
parentUpgrade dependencies (diff)
downloadferdium-server-6ed9da44690d5f68a5bb4e398c0a4ad4083ed6fa.tar.gz
ferdium-server-6ed9da44690d5f68a5bb4e398c0a4ad4083ed6fa.tar.zst
ferdium-server-6ed9da44690d5f68a5bb4e398c0a4ad4083ed6fa.zip
#16 Implement Password reset
Diffstat (limited to 'app')
-rw-r--r--app/Controllers/Http/DashboardController.js61
-rw-r--r--app/Models/Token.js3
2 files changed, 64 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
6const Service = use('App/Models/Service'); 6const Service = use('App/Models/Service');
7const Workspace = use('App/Models/Workspace'); 7const Workspace = use('App/Models/Workspace');
8const Persona = use('Persona');
8 9
9const crypto = require('crypto'); 10const crypto = require('crypto');
10const uuid = require('uuid/v4'); 11const 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,
diff --git a/app/Models/Token.js b/app/Models/Token.js
index f6bec08..50bcf1d 100644
--- a/app/Models/Token.js
+++ b/app/Models/Token.js
@@ -3,6 +3,9 @@
3const Model = use('Model'); 3const Model = use('Model');
4 4
5class Token extends Model { 5class Token extends Model {
6 user() {
7 return this.belongsTo('App/Models/User')
8 }
6} 9}
7 10
8module.exports = Token; 11module.exports = Token;