mirror of
https://github.com/rr-/szurubooru.git
synced 2025-07-17 08:26:24 +00:00
Switched to spaces
This commit is contained in:
@ -2,100 +2,100 @@ var App = App || {};
|
||||
App.Presenters = App.Presenters || {};
|
||||
|
||||
App.Presenters.RegistrationPresenter = function(
|
||||
jQuery,
|
||||
util,
|
||||
promise,
|
||||
api,
|
||||
topNavigationPresenter,
|
||||
messagePresenter) {
|
||||
jQuery,
|
||||
util,
|
||||
promise,
|
||||
api,
|
||||
topNavigationPresenter,
|
||||
messagePresenter) {
|
||||
|
||||
var $el = jQuery('#content');
|
||||
var templates = {};
|
||||
var $messages;
|
||||
var $el = jQuery('#content');
|
||||
var templates = {};
|
||||
var $messages;
|
||||
|
||||
function init(params, loaded) {
|
||||
topNavigationPresenter.select('register');
|
||||
topNavigationPresenter.changeTitle('Registration');
|
||||
promise.wait(util.promiseTemplate('registration-form'))
|
||||
.then(function(template) {
|
||||
templates.registration = template;
|
||||
render();
|
||||
loaded();
|
||||
}).fail(function() {
|
||||
console.log(arguments);
|
||||
loaded();
|
||||
});
|
||||
}
|
||||
function init(params, loaded) {
|
||||
topNavigationPresenter.select('register');
|
||||
topNavigationPresenter.changeTitle('Registration');
|
||||
promise.wait(util.promiseTemplate('registration-form'))
|
||||
.then(function(template) {
|
||||
templates.registration = template;
|
||||
render();
|
||||
loaded();
|
||||
}).fail(function() {
|
||||
console.log(arguments);
|
||||
loaded();
|
||||
});
|
||||
}
|
||||
|
||||
function render() {
|
||||
$el.html(templates.registration());
|
||||
$el.find('form').submit(registrationFormSubmitted);
|
||||
$messages = $el.find('.messages');
|
||||
$messages.width($el.find('form').width());
|
||||
}
|
||||
function render() {
|
||||
$el.html(templates.registration());
|
||||
$el.find('form').submit(registrationFormSubmitted);
|
||||
$messages = $el.find('.messages');
|
||||
$messages.width($el.find('form').width());
|
||||
}
|
||||
|
||||
function registrationFormSubmitted(e) {
|
||||
e.preventDefault();
|
||||
messagePresenter.hideMessages($messages);
|
||||
function registrationFormSubmitted(e) {
|
||||
e.preventDefault();
|
||||
messagePresenter.hideMessages($messages);
|
||||
|
||||
var formData = {
|
||||
userName: $el.find('[name=userName]').val(),
|
||||
password: $el.find('[name=password]').val(),
|
||||
passwordConfirmation: $el.find('[name=passwordConfirmation]').val(),
|
||||
email: $el.find('[name=email]').val(),
|
||||
};
|
||||
var formData = {
|
||||
userName: $el.find('[name=userName]').val(),
|
||||
password: $el.find('[name=password]').val(),
|
||||
passwordConfirmation: $el.find('[name=passwordConfirmation]').val(),
|
||||
email: $el.find('[name=email]').val(),
|
||||
};
|
||||
|
||||
if (!validateRegistrationFormData(formData)) {
|
||||
return;
|
||||
}
|
||||
if (!validateRegistrationFormData(formData)) {
|
||||
return;
|
||||
}
|
||||
|
||||
promise.wait(api.post('/users', formData))
|
||||
.then(function(response) {
|
||||
registrationSuccess(response);
|
||||
}).fail(function(response) {
|
||||
registrationFailure(response);
|
||||
});
|
||||
}
|
||||
promise.wait(api.post('/users', formData))
|
||||
.then(function(response) {
|
||||
registrationSuccess(response);
|
||||
}).fail(function(response) {
|
||||
registrationFailure(response);
|
||||
});
|
||||
}
|
||||
|
||||
function registrationSuccess(apiResponse) {
|
||||
$el.find('form').slideUp(function() {
|
||||
var message = 'Registration complete! ';
|
||||
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);
|
||||
});
|
||||
}
|
||||
function registrationSuccess(apiResponse) {
|
||||
$el.find('form').slideUp(function() {
|
||||
var message = 'Registration complete! ';
|
||||
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);
|
||||
});
|
||||
}
|
||||
|
||||
function registrationFailure(apiResponse) {
|
||||
messagePresenter.showError($messages, apiResponse.json && apiResponse.json.error || apiResponse);
|
||||
}
|
||||
function registrationFailure(apiResponse) {
|
||||
messagePresenter.showError($messages, apiResponse.json && apiResponse.json.error || apiResponse);
|
||||
}
|
||||
|
||||
function validateRegistrationFormData(formData) {
|
||||
if (formData.userName.length === 0) {
|
||||
messagePresenter.showError($messages, 'User name cannot be empty.');
|
||||
return false;
|
||||
}
|
||||
function validateRegistrationFormData(formData) {
|
||||
if (formData.userName.length === 0) {
|
||||
messagePresenter.showError($messages, 'User name cannot be empty.');
|
||||
return false;
|
||||
}
|
||||
|
||||
if (formData.password.length === 0) {
|
||||
messagePresenter.showError($messages, 'Password cannot be empty.');
|
||||
return false;
|
||||
}
|
||||
if (formData.password.length === 0) {
|
||||
messagePresenter.showError($messages, 'Password cannot be empty.');
|
||||
return false;
|
||||
}
|
||||
|
||||
if (formData.password !== formData.passwordConfirmation) {
|
||||
messagePresenter.showError($messages, 'Passwords must be the same.');
|
||||
return false;
|
||||
}
|
||||
if (formData.password !== formData.passwordConfirmation) {
|
||||
messagePresenter.showError($messages, 'Passwords must be the same.');
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return {
|
||||
init: init,
|
||||
render: render,
|
||||
};
|
||||
return {
|
||||
init: init,
|
||||
render: render,
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user