mirror of
https://github.com/rr-/szurubooru.git
synced 2025-07-17 08:26:24 +00:00
Added e-mail confirmation and password reset
This commit is contained in:
@ -40,12 +40,19 @@ App.Presenters.LoginPresenter = function(
|
||||
var password = $el.find('[name=password]').val();
|
||||
var remember = $el.find('[name=remember]').val();
|
||||
|
||||
//todo: client side error reporting
|
||||
if (userName.length == 0) {
|
||||
messagePresenter.showError($messages, 'User name cannot be empty.');
|
||||
return false;
|
||||
}
|
||||
|
||||
if (password.length == 0) {
|
||||
messagePresenter.showError($messages, 'Password cannot be empty.');
|
||||
return false;
|
||||
}
|
||||
|
||||
auth.loginFromCredentials(userName, password, remember)
|
||||
.then(function(response) {
|
||||
router.navigateToMainPage();
|
||||
//todo: "redirect" to main page
|
||||
}).fail(function(response) {
|
||||
messagePresenter.showError($messages, response.json && response.json.error || response);
|
||||
});
|
||||
|
@ -1,32 +0,0 @@
|
||||
var App = App || {};
|
||||
App.Presenters = App.Presenters || {};
|
||||
|
||||
App.Presenters.PasswordResetPresenter = function(
|
||||
jQuery,
|
||||
topNavigationPresenter,
|
||||
messagePresenter) {
|
||||
|
||||
var $el = jQuery('#content');
|
||||
var $messages = $el;
|
||||
|
||||
function init(args) {
|
||||
topNavigationPresenter.select('login');
|
||||
if (args.token) {
|
||||
alert('Got token');
|
||||
} else {
|
||||
render();
|
||||
}
|
||||
}
|
||||
|
||||
function render() {
|
||||
$el.html('Password reset placeholder');
|
||||
};
|
||||
|
||||
return {
|
||||
init: init,
|
||||
render: render,
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
App.DI.register('passwordResetPresenter', App.Presenters.PasswordResetPresenter);
|
@ -50,10 +50,13 @@ App.Presenters.RegistrationPresenter = function(
|
||||
}
|
||||
|
||||
function registrationSuccess(apiResponse) {
|
||||
//todo: tell user if it turned out that he needs to confirm his e-mail
|
||||
$el.find('form').slideUp(function() {
|
||||
var message = 'Registration complete! ';
|
||||
message += '<a href="#/login">Click here</a> to login.';
|
||||
if (!apiResponse.json.confirmed) {
|
||||
message += '<br/>Check your inbox for activation e-mail.<br/>If e-mail doesn\'t show up, check your spam folder.';
|
||||
} else {
|
||||
message += '<a href="#/login">Click here</a> to login.';
|
||||
}
|
||||
messagePresenter.showInfo($messages, message);
|
||||
});
|
||||
}
|
||||
|
@ -3,21 +3,111 @@ App.Presenters = App.Presenters || {};
|
||||
|
||||
App.Presenters.UserActivationPresenter = function(
|
||||
jQuery,
|
||||
topNavigationPresenter) {
|
||||
promise,
|
||||
util,
|
||||
auth,
|
||||
api,
|
||||
router,
|
||||
topNavigationPresenter,
|
||||
messagePresenter) {
|
||||
|
||||
var $el = jQuery('#content');
|
||||
var $messages = $el;
|
||||
var template;
|
||||
var formHidden = false;
|
||||
var operation;
|
||||
|
||||
function init(args) {
|
||||
if (auth.isLoggedIn()) {
|
||||
router.navigateToMainPage();
|
||||
return;
|
||||
}
|
||||
|
||||
topNavigationPresenter.select('login');
|
||||
render();
|
||||
reinit(args);
|
||||
}
|
||||
|
||||
function reinit(args) {
|
||||
operation = args.operation;
|
||||
console.log(operation);
|
||||
promise.wait(util.promiseTemplate('user-query-form')).then(function(html) {
|
||||
template = _.template(html);
|
||||
if (args.token) {
|
||||
hideForm();
|
||||
confirmToken(args.token);
|
||||
} else {
|
||||
showForm();
|
||||
}
|
||||
render();
|
||||
});
|
||||
}
|
||||
|
||||
function render() {
|
||||
$el.html('Account activation placeholder');
|
||||
};
|
||||
$el.html(template());
|
||||
$messages = $el.find('.messages');
|
||||
if (formHidden)
|
||||
$el.find('form').hide();
|
||||
$el.find('form').submit(userQueryFormSubmitted);
|
||||
}
|
||||
|
||||
function hideForm() {
|
||||
formHidden = true;
|
||||
}
|
||||
|
||||
function showForm() {
|
||||
formHidden = false;
|
||||
}
|
||||
|
||||
function userQueryFormSubmitted(e) {
|
||||
e.preventDefault();
|
||||
messagePresenter.hideMessages($messages);
|
||||
|
||||
var userNameOrEmail = $el.find('form input[name=user]').val();
|
||||
if (userNameOrEmail.length == 0) {
|
||||
messagePresenter.showError($messages, 'Field cannot be blank.');
|
||||
return;
|
||||
}
|
||||
var url = operation == 'passwordReset'
|
||||
? '/password-reset/' + userNameOrEmail
|
||||
: '/activation/' + userNameOrEmail;
|
||||
|
||||
api.post(url).then(function(response) {
|
||||
var message = operation == 'passwordReset'
|
||||
? 'Password reset request sent.'
|
||||
: 'Activation e-mail resent.';
|
||||
message += ' Check your inbox.<br/>If e-mail doesn\'t show up, check your spam folder.';
|
||||
|
||||
$el.find('#user-query-form').slideUp(function() {
|
||||
messagePresenter.showInfo($messages, message);
|
||||
});
|
||||
}).fail(function(response) {
|
||||
messagePresenter.showError($messages, response.json && response.json.error || response);
|
||||
});
|
||||
}
|
||||
|
||||
function confirmToken(token) {
|
||||
messagePresenter.hideMessages($messages);
|
||||
|
||||
var url = operation == 'passwordReset'
|
||||
? '/finish-password-reset/' + token
|
||||
: '/finish-activation/' + token;
|
||||
|
||||
api.post(url).then(function(response) {
|
||||
var message = operation == 'passwordReset'
|
||||
? 'Your new password is <strong>' + response.json.newPassword + '</strong>.'
|
||||
: 'E-mail activation successful.';
|
||||
|
||||
$el.find('#user-query-form').slideUp(function() {
|
||||
messagePresenter.showInfo($messages, message);
|
||||
});
|
||||
}).fail(function(response) {
|
||||
messagePresenter.showError($messages, response.json && response.json.error || response);
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
init: init,
|
||||
reinit: reinit,
|
||||
render: render,
|
||||
};
|
||||
|
||||
|
@ -24,8 +24,8 @@ App.Router = function(jQuery, util, appState) {
|
||||
inject('#/logout', 'logoutPresenter');
|
||||
inject('#/register', 'registrationPresenter');
|
||||
inject('#/upload', 'postUploadPresenter');
|
||||
inject('#/password-reset(/:token)', 'passwordResetPresenter');
|
||||
inject('#/activate(/:token)', 'userActivationPresenter');
|
||||
inject('#/password-reset(/:token)', 'userActivationPresenter', {operation: 'passwordReset'});
|
||||
inject('#/activate(/:token)', 'userActivationPresenter', {operation: 'activation'});
|
||||
inject('#/users(/:searchArgs)', 'userListPresenter');
|
||||
inject('#/user/:userName(/:tab)', 'userPresenter');
|
||||
inject('#/posts(/:searchArgs)', 'postListPresenter');
|
||||
@ -40,9 +40,9 @@ App.Router = function(jQuery, util, appState) {
|
||||
Path.root(newRoot);
|
||||
};
|
||||
|
||||
function inject(path, presenterName) {
|
||||
function inject(path, presenterName, additionalParams) {
|
||||
Path.map(path).to(function() {
|
||||
util.initContentPresenter(presenterName, this.params);
|
||||
util.initContentPresenter(presenterName, _.extend(this.params, additionalParams));
|
||||
});
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user