var Login = function () { var handleLogin = function() { $('.login-form').ajaxForm({ dataType: 'json', beforeSubmit: function(){ if(!$('.login-form').validate().form()) { return false; } }, success: function(data){ if(data.message !== 'ok') { $.notify(data.message, 'danger'); } else { window.location.replace(MC.baseUrl+"dashboard_user"); } } }); $('.login-form input').keypress(function (e) { if (e.which == 13) { if ($('.login-form').validate().form()) { $('.login-form').submit(); } return false; } }); } var handleForm = function(loginForm, forgotForm) { $(forgotForm).hide(); $(loginForm).find('a#forgot-true').click(function() { $(forgotForm).show(); $(loginForm).hide(); }); $(forgotForm).find('a#forgot-false').click(function() { $(forgotForm).hide(); $(loginForm).show(); }); $(forgotForm).ajaxForm({ dataType: 'json', beforeSubmit: function(){ $(forgotForm).find('.loader-forgot').show(); }, success: function(response){ $(forgotForm).find('.loader-forgot').hide(); if(response.errors) { $.notify(response.errors.message, 'error'); }else { $.notify(response.data.message, 'success'); setTimeout(function() { window.location = MC.baseUrl + 'home'; }, 3000); } } }); } return { //main function to initiate the module init: function () { handleLogin(); handleForm('form.login-form', 'form.forgot-form'); }, reloadCaptcha:function (reload,capimage){ reload.click(function(){ $.ajax({ url: MC.baseUrl + 'main/reload_captcha/', type: 'POST', success: function(response) { capimage.html(response.data); } }); }); } }; }();