diff --git a/controllers/user.js b/controllers/user.js index e0e9ae3d7f..07edf0e9f5 100644 --- a/controllers/user.js +++ b/controllers/user.js @@ -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); } }); }; diff --git a/public/js/main.js b/public/js/main.js index 4c812dae1d..c817b94a0d 100644 --- a/public/js/main.js +++ b/public/js/main.js @@ -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); } }); } diff --git a/views/bonfire/show.jade b/views/bonfire/show.jade index 72286d661b..2145bac009 100644 --- a/views/bonfire/show.jade +++ b/views/bonfire/show.jade @@ -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)