diff --git a/app.js b/app.js index baa56c1cf5..30bd4d17c9 100644 --- a/app.js +++ b/app.js @@ -258,6 +258,9 @@ app.get( ); app.all('/account', passportConf.isAuthenticated); app.get('/account/api', userController.getAccountAngular); +// Unique Check API route +app.get('/api/checkUniqueUsername/:username', userController.checkUniqueUsername); +app.get('/api/checkUniqueEmail/:email', userController.checkUniqueEmail); app.get('/account', userController.getAccount); app.post('/account/profile', userController.postUpdateProfile); app.post('/account/password', userController.postUpdatePassword); diff --git a/controllers/user.js b/controllers/user.js index 9d6a8ad6b4..ededc20fcf 100644 --- a/controllers/user.js +++ b/controllers/user.js @@ -70,7 +70,7 @@ exports.logout = function(req, res) { exports.getEmailSignin = function(req, res) { if (req.user) return res.redirect('/'); - res.render('account/email-signup', { + res.render('account/email-signin', { title: 'Sign in to your Free Code Camp Account' }); }; @@ -82,7 +82,7 @@ exports.getEmailSignin = function(req, res) { exports.getEmailSignup = function(req, res) { if (req.user) return res.redirect('/'); - res.render('account/email-signin', { + res.render('account/email-signup', { title: 'Create Your Free Code Camp Account' }); }; @@ -93,6 +93,7 @@ exports.getEmailSignup = function(req, res) { */ exports.postEmailSignup = function(req, res, next) { + console.log('post email signup called'); req.assert('email', 'Email is not valid').isEmail(); req.assert('password', 'Password must be at least 4 characters long').len(4); req.assert('confirmPassword', 'Passwords do not match') @@ -103,6 +104,7 @@ exports.postEmailSignup = function(req, res, next) { if (errors) { req.flash('errors', errors); return res.redirect('/email-signup'); + console.log(errors); } var user = new User({ @@ -166,6 +168,33 @@ exports.getAccount = function(req, res) { }); }; +/** + * Unique username check API Call + */ + +exports.checkUniqueUsername = function(req, res) { + User.count({'profile.username': req.params.username.toLowerCase()}, function (err, data) { + if (data == 1) { + return res.send(true); + } else { + return res.send(false); + } + }); +}; +/** + * Unique email check API Call + */ + +exports.checkUniqueEmail = function(req, res) { + User.count({'email': req.params.email.toLowerCase()}, function (err, data) { + if (data == 1) { + return res.send(true); + } else { + return res.send(false); + } + }); +}; + /** * GET /campers/:username diff --git a/public/js/main.js b/public/js/main.js index 56e9befd41..6e3385ddc4 100644 --- a/public/js/main.js +++ b/public/js/main.js @@ -54,3 +54,35 @@ profileValidation.controller('profileValidationController', ['$scope', '$http', } ]); +profileValidation.controller('emailSignUpController', ['$scope', + function($scope) { + + } +]); + +profileValidation.directive('uniqueUsername', 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()) { + $http.get("/api/checkUniqueUsername/" + element.val()).success(function (data) { + if (data) { + ngModel.$setValidity('unique', false); + } + }); + } + }); + } + }; +}); + + + +profileValidation.controller('emailSignInController', ['$scope', + function($scope) { + + } +]); \ No newline at end of file diff --git a/views/account/email-signin.jade b/views/account/email-signin.jade index ebc38961cc..860a9ce002 100644 --- a/views/account/email-signin.jade +++ b/views/account/email-signin.jade @@ -1,29 +1,27 @@ extends ../layout block content - .jumbotron.text-center - h2 Sign up with an email address here: - form.form-horizontal(method='POST') - input(type='hidden', name='_csrf', value=_csrf) - .form-group - .col-sm-6.col-sm-offset-3 - input.form-control(type='email', name='email', id='email', placeholder='Email', autofocus) - .form-group - .col-sm-6.col-sm-offset-3 - input.form-control(type='password', name='password', id='password', placeholder='Password') - .form-group - .col-sm-6.col-sm-offset-3 - input.form-control(type='password', name='confirmPassword', id='confirmPassword', placeholder='Confirm Password') - .form-group - .col-sm-offset-3.col-sm-6 - button.btn.btn-success(type='submit') - span.ion-person-add - | Signup - br - br - br - br - br - br - br - br - br + .jumbotron.text-center(ng-controller="emailSignInController") + h2 Sign in with an email address here: + form(method='POST', action='/email-signin') + input(type='hidden', name='_csrf', value=_csrf) + .col-sm-6.col-sm-offset-3 + .form-group + input.form-control(type='email', name='email', id='email', placeholder='Email', ng-model='email', autofocus=true) + | {{ $scope.email }} + .form-group + input.form-control(type='password', name='password', id='password', placeholder='Password', ng-model='password') + .form-group + button.btn.btn-primary(type='submit') + span.ion-android-hand + | Login + span    + a.btn.btn-info(href='/forgot') Forgot your password? + br + br + br + br + br + br + br + br + br \ No newline at end of file diff --git a/views/account/email-signup.jade b/views/account/email-signup.jade index 0764a2ee18..95923e53f4 100644 --- a/views/account/email-signup.jade +++ b/views/account/email-signup.jade @@ -1,26 +1,36 @@ extends ../layout block content - .jumbotron.text-center - h2 Sign in with an email address here: - form(method='POST') - input(type='hidden', name='_csrf', value=_csrf) - .col-sm-6.col-sm-offset-3 - .form-group - input.form-control(type='email', name='email', id='email', placeholder='Email', autofocus=true) - .form-group - input.form-control(type='password', name='password', id='password', placeholder='Password') - .form-group - button.btn.btn-primary(type='submit') - span.ion-android-hand - | Login - span    - a.btn.btn-info(href='/forgot') Forgot your password? - br - br - br - br - br - br - br - br - br \ No newline at end of file + .jumbotron.text-center + h2 Sign up with an email address here: + form.form-horizontal(method='POST', action='/email-signup', name="signupForm", novalidate="novalidate") + 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) + .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) + .col-sm-6.col-sm-offset-3(ng-show="signupForm.username.$error.unique && !signupForm.username.$pristine") + alert(type='danger') + span.ion-close-circled + | This username is taken. + .form-group + .col-sm-6.col-sm-offset-3 + input.form-control(type='password', ng-model='password', name='password', id='password', placeholder='password', required) + .form-group + .col-sm-6.col-sm-offset-3 + input.form-control(type='password', ng-model='confirmPassword', name='confirmPassword', id='confirmPassword', placeholder='confirm password', required) + .form-group + .col-sm-offset-3.col-sm-6 + button.btn.btn-success(type='submit') + span.ion-person-add + | Signup + br + br + br + br + br + br + br + br + br diff --git a/views/account/profile.jade b/views/account/profile.jade index b51b83b9f2..0fb25cd99e 100644 --- a/views/account/profile.jade +++ b/views/account/profile.jade @@ -13,7 +13,7 @@ block content .form-group label.col-sm-3.col-sm-offset-2.control-label(for='name') Name * .col-sm-4 - input.form-control(type='text', placeholder='Name', name='name', ng-model='user.profile.name', ng-minlength='3', ng-maxlength='50', required='required', id='name') + input.form-control(type='text', ng-keyup='keyPress()', placeholder='Name', name='name', ng-model='user.profile.name', ng-minlength='3', ng-maxlength='50', required='required', id='name') .col-sm-4.col-sm-offset-5(ng-show="profileForm.name.$invalid && !profileForm.name.$pristine && profileForm.name.$error.required") alert(type='danger') span.ion-close-circled