Cleaning up, enforcing username constraints to match profile page settings. Added uniqueness to profile username.

This commit is contained in:
terakilobyte
2015-01-09 22:05:45 -05:00
parent 11bc776ffb
commit b4395e2b59
4 changed files with 23 additions and 12 deletions

View File

@ -189,9 +189,7 @@ exports.checkUniqueUsername = function(req, res) {
*/ */
exports.checkUniqueEmail = function(req, res) { exports.checkUniqueEmail = function(req, res) {
console.log(req.params.email);
User.count({'email': decodeURIComponent(req.params.email).toLowerCase()}, function (err, data) { User.count({'email': decodeURIComponent(req.params.email).toLowerCase()}, function (err, data) {
console.log(User.findOne({'email': decodeURIComponent(req.params.email)}));
if (data == 1) { if (data == 1) {
return res.send(true); return res.send(true);
} else { } else {

View File

@ -48,6 +48,7 @@ profileValidation.controller('profileValidationController', ['$scope', '$http',
$http.get('/account/api').success(function(data) { $http.get('/account/api').success(function(data) {
$scope.user = data.user; $scope.user = data.user;
$scope.user.profile.username = $scope.user.profile.username.toLowerCase(); $scope.user.profile.username = $scope.user.profile.username.toLowerCase();
$scope.storedUsername = $scope.user.profile.username;
$scope.user.email = $scope.user.email.toLowerCase(); $scope.user.email = $scope.user.email.toLowerCase();
$scope.user.profile.twitterHandle = $scope.user.profile.twitterHandle.toLowerCase(); $scope.user.profile.twitterHandle = $scope.user.profile.twitterHandle.toLowerCase();
}); });
@ -93,7 +94,6 @@ profileValidation.directive('uniqueEmail', function($http) {
element.bind("keyup", function (event) { element.bind("keyup", function (event) {
ngModel.$setValidity('unique', true); ngModel.$setValidity('unique', true);
if (element.val()) { if (element.val()) {
console.log(encodeURIComponent(element.val()));
$http.get("/api/checkUniqueEmail/" + encodeURIComponent(element.val())).success(function (data) { $http.get("/api/checkUniqueEmail/" + encodeURIComponent(element.val())).success(function (data) {
if (data) { if (data) {
ngModel.$setValidity('unique', false); ngModel.$setValidity('unique', false);

View File

@ -5,19 +5,28 @@ block content
form.form-horizontal(method='POST', action='/email-signup', name="signupForm", novalidate="novalidate") 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)
.form-group .form-group
.col-sm-6.col-sm-offset-3 h3
input.form-control(type='email', ng-model='email', ng-keypress='', name='email', id='email', placeholder='email', autofocus, required, autocomplete="off", unique-email='') .col-sm-6.col-sm-offset-3
.col-sm-6.col-sm-offset-3(ng-show="signupForm.email.$error.unique && !signupForm.email.$pristine") input.form-control(type='email', ng-model='email', ng-keypress='', name='email', id='email', placeholder='email', autofocus, required, autocomplete="off", unique-email='')
alert(type='danger') .col-sm-3(ng-show="signupForm.email.$error.unique && !signupForm.email.$pristine")
span.ion-close-circled alert(type='danger')
| This email is taken. span.ion-close-circled
| This email is taken.
.form-group .form-group
.col-sm-6.col-sm-offset-3 .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) input.form-control(type='text', name='username', ng-keypress='', autocomplete="off", id='username', placeholder='username', ng-model='username', unique-username='', required, ng-minlength=5, ng-maxlength=20)
.col-sm-6.col-sm-offset-3(ng-show="signupForm.username.$error.unique && !signupForm.username.$pristine") .col-sm-6.col-sm-offset-3(ng-show="signupForm.username.$error.unique && !signupForm.username.$pristine")
alert(type='danger') alert(type='danger')
span.ion-close-circled span.ion-close-circled
| This username is taken. | This username is taken.
.col-sm-6.col-sm-offset-3(ng-show="signupForm.username.$error.minlength && !signupForm.username.$pristine")
alert(type='danger')
span.ion-close-circled
| Usernames must be at least 5 characters.
.col-sm-6.col-sm-offset-3(ng-show="signupForm.username.$error.maxlength && !signupForm.username.$pristine")
alert(type='danger')
span.ion-close-circled
| Usernames must be 20 characters or less.
.form-group .form-group
.col-sm-6.col-sm-offset-3 .col-sm-6.col-sm-offset-3
input.form-control(type='password', ng-model='password', name='password', id='password', placeholder='password', required) input.form-control(type='password', ng-model='password', name='password', id='password', placeholder='password', required)

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', ng-keyup='keyPress()', placeholder='Name', name='name', ng-model='user.profile.name', ng-minlength='3', ng-maxlength='50', required='required', id='name') input.form-control(type='text', 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
@ -30,7 +30,7 @@ block content
.form-group .form-group
label.col-sm-3.col-sm-offset-2.control-label(for='username') Username (path to public profile) * label.col-sm-3.col-sm-offset-2.control-label(for='username') Username (path to public profile) *
.col-sm-4 .col-sm-4
input.form-control(type='text', placeholder='username' name='username', id='username', ng-model='user.profile.username', required='required', ng-minlength='5', ng-maxlength='20') input.form-control(type='text', placeholder='username' name='username', id='username', ng-model='user.profile.username', required='required', ng-minlength='5', ng-maxlength='20', ng-keypress='', unique-username='')
.col-sm-4.col-sm-offset-5(ng-show="profileForm.username.$error.required && !profileForm.username.$pristine") .col-sm-4.col-sm-offset-5(ng-show="profileForm.username.$error.required && !profileForm.username.$pristine")
alert(type='danger') alert(type='danger')
span.ion-close-circled span.ion-close-circled
@ -43,6 +43,10 @@ block content
alert(type='danger') alert(type='danger')
span.ion-close-circled span.ion-close-circled
| Your username must be fewer than 15 characters. | Your username must be fewer than 15 characters.
.col-sm-4.col-sm-offset-5(ng-show="profileForm.username.$error.unique && !profileForm.username.$pristine")
alert(type='danger')
span.ion-close-circled
| This username is taken.
.form-group .form-group
label.col-sm-3.col-sm-offset-2.control-label(for='email') Email * label.col-sm-3.col-sm-offset-2.control-label(for='email') Email *