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.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);

View File

@ -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

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
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

View File

@ -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
.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

View File

@ -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