Permalink
Browse files

password reset now uses account email as unique lookup id

  • Loading branch information...
1 parent ca7da19 commit 933639a649d72514057d4a505a647833325f348a Stephen Braitsch committed Aug 27, 2012
View
2 app.js
@@ -15,5 +15,5 @@ require('./app/config')(app, exp);
require('./app/server/router')(app);
app.listen(8080, function(){
- console.log("Express server listening on port %d in %s mode", app.address().port, app.settings.env);
+ console.log("Express server listening on port %d in %s mode", app.address().port, app.settings.env);
});
@@ -1,24 +1,24 @@
function HomeController()
-{
-
+{
+
// bind event listeners to button clicks //
var that = this;
-
-// handle user logout //
+
+// handle user logout //
$('#btn-logout').click(function(){ that.attemptLogout(); });
-
-// confirm account deletion //
- $('#account-form-btn1').click(function(){$('.modal-confirm').modal('show')});
-
-// handle account deletion //
+
+// confirm account deletion //
+ $('#account-form-btn1').click(function(){$('.modal-confirm').modal('show')});
+
+// handle account deletion //
$('.modal-confirm .submit').click(function(){ that.deleteAccount(); });
-
+
this.deleteAccount = function()
{
$('.modal-confirm').modal('hide');
- var that = this;
- $.ajax({
+ var that = this;
+ $.ajax({
url: '/delete',
type: 'POST',
data: { id: $('#userId').val()},
@@ -28,7 +28,7 @@ function HomeController()
error: function(jqXHR){
console.log(jqXHR.responseText+' :: '+jqXHR.statusText);
}
- });
+ });
}
this.attemptLogout = function()
@@ -43,25 +43,25 @@ function HomeController()
},
error: function(jqXHR){
console.log(jqXHR.responseText+' :: '+jqXHR.statusText);
- }
+ }
});
- }
-
+ }
+
this.showLockedAlert = function(msg){
- $('.modal-alert').modal({ show : false, keyboard : false, backdrop : 'static' });
+ $('.modal-alert').modal({ show : false, keyboard : false, backdrop : 'static' });
$('.modal-alert .modal-header h3').text('Success!');
$('.modal-alert .modal-body p').html(msg);
$('.modal-alert').modal('show');
$('.modal-alert button').click(function(){window.location.href = '/';})
- setTimeout(function(){window.location.href = '/';}, 3000);
+ setTimeout(function(){window.location.href = '/';}, 3000);
}
}
HomeController.prototype.onUpdateSuccess = function()
{
- $('.modal-alert').modal({ show : false, keyboard : true, backdrop : true });
+ $('.modal-alert').modal({ show : false, keyboard : true, backdrop : true });
$('.modal-alert .modal-header h3').text('Success!');
- $('.modal-alert .modal-body p').html('Your account has been updated.');
+ $('.modal-alert .modal-body p').html('Your account has been updated.');
$('.modal-alert').modal('show');
$('.modal-alert button').off('click');
}
@@ -1,14 +1,14 @@
function LoginController()
{
-
-// bind event listeners to button clicks //
+
+// bind event listeners to button clicks //
$('#login-form #forgot-password').click(function(){ $('#get-credentials').modal('show');});
// automatically toggle focus between the email modal window and the login form //
$('#get-credentials').on('shown', function(){ $('#email-tf').focus(); });
$('#get-credentials').on('hidden', function(){ $('#user-tf').focus(); });
-
+
}
@@ -3,7 +3,7 @@ function SignupController()
{
// redirect to homepage when cancel button is clicked //
$('#account-form-btn1').click(function(){ window.location.href = '/';});
-
-// redirect to homepage on new account creation, add short delay so user can read alert window //
- $('.modal-alert #ok').click(function(){ setTimeout(function(){window.location.href = '/';}, 300)});
+
+// redirect to homepage on new account creation, add short delay so user can read alert window //
+ $('.modal-alert #ok').click(function(){ setTimeout(function(){window.location.href = '/';}, 300)});
}
@@ -1,14 +1,14 @@
function AccountValidator(){
-
+
// build array maps of the form inputs & control groups //
- this.formFields = [$('#name-tf'), $('#email-tf'), $('#user-tf'), $('#pass-tf')];
+ this.formFields = [$('#name-tf'), $('#email-tf'), $('#user-tf'), $('#pass-tf')];
this.controlGroups = [$('#name-cg'), $('#email-cg'), $('#user-cg'), $('#pass-cg')];
// bind the form-error modal window to this controller to display any errors //
- this.alert = $('.modal-form-errors');
+ this.alert = $('.modal-form-errors');
this.alert.modal({ show : false, keyboard : true, backdrop : true});
this.validateName = function(s)
@@ -28,19 +28,19 @@ function AccountValidator(){
this.validateEmail = function(e)
{
- var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
- return re.test(e);
- }
+ var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
+ return re.test(e);
+ }
this.showErrors = function(a)
{
$('.modal-form-errors .modal-body p').text('Please correct the following problems :');
var ul = $('.modal-form-errors .modal-body ul');
ul.empty();
for (var i=0; i < a.length; i++) ul.append('<li>'+a[i]+'</li>');
- this.alert.modal('show');
+ this.alert.modal('show');
}
-
+
}
AccountValidator.prototype.showInvalidEmail = function()
@@ -51,8 +51,8 @@ AccountValidator.prototype.showInvalidEmail = function()
AccountValidator.prototype.showInvalidUserName = function()
{
- this.controlGroups[2].addClass('error');
- this.showErrors(['That username is already in use.']);
+ this.controlGroups[2].addClass('error');
+ this.showErrors(['That username is already in use.']);
}
AccountValidator.prototype.validateForm = function()
@@ -66,15 +66,15 @@ AccountValidator.prototype.validateForm = function()
this.controlGroups[1].addClass('error'); e.push('Please Enter A Valid Email');
}
if (this.validateName(this.formFields[2].val()) == false) {
- this.controlGroups[2].addClass('error');
+ this.controlGroups[2].addClass('error');
e.push('Please Choose A Username');
}
if (this.validatePassword(this.formFields[3].val()) == false) {
- this.controlGroups[3].addClass('error');
+ this.controlGroups[3].addClass('error');
e.push('Password Should Be At Least 6 Characters');
}
if (e.length) this.showErrors(e);
return e.length === 0;
}
-
+
@@ -1,15 +1,15 @@
function EmailValidator(){
-
-// bind this to _local for anonymous functions //
-
+
+// bind this to _local for anonymous functions //
+
var _local = this;
-
-// modal window to allow users to request credentials by email //
- _local.retrievePassword = $('#get-credentials');
- _local.retrievePassword.modal({ show : false, keyboard : true, backdrop : true });
- _local.retrievePasswordAlert = $('#get-credentials .alert');
- _local.retrievePassword.on('show', function(){ $('#get-credentials-form').resetForm(); _local.retrievePasswordAlert.hide();});
+
+// modal window to allow users to request credentials by email //
+ _local.retrievePassword = $('#get-credentials');
+ _local.retrievePassword.modal({ show : false, keyboard : true, backdrop : true });
+ _local.retrievePasswordAlert = $('#get-credentials .alert');
+ _local.retrievePassword.on('show', function(){ $('#get-credentials-form').resetForm(); _local.retrievePasswordAlert.hide();});
}
@@ -23,7 +23,7 @@ EmailValidator.prototype.showEmailAlert = function(m)
{
this.retrievePasswordAlert.attr('class', 'alert alert-error');
this.retrievePasswordAlert.html(m);
- this.retrievePasswordAlert.show();
+ this.retrievePasswordAlert.show();
}
EmailValidator.prototype.hideEmailAlert = function()
@@ -36,5 +36,4 @@ EmailValidator.prototype.showEmailSuccess = function(m)
this.retrievePasswordAlert.attr('class', 'alert alert-success');
this.retrievePasswordAlert.html(m);
this.retrievePasswordAlert.fadeIn(500);
-}
-
+}
@@ -1,16 +1,16 @@
function LoginValidator(){
-
+
// bind a simple alert window to this controller to display any errors //
-
+
this.loginErrors = $('.modal-alert');
- this.loginErrors.modal({ show : false, keyboard : true, backdrop : true });
+ this.loginErrors.modal({ show : false, keyboard : true, backdrop : true });
this.showLoginError = function(t, m)
{
- $('.modal-alert .modal-header h3').text(t);
- $('.modal-alert .modal-body p').text(m);
- this.loginErrors.modal('show');
+ $('.modal-alert .modal-header h3').text(t);
+ $('.modal-alert .modal-body p').text(m);
+ this.loginErrors.modal('show');
}
}
@@ -19,7 +19,7 @@ LoginValidator.prototype.validateForm = function()
{
if ($('#user-tf').val() == ''){
this.showLoginError('Whoops!', 'Please enter a valid username');
- return false;
+ return false;
} else if ($('#pass-tf').val() == ''){
this.showLoginError('Whoops!', 'Please enter a valid password');
return false;
@@ -1,7 +1,7 @@
function ResetValidator(){
-// modal window to allow users to reset their password //
+// modal window to allow users to reset their password //
this.setPassword = $('#set-password');
this.setPassword.modal({ show : false, keyboard : false, backdrop : 'static' });
this.setPasswordAlert = $('#set-password .alert');
@@ -11,7 +11,7 @@ ResetValidator.prototype.validatePassword = function(s)
{
if (s.length >= 6){
return true;
- } else{
+ } else{
this.showAlert('Password Should Be At Least 6 Characters');
return false;
}
@@ -21,7 +21,7 @@ ResetValidator.prototype.showAlert = function(m)
{
this.setPasswordAlert.attr('class', 'alert alert-error');
this.setPasswordAlert.html(m);
- this.setPasswordAlert.show();
+ this.setPasswordAlert.show();
}
ResetValidator.prototype.hideAlert = function()
@@ -34,5 +34,4 @@ ResetValidator.prototype.showSuccess = function(m)
this.setPasswordAlert.attr('class', 'alert alert-success');
this.setPasswordAlert.html(m);
this.setPasswordAlert.fadeIn(500);
-}
-
+}
@@ -9,7 +9,7 @@ $(document).ready(function(){
if (av.validateForm() == false){
return false;
} else{
- // push the disabled username field onto the form data array //
+ // push the disabled username field onto the form data array //
formData.push({name:'user', value:$('#user-tf').val()})
return true;
}
@@ -11,7 +11,7 @@ $(document).ready(function(){
if (lv.validateForm() == false){
return false;
} else{
- // append 'remember-me' option to formData to write local cookie //
+ // append 'remember-me' option to formData to write local cookie //
formData.push({name:'remember-me', value:$("input:checkbox:checked").length == 1})
return true;
}
@@ -25,11 +25,12 @@ $(document).ready(function(){
});
$('#user-tf').focus();
-// login retrieval form via email //
+// login retrieval form via email //
- var ev = new EmailValidator();
+ var ev = new EmailValidator();
$('#get-credentials-form').ajaxForm({
+ url: '/lost-password',
beforeSubmit : function(formData, jqForm, options){
if (ev.validateEmail($('#email-tf').val())){
ev.hideEmailAlert();
@@ -43,7 +44,7 @@ $(document).ready(function(){
ev.showEmailSuccess("Check your email on how to reset your password.");
},
error : function(){
- ev.showEmailAlert("I'm Sorry. I could not find that email address");
+ ev.showEmailAlert("Sorry. There was a problem, please try again later.");
}
});
@@ -1,16 +1,14 @@
$(document).ready(function(){
- var rv = new ResetValidator();
+ var rv = new ResetValidator();
$('#set-password-form').ajaxForm({
beforeSubmit : function(formData, jqForm, options){;
- rv.hideAlert();
+ rv.hideAlert();
if (rv.validatePassword($('#pass-tf').val()) == false){
return false;
} else{
- // append the pid onto the formData array //
- formData.push({name:'pid', value:$('#pid').val()});
return true;
}
},
@@ -22,7 +20,8 @@ $(document).ready(function(){
rv.showAlert("I'm sorry something went wrong, please try again.");
}
});
+
$('#set-password').modal('show');
$('#set-password').on('shown', function(){ $('#pass-tf').focus(); })
-
+
});
Oops, something went wrong.

0 comments on commit 933639a

Please sign in to comment.