Commit c1d7b733 authored by Evren Kutar's avatar Evren Kutar

use isvalidemail in custom validation

parent af99d361
...@@ -11,7 +11,7 @@ login.config(['$routeProvider', function ($routeProvider) { ...@@ -11,7 +11,7 @@ login.config(['$routeProvider', function ($routeProvider) {
// controller: 'LoginCtrl' // controller: 'LoginCtrl'
//}); //});
}]); }]);
login.controller('LoginCtrl', function ($scope, $http, $location, $rootScope, AUTH_EVENTS, LoginService) { login.controller('LoginCtrl', function ($scope, $q, $timeout, $http, $location, $rootScope, AUTH_EVENTS, LoginService) {
$scope.schema = $scope.schema =
{ {
title: "Login", title: "Login",
...@@ -44,7 +44,23 @@ login.controller('LoginCtrl', function ($scope, $http, $location, $rootScope, AU ...@@ -44,7 +44,23 @@ login.controller('LoginCtrl', function ($scope, $http, $location, $rootScope, AU
$scope.form = [ $scope.form = [
{ {
key: "email", key: "email",
type: "email" type: "email",
validationMessages: {
'emailNotValid': 'Email is not valid!'
},
$asyncValidators: {
emailNotValid: function(value){
var deferred = $q.defer();
$timeout(function(){
if (LoginService.isValidEmail(value)) {
deferred.resolve();
} else {
deferred.reject();
}
}, 500);
return deferred.promise;
}
}
}, },
{ {
key: "password", key: "password",
...@@ -63,8 +79,7 @@ login.controller('LoginCtrl', function ($scope, $http, $location, $rootScope, AU ...@@ -63,8 +79,7 @@ login.controller('LoginCtrl', function ($scope, $http, $location, $rootScope, AU
var credentials = {email: form.email.$modelValue, password: form.password.$modelValue}; var credentials = {email: form.email.$modelValue, password: form.password.$modelValue};
console.log(form); console.log(form);
var loginResponse = LoginService.login(credentials); LoginService.login(credentials);
console.log(loginResponse);
} }
else { else {
console.log("not valid"); console.log("not valid");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment