aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/public/js/views
diff options
context:
space:
mode:
authorDennis Eriksen <dennis.se@gmail.com>2013-03-20 12:43:33 +0100
committerDennis Eriksen <dennis.se@gmail.com>2013-03-20 12:43:33 +0100
commit266767e6b31d4799b218a7dc9ffd0d6f2eca92a8 (patch)
treee3e68b3acdfb276cadcc23d0028a6c1dd3bc8f21 /public/js/views
parentEdited "Sign in" button - for fun (diff)
downloadDivid-266767e6b31d4799b218a7dc9ffd0d6f2eca92a8.tar.gz
login screen
Diffstat (limited to 'public/js/views')
-rw-r--r--public/js/views/home.js49
-rw-r--r--public/js/views/login.js51
-rw-r--r--public/js/views/reset.js27
-rw-r--r--public/js/views/signup.js39
4 files changed, 166 insertions, 0 deletions
diff --git a/public/js/views/home.js b/public/js/views/home.js
new file mode 100644
index 0000000..eda246a
--- /dev/null
+++ b/public/js/views/home.js
@@ -0,0 +1,49 @@
+
+$(document).ready(function(){
+
+ var hc = new HomeController();
+ var av = new AccountValidator();
+
+ $('#account-form').ajaxForm({
+ beforeSubmit : function(formData, jqForm, options){
+ if (av.validateForm() == false){
+ return false;
+ } else{
+ // push the disabled username field onto the form data array //
+ formData.push({name:'user', value:$('#user-tf').val()})
+ return true;
+ }
+ },
+ success : function(responseText, status, xhr, $form){
+ if (status == 'success') hc.onUpdateSuccess();
+ },
+ error : function(e){
+ if (e.responseText == 'email-taken'){
+ av.showInvalidEmail();
+ } else if (e.responseText == 'username-taken'){
+ av.showInvalidUserName();
+ }
+ }
+ });
+ $('#name-tf').focus();
+ $('#github-banner').css('top', '41px');
+
+// customize the account settings form //
+
+ $('#account-form h1').text('Account Settings');
+ $('#account-form #sub1').text('Here are the current settings for your account.');
+ $('#user-tf').attr('disabled', 'disabled');
+ $('#account-form-btn1').html('Delete');
+ $('#account-form-btn1').addClass('btn-danger');
+ $('#account-form-btn2').html('Update');
+
+// setup the confirm window that displays when the user chooses to delete their account //
+
+ $('.modal-confirm').modal({ show : false, keyboard : true, backdrop : true });
+ $('.modal-confirm .modal-header h3').text('Delete Account');
+ $('.modal-confirm .modal-body p').html('Are you sure you want to delete your account?');
+ $('.modal-confirm .cancel').html('Cancel');
+ $('.modal-confirm .submit').html('Delete');
+ $('.modal-confirm .submit').addClass('btn-danger');
+
+}) \ No newline at end of file
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("<b> Error!</b> 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
diff --git a/public/js/views/reset.js b/public/js/views/reset.js
new file mode 100644
index 0000000..c6a6166
--- /dev/null
+++ b/public/js/views/reset.js
@@ -0,0 +1,27 @@
+
+$(document).ready(function(){
+
+ var rv = new ResetValidator();
+
+ $('#set-password-form').ajaxForm({
+ beforeSubmit : function(formData, jqForm, options){;
+ rv.hideAlert();
+ if (rv.validatePassword($('#pass-tf').val()) == false){
+ return false;
+ } else{
+ return true;
+ }
+ },
+ success : function(responseText, status, xhr, $form){
+ rv.showSuccess("Your password has been reset.");
+ setTimeout(function(){ window.location.href = '/'; }, 3000);
+ },
+ error : function(){
+ rv.showAlert("I'm sorry something went wrong, please try again.");
+ }
+ });
+
+ $('#set-password').modal('show');
+ $('#set-password').on('shown', function(){ $('#pass-tf').focus(); })
+
+}); \ No newline at end of file
diff --git a/public/js/views/signup.js b/public/js/views/signup.js
new file mode 100644
index 0000000..52de197
--- /dev/null
+++ b/public/js/views/signup.js
@@ -0,0 +1,39 @@
+
+$(document).ready(function(){
+
+ var av = new AccountValidator();
+ var sc = new SignupController();
+
+ $('#account-form').ajaxForm({
+ beforeSubmit : function(formData, jqForm, options){
+ return av.validateForm();
+ },
+ success : function(responseText, status, xhr, $form){
+ if (status == 'success') $('.modal-alert').modal('show');
+ },
+ error : function(e){
+ if (e.responseText == 'email-taken'){
+ av.showInvalidEmail();
+ } else if (e.responseText == 'username-taken'){
+ av.showInvalidUserName();
+ }
+ }
+ });
+ $('#name-tf').focus();
+
+// customize the account signup form //
+
+ $('#account-form h1').text('Signup');
+ $('#account-form #sub1').text('Please tell us a little about yourself');
+ $('#account-form #sub2').text('Choose your username & password');
+ $('#account-form-btn1').html('Cancel');
+ $('#account-form-btn2').html('Submit');
+ $('#account-form-btn2').addClass('btn-primary');
+
+// setup the alert that displays when an account is successfully created //
+
+ $('.modal-alert').modal({ show : false, keyboard : false, backdrop : 'static' });
+ $('.modal-alert .modal-header h3').text('Success!');
+ $('.modal-alert .modal-body p').html('Your account has been created.</br>Click OK to return to the login page.');
+
+}) \ No newline at end of file