diff --git a/controllers/user.js b/controllers/user.js index ededc20fcf..c2ecd1b890 100644 --- a/controllers/user.js +++ b/controllers/user.js @@ -186,7 +186,9 @@ exports.checkUniqueUsername = function(req, res) { */ exports.checkUniqueEmail = function(req, res) { - User.count({'email': req.params.email.toLowerCase()}, function (err, data) { + console.log(req.params.email); + User.count({'email': decodeURIComponent(req.params.email).toLowerCase()}, function (err, data) { + console.log(User.findOne({'email': decodeURIComponent(req.params.email)})); if (data == 1) { return res.send(true); } else { diff --git a/public/js/main.js b/public/js/main.js index 6e3385ddc4..26983d7c9a 100644 --- a/public/js/main.js +++ b/public/js/main.js @@ -60,6 +60,12 @@ profileValidation.controller('emailSignUpController', ['$scope', } ]); +profileValidation.controller('emailSignInController', ['$scope', + function($scope) { + + } +]); + profileValidation.directive('uniqueUsername', function($http) { return { restrict: 'A', @@ -79,10 +85,22 @@ profileValidation.directive('uniqueUsername', function($http) { }; }); - - -profileValidation.controller('emailSignInController', ['$scope', - function($scope) { - - } -]); \ No newline at end of file +profileValidation.directive('uniqueEmail', function($http) { + return { + restrict: 'A', + require: 'ngModel', + link: function (scope, element, attrs, ngModel) { + element.bind("keyup", function (event) { + ngModel.$setValidity('unique', true); + if (element.val()) { + console.log(encodeURIComponent(element.val())); + $http.get("/api/checkUniqueEmail/" + encodeURIComponent(element.val())).success(function (data) { + if (data) { + ngModel.$setValidity('unique', false); + } + }); + } + }); + } + }; +}); \ No newline at end of file diff --git a/views/account/email-signup.jade b/views/account/email-signup.jade index 95923e53f4..86fb400d3b 100644 --- a/views/account/email-signup.jade +++ b/views/account/email-signup.jade @@ -6,7 +6,11 @@ block content input(type='hidden', name='_csrf', value=_csrf) .form-group .col-sm-6.col-sm-offset-3 - input.form-control(type='email', ng-model='email', name='email', id='email', placeholder='email', autofocus, required) + input.form-control(type='email', ng-model='email', ng-keypress='', name='email', id='email', placeholder='email', autofocus, required, autocomplete="off") + .col-sm-6.col-sm-offset-3(ng-show="signupForm.email.$error.unique && !signupForm.email.$pristine") + alert(type='danger') + span.ion-close-circled + | This email is taken. .form-group .col-sm-6.col-sm-offset-3 input.form-control(type='text', name='username', ng-keypress='', autocomplete="off", id='username', placeholder='username', ng-model='username', unique-username='', required)