|
|
@@ -690,5 +690,121 @@ define([ 'angular', 'common/services', 'common/utils', 'big'], function(angular,
|
|
|
.factory('B2bCustomer', ['$resource', 'BaseService', function($resource, BaseService){
|
|
|
var b2bPath = BaseService.getB2bUrl();
|
|
|
return $resource(b2bPath + 'vendor/customer/info/search', {}, {});
|
|
|
+ }])
|
|
|
+ .factory('B2bAuthenticationService', ['$http', 'SessionService', 'BaseService', 'SerializerUtil', function($http, SessionService, BaseService, SerializerUtil) {
|
|
|
+ var cacheSession = function() {
|
|
|
+ SessionService.set('authenticated', true);
|
|
|
+ };
|
|
|
+ var uncacheSession = function() {
|
|
|
+ SessionService.unset('authenticated');
|
|
|
+ };
|
|
|
+ var rootPath = BaseService.getB2bUrl();
|
|
|
+ return {
|
|
|
+ root: function() {
|
|
|
+ return rootPath;
|
|
|
+ },
|
|
|
+ logout: function() {
|
|
|
+ var keys = document.cookie.match(/[^ =;]+(?=\=)/g);
|
|
|
+ if(keys) {
|
|
|
+ for(var i = keys.length; i--;)
|
|
|
+ document.cookie = keys[i] + '=0;expires=' + new Date(0).toUTCString()
|
|
|
+ }
|
|
|
+ var config = {
|
|
|
+ cache: false,
|
|
|
+ headers: {
|
|
|
+ 'Cache-Control': 'no-cache',
|
|
|
+ 'Pragma': 'no-cache',
|
|
|
+ },
|
|
|
+ ifModified :true ,
|
|
|
+ };
|
|
|
+ var logout = $http.get(rootPath + "/logout", config);
|
|
|
+ var refresh = function(data) {
|
|
|
+ var pathName = document.location.pathname;
|
|
|
+ var index = pathName.substr(1).indexOf("/");// platform-b2c/logout/proxy
|
|
|
+ var result = pathName.substr(0,index);
|
|
|
+ var uri = pathName.substr(13,index+1000) + document.location.hash;
|
|
|
+ if (result == '/platform-b2b') {
|
|
|
+ var contextPath = ''
|
|
|
+ data.content = contextPath + uri;
|
|
|
+ }
|
|
|
+ if (data.content) {
|
|
|
+ if (data.content == window.location.href) {
|
|
|
+ window.location.reload();
|
|
|
+ } else {
|
|
|
+ window.location.href = data.content;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ logout.success(uncacheSession);
|
|
|
+ logout.success(function(data) {
|
|
|
+ if (data.url) {
|
|
|
+ $.ajax({
|
|
|
+ url: data.url,
|
|
|
+ type: "get",
|
|
|
+ cache: false,
|
|
|
+ dataType: "jsonp",
|
|
|
+ jsonp: "callback",
|
|
|
+ jsonpCallback: "successCallback",
|
|
|
+ success: function (response) {
|
|
|
+ console.log(response);
|
|
|
+ refresh(data);
|
|
|
+ },
|
|
|
+ error: function (response) {
|
|
|
+ console.log(response);
|
|
|
+ refresh(data);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ refresh(data);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return logout;
|
|
|
+ },
|
|
|
+ redirectSignin: function() {
|
|
|
+ $http.get(rootPath + '/login/page').success(function(data) {
|
|
|
+ if (data.content) {
|
|
|
+ window.location.href = data.content;
|
|
|
+ } else {
|
|
|
+ toaster.pop('error', '系统错误');
|
|
|
+ }
|
|
|
+ }).error(function() {
|
|
|
+ toaster.pop('error', '系统错误');
|
|
|
+ });
|
|
|
+ },
|
|
|
+ redirectRegister: function() {
|
|
|
+ // 获取跳转注册的url
|
|
|
+ $http.get(rootPath + '/register/page', {
|
|
|
+ params: {
|
|
|
+ returnUrl: window.location.href
|
|
|
+ }
|
|
|
+ }).success(function(data) {
|
|
|
+ if (data.content) {
|
|
|
+ window.location.href = data.content;
|
|
|
+ } else {
|
|
|
+ alert('系统错误');
|
|
|
+ }
|
|
|
+ }).error(function() {
|
|
|
+ alert('系统错误');
|
|
|
+ });
|
|
|
+ },
|
|
|
+ isAuthed: function() {
|
|
|
+ return SessionService.get('authenticated');
|
|
|
+ },
|
|
|
+ getAuthentication: function() {
|
|
|
+ var request = $http.get(rootPath + '/authentication', {cache: true});
|
|
|
+ request.success(function(data) {
|
|
|
+ if (data) {
|
|
|
+ cacheSession();
|
|
|
+ } else {
|
|
|
+ uncacheSession();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ request.error(uncacheSession);
|
|
|
+ return request;
|
|
|
+ },
|
|
|
+ reSignin: function(enUU) {
|
|
|
+ return $http.get(rootPath + '/authentication/' + enUU);
|
|
|
+ }
|
|
|
+ };
|
|
|
}]);
|
|
|
});
|