mirror of
https://github.com/rr-/szurubooru.git
synced 2025-07-17 08:26:24 +00:00
client+server: finish password reminders
This commit is contained in:
@ -5,10 +5,12 @@ const page = require('page');
|
||||
const api = require('../api.js');
|
||||
const topNavController = require('../controllers/top_nav_controller.js');
|
||||
const LoginView = require('../views/login_view.js');
|
||||
const PasswordResetView = require('../views/password_reset_view.js');
|
||||
|
||||
class AuthController {
|
||||
constructor() {
|
||||
this.loginView = new LoginView();
|
||||
this.passwordResetView = new PasswordResetView();
|
||||
|
||||
const auth = cookies.getJSON('auth');
|
||||
if (auth && auth.user && auth.password) {
|
||||
@ -51,6 +53,43 @@ class AuthController {
|
||||
page('/');
|
||||
this.loginView.notifySuccess('Logged out');
|
||||
}
|
||||
|
||||
passwordResetRoute() {
|
||||
topNavController.activate('login');
|
||||
this.passwordResetView.render({
|
||||
proceed: nameOrEmail => {
|
||||
api.logout();
|
||||
cookies.remove('auth');
|
||||
return new Promise((resolve, reject) => {
|
||||
api.get('/password-reset/' + nameOrEmail)
|
||||
.then(() => { resolve(); })
|
||||
.catch(errorMessage => { reject(errorMessage); });
|
||||
});
|
||||
}});
|
||||
}
|
||||
|
||||
passwordResetFinishRoute(name, token) {
|
||||
api.logout();
|
||||
cookies.remove('auth');
|
||||
api.post('/password-reset/' + name, {token: token})
|
||||
.then(response => {
|
||||
const password = response.password;
|
||||
api.login(name, password)
|
||||
.then(() => {
|
||||
cookies.set(
|
||||
'auth', {'user': name, 'password': password}, {});
|
||||
page('/');
|
||||
this.passwordResetView.notifySuccess(
|
||||
'New password: ' + password);
|
||||
}).catch(errorMessage => {
|
||||
page('/');
|
||||
this.passwordResetView.notifyError(errorMessage);
|
||||
});
|
||||
}).catch(response => {
|
||||
page('/');
|
||||
this.passwordResetView.notifyError(response.description);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = new AuthController();
|
||||
|
Reference in New Issue
Block a user