// Shorthand for $( document ).ready() $(function() { /*--------------------------------------------------- CHECKING THE URL FOR PARAMETERS (USER REDIRECTION) ------------------------------------------------------*/ /*Get the dynamic variables stored in the url as parameters and store them as JavaScript variables ready for use in the code:*/ // example.com?param1=name¶m2=&id=6 // $.urlParam('param1'); // name // $.urlParam('id'); // 6 // $.urlParam('param2'); // null $.urlParam = function(name) { var results = new RegExp('[\?&]' + name + '=([^]*)').exec(window.location .href); // user is not redirected from the email activation link if (results === null) { return null; } // user is redirected from the email activation link else { return results[1] || 0; } }; /*-------- USER EMAIL ACTIVATED OR NOT ---------*/ /* When activation.php returns the varification variable: (redirecting the user to the page)*/ //store the parameter in a variable var emailVerification = $.urlParam('verification'); /*verification sucessful, parameter is true*/ if (emailVerification !== null && emailVerification === 'true') { //create an html for the activation fail message var verificationMessage_true = "
Great! Your email is activated. You can now log in!
Sorry, we couldn't activate your email :(
Please contact us at hello@ethicscanvas.org and we will fix it for you.
Great! Your password has been changed. You can now log in!
Sorry, We couldn't change your password :(
Please contact us at hello@ethicscanvas.org and we will fix it for you.
Something went wrong! Please contact us at hello@ethicscanvas.org.
' ); /*user is already registered*/ } else if (data == 401) { $('.sign-up-in').find('.form-login-feedback ').addClass( 'info-feedback').html( 'You are already registered. Please log in!
'); //have the log in pill field activated $('.nav-tabs a[href="#login-tab"]').tab('show'); // Select tab by name /*put the already entered email in the email input of the login form*/ //the email that the existing user tried to sign up with var user_email = $('.sign-up-form').find('#email-signup') .val(); //put the email in the login form $('.log-in-form').find('#email-login').val(user_email); } else if (data == 201) { $('.sign-up-in').find('.form-signup-feedback ').addClass( 'success-feedback').html( 'Thank you! Please check your email ' + $( "#email-signup").val() + ' and activate your account.
'); } }).fail(function(jqXHR) { console.log("Fail Error -> " + jqXHR.status + ' ' + jqXHR .statustext); }); /* Because the type of the button is submit */ return false; } //end of else }); // end of handling the click on THE Sign Up button /* ------------------------------------------- LOGIN FORM SUBMISSION & SERVER FEEDBACK ---------------------------------------------*/ $('.log-in-form').on('submit', function(event) { var url = "php/log-in.php"; var sign_in_data = $(this).serialize(); /* --------------------------- Post the serialized form data to the log-in.php file -----------------------------*/ $.post(url, { sign_in_data: sign_in_data }, function(data, status) { //Handling LOGIN form feedback from the server if (data == 400) { $('.sign-up-in').find('.form-login-feedback').addClass( 'warning-feedback').html( 'Something went wrong! Please contact us at hello@ethicscanvas.org.
' ); /*user is already registered*/ } else if (data == 401) { $('.sign-up-in').find('.form-login-feedback').addClass( 'warning-feedback').html( 'The username or password is incorrect. Please try again!
' ); } else if (data == 200) { $('.sign-up-in').find('.form-login-feedback ').addClass( 'success-feedback').html( 'Great! Going to the canvas now...
'); /*Send the user to their canvas dashbord*/ window.location.href = 'canvas/php/dashboard.php'; } else if (data == 402) { $('.sign-up-in').find('.form-login-feedback').addClass( 'warning-feedback').html( 'You already have an account. Please activate it in the email we sent you.
' ); } }).fail(function(jqXHR) { console.log("Error " + jqXHR.status + ' ' + jqXHR.statustext); }); /* Because the type of the button is submit */ return false; }); // end of handling the click on THE Sign Up button /*------------#Resend The Activation Email --------*/ $('.sign-up-in').find('.form-login-feedback').on("click", '.resend-activation', function() { var url = 'php/resend-activation.php'; var email_resend = $('.log-in-form').find('#email-login').serialize(); $.post(url, { email_resend: email_resend }, function(data, status) { console.log( 'User clicked on resend activation email: \n' + 'RESPONSE from resend-activation.php => \n' + 'data:' + data + '\n status: ' + status); }); //end of post }); //end of on click for resending activation /*------------#Forgot password --------*/ $('.log-in-form').find('.forgot-password').on("click", 'a', function(e) { e.preventDefault(); //have the reset password pill field activated $('.nav-tabs a[href="#reset-password-tab"]').tab('show'); // Select tab by name //get the value of the email input field in the login form var email_to_reset = $('.log-in-form').find('#email-login').val(); /*if the user already entered an email address here, and it's a valid email*/ /* put that email address in the input field of the password reset*/ if (email_to_reset !== null && ValidateEmail($("#email-login").val())) { $('.reset-password-form').find('#email-reset-password').val( email_to_reset); } }); //end of click on forgot the password link /*--------------- #Reset password ----------------*/ $('.reset-password-form').on('submit', function() { var url = 'php/reset-password.php'; var reset_password = $('.reset-password-form').find( '#email-reset-password').serialize(); $.post(url, { reset_password: reset_password }, function(data, status) { if (data == 400) { $('.sign-up-in').find('.form-reset-password-feedback').addClass('warning-feedback').html('Something is not right. :/ Please contact us at hello@thicscanvas.org
'); } else if (data == 401) { $('.sign-up-in').find('.form-reset-password-feedback').addClass('warning-feedback').html('Please enter a correct email address.
'); } else if (data == 200) { $('.sign-up-in').find('.form-reset-password-feedback').addClass('success-feedback').html('Thank you! :) We sent you an email to reset your password
'); } }); //end of post return false; }); /* ------------------------------------------- Inline FRONT END FORM VALIDATION ---------------------------------------------*/ /* ------- Validating the sign up form ------------ */ $(".sign-up-form").on("click", '.sign-up', function() { var user_name = $('#firstname-signup').val(); if (user_name === '') { $('#name-register-message').addClass('message-field').text( "Please enter your name."); } else { $('#name-register-message').removeClass('message-field').text( ""); } if (!ValidateEmail($("#email-signup").val())) { $('#email-register-message').addClass('message-field').text( 'Please enter a valid email address.'); } else { $('#email-register-message').removeClass('message-field') .text( ""); } var pass1 = $('#password-signup').val(); var pass2 = $('#password-signup-conf').val(); if (pass1 === '') { $('#pass-register-message').addClass('message-field').text( "Please enter a password."); } if (pass2 === '') { $('#pass-conf-register-message').addClass('message-field') .text( "Please confirm your password."); } if (pass1 !== '' && pass2 !== '' && pass1 !== pass2) { $('#pass-register-message, #pass-conf-register-message').addClass( 'message-field').text( "Passwords don't match."); } if (pass1 !== '' && pass2 !== '' && pass1 === pass2) { $('#pass-register-message, #pass-conf-register-message').removeClass( 'message-field').text( ""); } }); /* -------- Validating the log in form ---------- */ $(".log-in-form").on("click", '.log-in', function() { if (!ValidateEmail($("#email-login").val())) { $('#email-login-message').addClass('message-field').text( 'Please enter a valid email address.'); } var pass1b = $('#password-login').val(); if (pass1b === '') { $('#pass-login-message').addClass('message-field').text( "Please enter your password."); } }); /* -------- Validating the password reset form ---------- */ $('.reset-password-form').on('click', '#reset-password-btn', function() { // if the email input field is empty if ($('.reset-password-form').find( '#email-reset-password').val() === '') { $('.reset-password-form').find('#reset-password-message').addClass('message-field').text('Please enter your email.'); } }); // end of click on reset }); // end of jQuery file