Added IValidatable; moved validation to FormData

I still struggle to find out how to deal with arguments like
$userNameOrEmail. Should I trim() them in controllers, or in service?
If I do it in service, shouldn't all of such validation belong in there?
This commit is contained in:
Marcin Kurczewski
2014-09-09 19:38:16 +02:00
parent e6c7ed7e11
commit c117367974
16 changed files with 170 additions and 81 deletions

View File

@ -26,9 +26,9 @@ App.Auth = function(_, jQuery, util, api, appState, promise) {
listTags: 'listTags',
};
function loginFromCredentials(userName, password, remember) {
function loginFromCredentials(userNameOrEmail, password, remember) {
return promise.make(function(resolve, reject) {
promise.wait(api.post('/login', {userName: userName, password: password}))
promise.wait(api.post('/login', {userNameOrEmail: userNameOrEmail, password: password}))
.then(function(response) {
updateAppState(response);
jQuery.cookie(

View File

@ -38,11 +38,11 @@ App.Presenters.LoginPresenter = function(
e.preventDefault();
messagePresenter.hideMessages($messages);
var userName = $el.find('[name=user]').val();
var userNameOrEmail = $el.find('[name=user]').val();
var password = $el.find('[name=password]').val();
var remember = $el.find('[name=remember]').val();
if (userName.length === 0) {
if (userNameOrEmail.length === 0) {
messagePresenter.showError($messages, 'User name cannot be empty.');
return false;
}
@ -52,7 +52,7 @@ App.Presenters.LoginPresenter = function(
return false;
}
auth.loginFromCredentials(userName, password, remember)
auth.loginFromCredentials(userNameOrEmail, password, remember)
.then(function(response) {
router.navigateToMainPage();
}).fail(function(response) {