From 266767e6b31d4799b218a7dc9ffd0d6f2eca92a8 Mon Sep 17 00:00:00 2001 From: Dennis Eriksen Date: Wed, 20 Mar 2013 12:43:33 +0100 Subject: login screen --- public/js/views/login.js | 51 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 public/js/views/login.js (limited to 'public/js/views/login.js') diff --git a/public/js/views/login.js b/public/js/views/login.js new file mode 100644 index 0000000..27fe31d --- /dev/null +++ b/public/js/views/login.js @@ -0,0 +1,51 @@ + +$(document).ready(function(){ + + var lv = new LoginValidator(); + var lc = new LoginController(); + +// main login form // + + $('#login-form').ajaxForm({ + beforeSubmit : function(formData, jqForm, options){ + if (lv.validateForm() == false){ + return false; + } else{ + // append 'remember-me' option to formData to write local cookie // + formData.push({name:'remember-me', value:$("input:checkbox:checked").length == 1}) + return true; + } + }, + success : function(responseText, status, xhr, $form){ + if (status == 'success') window.location.href = '/home'; + }, + error : function(e){ + lv.showLoginError('Login Failure', 'Please check your username and/or password'); + } + }); + $('#user-tf').focus(); + +// login retrieval form via email // + + var ev = new EmailValidator(); + + $('#get-credentials-form').ajaxForm({ + url: '/lost-password', + beforeSubmit : function(formData, jqForm, options){ + if (ev.validateEmail($('#email-tf').val())){ + ev.hideEmailAlert(); + return true; + } else{ + ev.showEmailAlert(" Error! Please enter a valid email address"); + return false; + } + }, + success : function(responseText, status, xhr, $form){ + ev.showEmailSuccess("Check your email on how to reset your password."); + }, + error : function(){ + ev.showEmailAlert("Sorry. There was a problem, please try again later."); + } + }); + +}) \ No newline at end of file -- cgit v1.2.3