start angularizing sign up form

This commit is contained in:
Michael Q Larson
2015-01-09 17:52:19 -08:00
parent 99253a7745
commit 3e7da5ae98
6 changed files with 126 additions and 54 deletions

3
app.js
View File

@ -258,6 +258,9 @@ app.get(
); );
app.all('/account', passportConf.isAuthenticated); app.all('/account', passportConf.isAuthenticated);
app.get('/account/api', userController.getAccountAngular); 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.get('/account', userController.getAccount);
app.post('/account/profile', userController.postUpdateProfile); app.post('/account/profile', userController.postUpdateProfile);
app.post('/account/password', userController.postUpdatePassword); app.post('/account/password', userController.postUpdatePassword);

View File

@ -70,7 +70,7 @@ exports.logout = function(req, res) {
exports.getEmailSignin = function(req, res) { exports.getEmailSignin = function(req, res) {
if (req.user) return res.redirect('/'); 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' title: 'Sign in to your Free Code Camp Account'
}); });
}; };
@ -82,7 +82,7 @@ exports.getEmailSignin = function(req, res) {
exports.getEmailSignup = function(req, res) { exports.getEmailSignup = function(req, res) {
if (req.user) return res.redirect('/'); if (req.user) return res.redirect('/');
res.render('account/email-signin', { res.render('account/email-signup', {
title: 'Create Your Free Code Camp Account' title: 'Create Your Free Code Camp Account'
}); });
}; };
@ -93,6 +93,7 @@ exports.getEmailSignup = function(req, res) {
*/ */
exports.postEmailSignup = function(req, res, next) { exports.postEmailSignup = function(req, res, next) {
console.log('post email signup called');
req.assert('email', 'Email is not valid').isEmail(); req.assert('email', 'Email is not valid').isEmail();
req.assert('password', 'Password must be at least 4 characters long').len(4); req.assert('password', 'Password must be at least 4 characters long').len(4);
req.assert('confirmPassword', 'Passwords do not match') req.assert('confirmPassword', 'Passwords do not match')
@ -103,6 +104,7 @@ exports.postEmailSignup = function(req, res, next) {
if (errors) { if (errors) {
req.flash('errors', errors); req.flash('errors', errors);
return res.redirect('/email-signup'); return res.redirect('/email-signup');
console.log(errors);
} }
var user = new User({ 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 * GET /campers/:username

View File

@ -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) {
}
]);

View File

@ -1,29 +1,27 @@
extends ../layout extends ../layout
block content block content
.jumbotron.text-center .jumbotron.text-center(ng-controller="emailSignInController")
h2 Sign up with an email address here: h2 Sign in with an email address here:
form.form-horizontal(method='POST') form(method='POST', action='/email-signin')
input(type='hidden', name='_csrf', value=_csrf) input(type='hidden', name='_csrf', value=_csrf)
.form-group .col-sm-6.col-sm-offset-3
.col-sm-6.col-sm-offset-3 .form-group
input.form-control(type='email', name='email', id='email', placeholder='Email', autofocus) input.form-control(type='email', name='email', id='email', placeholder='Email', ng-model='email', autofocus=true)
.form-group | {{ $scope.email }}
.col-sm-6.col-sm-offset-3 .form-group
input.form-control(type='password', name='password', id='password', placeholder='Password') input.form-control(type='password', name='password', id='password', placeholder='Password', ng-model='password')
.form-group .form-group
.col-sm-6.col-sm-offset-3 button.btn.btn-primary(type='submit')
input.form-control(type='password', name='confirmPassword', id='confirmPassword', placeholder='Confirm Password') span.ion-android-hand
.form-group | Login
.col-sm-offset-3.col-sm-6 span   
button.btn.btn-success(type='submit') a.btn.btn-info(href='/forgot') Forgot your password?
span.ion-person-add br
| Signup br
br br
br br
br br
br br
br br
br br
br br
br
br

View File

@ -1,26 +1,36 @@
extends ../layout extends ../layout
block content block content
.jumbotron.text-center .jumbotron.text-center
h2 Sign in with an email address here: h2 Sign up with an email address here:
form(method='POST') form.form-horizontal(method='POST', action='/email-signup', name="signupForm", novalidate="novalidate")
input(type='hidden', name='_csrf', value=_csrf) input(type='hidden', name='_csrf', value=_csrf)
.col-sm-6.col-sm-offset-3 .form-group
.form-group .col-sm-6.col-sm-offset-3
input.form-control(type='email', name='email', id='email', placeholder='Email', autofocus=true) input.form-control(type='email', ng-model='email', name='email', id='email', placeholder='email', autofocus, required)
.form-group .form-group
input.form-control(type='password', name='password', id='password', placeholder='Password') .col-sm-6.col-sm-offset-3
.form-group input.form-control(type='text', name='username', ng-keypress='', autocomplete="off", id='username', placeholder='username', ng-model='username', unique-username='', required)
button.btn.btn-primary(type='submit') .col-sm-6.col-sm-offset-3(ng-show="signupForm.username.$error.unique && !signupForm.username.$pristine")
span.ion-android-hand alert(type='danger')
| Login span.ion-close-circled
span    | This username is taken.
a.btn.btn-info(href='/forgot') Forgot your password? .form-group
br .col-sm-6.col-sm-offset-3
br input.form-control(type='password', ng-model='password', name='password', id='password', placeholder='password', required)
br .form-group
br .col-sm-6.col-sm-offset-3
br input.form-control(type='password', ng-model='confirmPassword', name='confirmPassword', id='confirmPassword', placeholder='confirm password', required)
br .form-group
br .col-sm-offset-3.col-sm-6
br button.btn.btn-success(type='submit')
br span.ion-person-add
| Signup
br
br
br
br
br
br
br
br
br

View File

@ -13,7 +13,7 @@ block content
.form-group .form-group
label.col-sm-3.col-sm-offset-2.control-label(for='name') Name * label.col-sm-3.col-sm-offset-2.control-label(for='name') Name *
.col-sm-4 .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") .col-sm-4.col-sm-offset-5(ng-show="profileForm.name.$invalid && !profileForm.name.$pristine && profileForm.name.$error.required")
alert(type='danger') alert(type='danger')
span.ion-close-circled span.ion-close-circled