'use strict'; angular .module('user.authservice', []) .factory('AuthService', ['$http', function ($http) { var authService = {}; authService.login = function (credentials) { return $http.post("/cgi-bin/wspd_cgi.sh/WService=WSWMSWebLive/login/customerlogin.p?session=aizzcpkOoppjhlhkdildplrqbcvSdKhB&btnSignIn=Yes&cNoCache=" + (new Date).getTime() + "", credentials) .then(function (res) { authService.cAuthStatus = res.headers().authstatus; authService.isAuthorized = res.data.ttAuthentication[0].lAuthStatus if (!authService.isAuthorized) { authService.cErrorCode = res.data.ttErrors[0].cErrorCode; authService.cErrorMsg = res.data.ttErrors[0].cErrorMsg; authService.cAccessToken = res.data.ttAuthentication[0].cAccessToken; authService.iAuthCode = res.data.ttAuthentication[0].iAuthCode; authService.dWebUsrObj = res.data.ttCredentials[0].dWebUsrObj; authService.iRowVersion = res.data.ttCredentials[0].iRowVersion; } else { authService.cAccessToken = res.data.ttAuthentication[0].cAccessToken; authService.iAuthCode = res.data.ttAuthentication[0].iAuthCode; authService.cRedirection = res.data.ttAuthentication[0].cRedirection; } return authService; }, function (res) { authService.isAuthorized = false; return authService; }); } authService.savePassword = function (p1, p2) { var param = { cPassword: p1, cConfPwd: p2, cFieldId: authService.iAuthCode, cPassKey: authService.cAccessToken, dWebUsrObj: authService.dWebUsrObj, iRowVersion: authService.iRowVersion }; return $http.post("/cgi-bin/wspd_cgi.sh/WService=WSWMSWebLive/login/customerlogin.p?session=aizzcpkOoppjhlhkdildplrqbcvSdKhB&cAjaxRequest=savePassword&cNoCache=" + (new Date).getTime() + "", param) .then(function (res) { authService.status = res.headers().requeststatus; authService.cErrorCode = (res.data.ttErrors ? res.data.ttErrors[0].cErrorCode : ""); authService.cErrorMsg = (res.data.ttErrors ? res.data.ttErrors[0].cErrorMsg : ""); authService.cFieldName = (res.data.ttErrors ? res.data.ttErrors[0].cFieldName : ""); authService.isAuthorized = (res.data.ttAuthentication ? res.data.ttAuthentication[0].lAuthStatus : authService.isAuthorized); authService.cAccessToken = (res.data.ttAuthentication ? res.data.ttAuthentication[0].cAccessToken : authService.cAccessToken); authService.iAuthCode = (res.data.ttAuthentication ? res.data.ttAuthentication[0].iAuthCode : authService.iAuthCode); authService.dWebUsrObj = (res.data.ttCredentials ? res.data.ttCredentials[0].dWebUsrObj : authService.dWebUsrObj); authService.iRowVersion = (res.data.ttCredentials ? res.data.ttCredentials[0].iRowVersion : authService.iRowVersion); return authService; }, function (res) { authService.isAuthorized = false; return authService; }); } authService.forgottenPwd = function (p1,p2) { return $http.post("/cgi-bin/wspd_cgi.sh/WService=WSWMSWebLive/login/customerlogin.p?session=aizzcpkOoppjhlhkdildplrqbcvSdKhB&cAjaxRequest=forgottenPwd&cNoCache=" + (new Date).getTime() + "",{cUserName:p1,cPassKey:p2}) .then(function (res) { authService.status = res.headers().requeststatus; authService.cErrorCode = (res.data.ttErrors ? res.data.ttErrors[0].cErrorCode : ""); authService.cErrorMsg = (res.data.ttErrors ? res.data.ttErrors[0].cErrorMsg : ""); authService.passwordrules = res.data; return authService; }, function (res) { authService.isAuthorized = false; return authService; }); } authService.getPasswordRules = function () { return $http.post("/cgi-bin/wspd_cgi.sh/WService=WSWMSWebLive/login/customerlogin.p?session=aizzcpkOoppjhlhkdildplrqbcvSdKhB&cAjaxRequest=getPasswordRules&cNoCache=" + (new Date).getTime() + "") .then(function (res) { authService.status = res.headers().requeststatus; authService.cErrorCode = (res.data.ttErrors ? res.data.ttErrors[0].cErrorCode : ""); authService.cErrorMsg = (res.data.ttErrors ? res.data.ttErrors[0].cErrorMsg : ""); authService.passwordrules = res.data; return authService; }, function (res) { authService.isAuthorized = false; return authService; }); } authService.submitApplication = function (p1) { return $http.post("/cgi-bin/wspd_cgi.sh/WService=WSWMSWebLive/login/customerlogin.p?session=aizzcpkOoppjhlhkdildplrqbcvSdKhB&cAjaxRequest=submitApplication&cNoCache=" + (new Date).getTime() + "",p1) .then(function (res) { authService.status = res.headers().requeststatus; authService.cErrorCode = (res.data.ttErrors ? res.data.ttErrors[0].cErrorCode : ""); authService.cErrorMsg = (res.data.ttErrors ? res.data.ttErrors[0].cErrorMsg : ""); authService.passwordrules = res.data; return authService; }, function (res) { authService.isAuthorized = false; return authService; }); } return authService; } ]);