Rev 25391 | Rev 33061 | Go to most recent revision | View as "text/plain" | Blame | Compare with Previous | Last modification | View Log | RSS feed
var googleProfile;var partnerName;$(function() {$('form').on('submit', function() {if($(this).find("#password").length > 0) {login();} else {var email=$("#email").val();console.log(email);if(email==""|email==null||email==undefined){alert("Input field email can't be empty");return;}forgetPassword(email);}return false;});$(document).on('click', ".forgetPassword", function() {$("#auth").toggle();$('#forget-password').toggle();});});$(document).ajaxComplete(function() {});var startApp = function() {gapi.load('auth2', function() {// Retrieve the singleton for the GoogleAuth library and set up the// client.auth2 = gapi.auth2.init({client_id : googleApiKey,cookiepolicy : 'single_host_origin',// Request scopes in addition to 'profile' and 'email'// scope: 'additional_scope'});attachSignin(document.getElementById('customBtn'));});};function login() {console.log("Login DashBoard");var emailIdOrMobileNumber = $("#emailormobile").val();console.log(emailormobile);var password = $("input[type='password']").val();if (emailIdOrMobileNumber == "" || emailIdOrMobileNumber == undefined || emailIdOrMobileNumber == null) {alert("Input field emailIdOrMobileNumber can't be empty")return;}if (password == "" || password == null || password == undefined) {alert("password can't be empty")return;}submitUser(null, emailIdOrMobileNumber, password)}function attachSignin(element) {console.log(element.id);auth2.attachClickHandler(element, {}, function(googleUser) {googleProfile = googleUser.getBasicProfile();console.log(googleProfile.getImageUrl());submitUser(googleUser, googleProfile.getEmail(),null);}, function(error) {console.log(JSON.stringify(error, undefined, 2));});}function submitUser(googleUser, emailIdOrMobileNumber, password) {if (googleUser) {var params = {"token" : googleUser.getAuthResponse().id_token,"emailIdOrMobileNumber" : emailIdOrMobileNumber,"password" : ""};} else {var params = {"token":"","emailIdOrMobileNumber" : emailIdOrMobileNumber,"password" : password};}// var response = doPostAjaxRequestWithParams(context+"/login", params);doAjaxRequestWithParamsHandler(context + "/login", "POST", params,function(response) {response = JSON.parse(response);if (response.status) {if(response.name){partnerName=response.name;}addProfileInLocalDb();window.location.href = response.redirectUrl;} else {alert("Retailer not found, Please login");}});}function forgetPassword(emailId){var params={"emailId":emailId}doAjaxRequestWithParamsHandler(context + "/forgetPassword", "POST", params,function(response) {if(response=="true"){$("#login-container").css('display', 'none');$('#forget-password').css('display', 'inline-block');$("#reset-password").css('display', 'none');$('#send-password').css('display', 'inline-block');}});}function addProfileInLocalDb() {if(googleProfile){var profile = {'image_url' : googleProfile.getImageUrl(),'name' : googleProfile.getName()};console.log(googleProfile.getImageUrl);console.log(googleProfile.getName());localStorage.setItem("profile", JSON.stringify(profile));}else{var profile = {'image_url' : "",'name' : partnerName};console.log(partnerName);//console.log(googleProfile.getName());localStorage.setItem("profile", JSON.stringify(profile));}}