-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(dashboard): Force password change on user
- Loading branch information
1 parent
3642138
commit bd3554a
Showing
16 changed files
with
115 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module.exports = { | ||
method: 'GET', | ||
path: '/dashboard/change-password', | ||
config: { auth: 'session' }, | ||
handler(req, res) { | ||
res.view('change-password', { | ||
pageTitle: 'Password change', | ||
}); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
const Joi = require('joi'); | ||
|
||
module.exports = { | ||
method: 'POST', | ||
path: '/dashboard/change-password', | ||
config: { | ||
auth: 'session', | ||
validate: { | ||
payload: { | ||
plainPassword: Joi.string().min(6).required(), | ||
plainPasswordCheck: Joi.string().required(), | ||
}, | ||
}, | ||
}, | ||
handler(req, res) { | ||
if (req.payload.plainPassword !== req.payload.plainPasswordCheck) { | ||
return res.view('change-password', { | ||
pageTitle: 'Password change', | ||
error: 'Passwords don\'t match', | ||
}).code(401); | ||
} | ||
|
||
const user = req.auth.credentials; | ||
|
||
return user.comparePassword(req.payload.plainPassword) | ||
.then((isSamePassword) => { | ||
if (isSamePassword) { | ||
return res.view('change-password', { | ||
pageTitle: 'Password change', | ||
error: 'You must choose a password different from the previous one', | ||
}).code(401); | ||
} | ||
|
||
return user.hashPassword(req.payload.plainPassword) | ||
.then(() => { | ||
user.needPasswordChange = false; | ||
return user.save(); | ||
}) | ||
.then(() => res.redirect('/dashboard')); | ||
}) | ||
.catch(() => res.view('change-password', { | ||
pageTitle: 'Password change', | ||
error: 'An unknown error occurred', | ||
}).code(401)); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<div class="mdl-grid"> | ||
<form class="mdl-cell mdl-cell--6-col mdl-cell--3-offset-desktop mdl-cell--1-offset-tablet mdl-card mdl-shadow--2dp" | ||
method="POST"> | ||
<div class="mdl-card__title"> | ||
<h2 class="mdl-card__title-text">Change password</h2> | ||
</div> | ||
<div class="mdl-card__supporting-text mdl-grid"> | ||
You've been requested to change your password for security reasons. Choose a new password bellow : | ||
|
||
<div class="mdl-cell mdl-cell--6-col mdl-cell--8-col-tablet mdl-textfield mdl-js-textfield mdl-textfield--floating-label"> | ||
<input class="mdl-textfield__input" type="password" id="plainPasswordInput" name="plainPassword" pattern=".{6,}" required> | ||
<label class="mdl-textfield__label" for="plainPasswordInput">Password</label> | ||
</div> | ||
|
||
<div class="mdl-cell mdl-cell--6-col mdl-cell--8-col-tablet mdl-textfield mdl-js-textfield mdl-textfield--floating-label"> | ||
<input class="mdl-textfield__input" type="password" id="plainPasswordCheckInput" name="plainPasswordCheck" pattern=".{6,}" required> | ||
<label class="mdl-textfield__label" for="plainPasswordCheckInput">Repeat Password</label> | ||
</div> | ||
|
||
{{ error }} | ||
|
||
<input type="hidden" name="crumb" value="{{crumb}}"> | ||
</div> | ||
|
||
<div class="mdl-card__actions mdl-card--border"> | ||
<button class="mdl-button mdl-button--colored mdl-js-button mdl-js-ripple-effect" type="submit"> | ||
Save | ||
</button> | ||
</div> | ||
</form> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,14 @@ | ||
{ | ||
"parser": "babel-eslint", | ||
"extends": ["airbnb-base"], | ||
"plugins": [ | ||
"babel" | ||
], | ||
"env": { | ||
"node": true, | ||
"mocha": true | ||
}, | ||
"rules": { | ||
"prefer-arrow-callback": 0, | ||
"generator-star-spacing": 0, | ||
"func-names": 0, | ||
"import/no-extraneous-dependencies": 0, | ||
"babel/generator-star-spacing": 1, | ||
"no-underscore-dangle": 0 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters