Existing username check now working, error box showing and hiding properly, UI tweaks

This commit is contained in:
Nathan Leniz
2015-01-24 12:51:53 -05:00
parent 022b8daddc
commit 4128b3b765
3 changed files with 20 additions and 15 deletions

View File

@ -191,9 +191,11 @@ exports.checkUniqueUsername = function(req, res) {
exports.checkExistingUsername = function(req, res) {
User.count({'profile.username': req.params.username.toLowerCase()}, function (err, data) {
if (data == 1) {
return res.send(false);
} else {
debug('sending false back')
return res.send(true);
} else {
debug('sending true back')
return res.send(false);
}
});
};

View File

@ -96,7 +96,7 @@ profileValidation.controller('profileValidationController', ['$scope', '$http',
profileValidation.controller('pairedWithController', ['$scope',
function($scope) {
$scope.existingUser = null;
}
]);
@ -152,16 +152,16 @@ profileValidation.directive('existingUsername', function($http) {
require: 'ngModel',
link: function (scope, element, attrs, ngModel) {
element.bind("keyup", function (event) {
ngModel.$setValidity('exists', true);
ngModel.$setValidity('exists', false);
if (element.val()) {
$http.get("/api/checkExistingUsername/" + element.val()).success(function (data) {
$http.get("/api/checkExistingUsername/" + element.val() + ' ').success(function (data) {
console.log('in existing username function');
if (element.val() == scope.existingUsername) {
console.log('matches a username');
ngModel.$setValidity('exists', true);
} else if (data) {
console.log("doesn't match a username")
console.log("doesn't match a username");
ngModel.$setValidity('exists', false);
} else if (data) {
console.log("matches a username")
ngModel.$setValidity('exists', true);
}
});
}

View File

@ -62,13 +62,16 @@ block content
span.landing-icon.ion-checkmark-circled.text-primary
- if (cc)
form.form-horizontal(novalidate='novalidate', name='completedWithForm')
.form-group.text-center
label(for="existingUserName") If you paired with someone, enter their username here.
.col-xs-10.col-xs-offset-1.col-sm-8.col-sm-offset-2.col-md-8.col-md-offset-2
input.form-control#completed-with(name="existingUser", placeholder='Otherwise just leave it blank', existing-username='', ng-model="existingUser")
.col-xs-10.col-xs-offset-1.col-sm-8.col-sm-offset-2.col-md-8.col-md-offset-2(ng-show="completedWithForm.$error.exists && !completedWithForm.existingUser.$pristine")
alert(type='danger')
span.ion-close-circled
| Username not found
input.form-control#completed-with(name="completed-with", placeholder="If you paired with someone, enter their username here", ng-keypress='', existing-username='', ng-model="existingUsername")
.col-sm-4.col-sm-offset-5(ng-show="completedWithForm.existingUsername.$error.unique && !completedWithForm.existingUsername.$pristine")
alert(type='danger')
span.ion-close-circled
| Username not found
a.animated.fadeIn.btn.btn-lg.btn-primary.btn-block.next-bonfire-button(name='_csrf', value=_csrf, aria-hidden='true', ng-disabled='completedWithForm.$invalid') Take me to my next challenge
a.animated.fadeIn.btn.btn-lg.btn-primary.btn-block.next-bonfire-button(name='_csrf', value=_csrf, aria-hidden='true', ng-disabled='completedWithForm.$invalid') Take me to my next challenge
- if (points && points > 2)