Files
habitica/website/server/controllers/top-level/auth.js
Matteo Pagliazzi e1ad19c216 Client: Port Reset Password Page (#9057)
* start work on porting the reset password page

* add new api route for setting a new password after a reset

* wip client page

* port tests

* wip

* fix linting

* skip tests
2017-09-27 18:57:52 +02:00

38 lines
1.0 KiB
JavaScript

import locals from '../../middlewares/locals';
import { validatePasswordResetCodeAndFindUser } from '../../libs/password';
let api = {};
// Internal authentication routes
// Set a new password after having requested a password reset (GET route to input password)
api.resetPasswordSetNewOne = {
method: 'GET',
url: '/static/user/auth/local/reset-password-set-new-one',
middlewares: [locals],
runCron: false,
async handler (req, res) {
const code = req.query.code;
const user = await validatePasswordResetCodeAndFindUser(code);
const isValidCode = Boolean(user);
const hasError = !isValidCode;
const message = !isValidCode ? res.t('invalidPasswordResetCode') : null;
return res.redirect(`/reset-password?hasError=${hasError}&message=${message}&code=${code}`);
},
};
// Logout the user from the website.
api.logout = {
method: 'GET',
url: '/logout',
async handler (req, res) {
if (req.logout) req.logout(); // passportjs method
req.session = null;
res.redirect('/');
},
};
module.exports = api;