/** * Created by kumaran on 1/19/17. */ commonsApp.controller('signInController', [ '$scope', 'signInService','$timeout', function($scope, signInService,$timeout) { var userMail = ''; $scope.isSignInPopupEnabled = false; $scope.isSignInSuccessShown = false; $scope.showLoading = false; $scope.showErrorMsg = false; $scope.autErrorMsg = ""; //Variable to control the close button. By default enable close button $scope.isMandate = false; var accessTerm = " access" $scope.page = accessTerm; $scope.validEmail = true; var targetUrl = undefined; var AUTO_LOGIN_SUCCESS_STRING = "5"; $scope.emailCntrl = {} $scope.emailCntrl.publish = function(labelName, newValue, isValid) { if (isValid && isValid != '') $scope.email = newValue; $scope.showErrorMsg = false; $scope.validEmail = isValid; }; $scope.showSignInPopup = function(page, targetUrl) { $scope.initSignInPopup(userMail); this.targetUrl = targetUrl; $scope.isSignInSuccessShown = false; $scope.showLoading = false; $scope.showErrorMsg = false; $scope.autErrorMsg = ""; $scope.validEmail = true; $scope.isSignInPopupEnabled = true; $scope.page = page; // document.querySelector(".aut-overlay-main").style.display // = "block"; } $scope.$on("mandateAuthentication", function (event, args) { $scope.page = args.page; $scope.showSignInPopup($scope.page,args.targetURL); $scope.isMandate = args.isMandate == undefined ? false : args.isMandate; }); $scope.closeSignInContainer = function() { $scope.isSignInPopupEnabled = false; // document.querySelector(".aut-overlay-main").style.display // = ""; // ?? } $scope.closeSignInSuccessContainer = function() { $scope.isSignInSuccessShown = false; } $scope.initSignInPopup = function(email) { userMail = email; $scope.email = email; } $scope.register = function(){ logout(this.targetUrl,true); } $scope.requestSignInLink = function() { $scope.showErrorMsg = false; $scope.emailCntrl.validateField() var targetLink = this.targetUrl; if ($scope.validEmail == true) { var promise = signInService .requestSignInLink($scope.email, targetLink); $scope.showLoading = true; promise.then(function(response) { var responseData = response.data if (responseData.result == SUCCESS_STRING) { $scope.isSignInPopupEnabled = false; $scope.showLoading = false; $scope.isSignInSuccessShown = true; trackSignInRequest(responseData.memberId, $scope.email, 'Identify Form', false) // TODO: // discuss // with // team // and // document // this } else if(responseData.result == AUTO_LOGIN_SUCCESS_STRING) { $scope.isSignInPopupEnabled = false; $scope.showLoading = false; trackSignInRequest(responseData.memberId, $scope.email, 'Identify Form',true,targetLink) } else { $scope.autErrorMsg = responseData.message; $timeout(function(){ $scope.validEmail=false; $scope.showErrorMsg = true; $scope.showLoading = false; },1000); // responseData.message // showSignInErrorMsg(response.message); // $("#signInForm // input").removeClass("valid"); } }) } } } ]); commonsApp.service('signInService',['$http','Constants',function ($http,Constants) { var baseUrl = Constants.apiUrl; this.requestSignInLink = function(email, targetUrl) { if(targetUrl == undefined) { targetUrl = window.location.href; } var promise = $http.post(baseUrl + "/requestSignInLink.htm?email="+email+'&targetURL='+targetUrl) return promise } }])