Existing username check now working, error box showing and hiding properly, UI tweaks
This commit is contained in:
@ -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);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
@ -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);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -62,12 +62,15 @@ block content
|
||||
span.landing-icon.ion-checkmark-circled.text-primary
|
||||
- if (cc)
|
||||
form.form-horizontal(novalidate='novalidate', name='completedWithForm')
|
||||
|
||||
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")
|
||||
.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
|
||||
|
||||
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
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user