Adding in existing username checking, NOT WORKING AT THE MOMENT
This commit is contained in:
4
app.js
4
app.js
@ -257,6 +257,7 @@ app.get(
|
||||
|
||||
// Unique Check API route
|
||||
app.get('/api/checkUniqueUsername/:username', userController.checkUniqueUsername);
|
||||
app.get('/api/checkExistingUsername/:username', userController.checkExistingUsername);
|
||||
app.get('/api/checkUniqueEmail/:email', userController.checkUniqueEmail);
|
||||
app.get('/account', userController.getAccount);
|
||||
app.post('/account/profile', userController.postUpdateProfile);
|
||||
@ -286,7 +287,8 @@ app.post('/completed-challenge', function (req, res) {
|
||||
});
|
||||
|
||||
app.post('/completed-bonfire/', function (req, res) {
|
||||
debug(req.body, 'In post method'); // TODO: remove debug statement
|
||||
debug(req.body, 'In post method'
|
||||
); // TODO: remove debug statement
|
||||
req.user.bonfiresHash[parseInt(req.body.bonfireNumber)] =
|
||||
Math.round(+new Date() / 1000);
|
||||
var timestamp = req.user.bonfiresHash;
|
||||
|
@ -184,6 +184,20 @@ exports.checkUniqueUsername = function(req, res) {
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Existing username check
|
||||
*/
|
||||
exports.checkExistingUsername = function(req, res) {
|
||||
User.count({'profile.username': req.params.username.toLowerCase()}, function (err, data) {
|
||||
if (data == 1) {
|
||||
return res.send(false);
|
||||
} else {
|
||||
return res.send(true);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Unique email check API Call
|
||||
*/
|
||||
|
@ -94,6 +94,13 @@ profileValidation.controller('profileValidationController', ['$scope', '$http',
|
||||
}
|
||||
]);
|
||||
|
||||
profileValidation.controller('pairedWithController', ['$scope',
|
||||
function($scope) {
|
||||
|
||||
|
||||
}
|
||||
]);
|
||||
|
||||
profileValidation.controller('emailSignUpController', ['$scope',
|
||||
function($scope) {
|
||||
|
||||
@ -138,6 +145,30 @@ profileValidation.directive('uniqueUsername', function($http) {
|
||||
}
|
||||
}
|
||||
});
|
||||
// TODO: FIX THIS
|
||||
profileValidation.directive('existingUsername', function($http) {
|
||||
return {
|
||||
restrict: 'A',
|
||||
require: 'ngModel',
|
||||
link: function (scope, element, attrs, ngModel) {
|
||||
element.bind("keyup", function (event) {
|
||||
ngModel.$setValidity('exists', true);
|
||||
if (element.val()) {
|
||||
$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")
|
||||
ngModel.$setValidity('exists', false);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
profileValidation.directive('uniqueEmail', function($http) {
|
||||
return {
|
||||
|
@ -55,13 +55,20 @@ block content
|
||||
.modal-content
|
||||
.modal-header.challenge-list-header Nicely done!
|
||||
a.close.closing-x(href='#', data-dismiss='modal', aria-hidden='true') ×
|
||||
.modal-body
|
||||
.modal-body(ng-controller="pairedWithController")
|
||||
|
||||
.text-center
|
||||
.animated.zoomInDown.delay-half
|
||||
span.landing-icon.ion-checkmark-circled.text-primary
|
||||
- if (cc)
|
||||
form.form-horizontal(novalidate='novalidate', name='completedWithForm')
|
||||
|
||||
a.animated.fadeIn.btn.btn-lg.btn-primary.btn-block.next-bonfire-button(name='_csrf', value=_csrf, aria-hidden='true') Take me to my next challenge
|
||||
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
|
||||
|
||||
|
||||
- if (points && points > 2)
|
||||
|
Reference in New Issue
Block a user