PageSourceSearch

https://www.ceprinter.com/home/js/services/userService.js

js ceprinter.com collected 2026-10-07 04:08:34 UTC 3,791 bytes, 150 lines download raw bytes

1four51.app.factory('User', ['$q', '$rootScope', '$resource', '$451', 'Security', 'Error', function($q, $rootScope, $resource, $451, Security, Error) {
2	var _cacheName = '451Cache.User.' + $451.apiName;
3	function _then(fn, data) {
4		if (angular.isFunction(fn))
5			fn(data);
6	}
7
8	function _extend(u) {
9		u.Permissions.contains = function(value) {
10			return $451.contains(u.Permissions, value);
11		};
12		if ($451.contains(u.Permissions, ['PayByVisa', 'PayByMasterCard', 'PayByAmex', 'PayByDiscover', 'PayByDinersClub', 'PayByJCB', 'PayByDelta', 'PayBySwitch', 'PayBySolo', 'PayByElectron', 'PayByLaser']))
13			u.Permissions.push('PayByCreditCard');
14
15		angular.forEach(u.CustomFields, function(f) {
16			if (f.ControlType == 'File' && f.File && f.File.Url.indexOf('auth') == -1)
17				f.File.Url += "&auth=" + Security.auth();
18		});
19		if(u.Company.POIDMask){
20			u.Company.POIDMask = u.Company.POIDMask.toUpperCase();
21		}
22	}
23
24	var _refresh = function() {
25		store.remove(_cacheName);
26		_get();
27	};
28
29	var _get = function(success) {
30		var user = store.get(_cacheName);
31		user ? (function() { _extend(user); _then(success,user); })() :
32			$resource($451.api('user')).get().$promise.then(function(u) {
33				_extend(u);
34				_then(success,u);
35				store.set(_cacheName, u);
36			});
37	};
38
39	var _save = function(user, success, error) {
40		$resource($451.api('user')).save(user).$promise.then(
41			function(u) {
42				_extend(u);
43				_then(success,u);
44				store.set(_cacheName, u);
45			},
46			function(ex) {
47				if (angular.isFunction(error))
48					error(Error.format(ex));
49			}
50		);
51	};
52
53	var _login = function(credentials, success, error) {
54		store.clear();
55		if(credentials.CurrentPassword && !credentials.NewPassword){
56			delete credentials.CurrentPassword;
57		}
58		if(!credentials.Username && !credentials.Password && !credentials.Email){
59			credentials = {};
60			credentials.Username = null;
61			credentials.Password = null;
62		}
63		$resource($451.api('login/user')).save(credentials).$promise.then(
64			function(u) {
65				if(credentials.CurrentOrderID){
66					_setorder(credentials.CurrentOrderID,success,error);
67				}
68				else{
69					_then(success, u);
70				}
71			},
72			function(ex) {
73				if (angular.isFunction(error))
74					error(Error.format(ex));
75			}
76		);
77	};
78
79	var _reset = function(credentials, success, error) {
80		store.clear();
81		$resource($451.api('login')).save(credentials).$promise.then(
82			function(u) {
83				if(credentials.CurrentOrderID){
84					_setorder(credentials.CurrentOrderID,success,error);
85				}
86				else{
87					_then(success, u);
88				}
89			},
90			function(ex) {
91				if (angular.isFunction(error)) {
92					error(Error.format(ex));
93				}
94			}
95		)
96	};
97
98	var _setorder = function(id, success, error) {
99		$resource($451.api('user/currentorder/:id'), { id: '@id' }).save({ id: id }).$promise.then(
100			function(data) {
101				store.set(_cacheName, data);
102				_then(success, data);
103			},
104			function(ex) {
105				if (error)
106					error(Error.format(ex));
107			}
108		);
109	};
110
111	var _startneworder = function(user, success, error) {
112		user.CurrentOrderID = null;
113		$resource($451.api('/user/neworder')).save().$promise.then(
114			function(user) {
115				store.set(_cacheName, user);
116				$rootScope.$broadcast('event:orderUpdate', null);
117				_then(success, user);
118			},
119			function(ex) {
120				if (error)
121					error(Error.format(ex));
122			}
123		);
124	};
125
126	var _logout = function(credentials, success, error) {
127		store.clear();
128		$resource($451.api('logout/user')).save(credentials).$promise.then(
129			function(u) {
130				Security.logout();
131				_then(success, u);
132			},
133			function(ex) {
134				if (angular.isFunction(error))
135					error(Error.format(ex));
136			}
137		);
138	};
139
140	return {
141		get: _get,
142		login: _login,
143		save: _save,
144		logout: _logout,
145		refresh: _refresh,
146		reset: _reset,
147		setcurrentorder: _setorder,
148		startneworder: _startneworder
149	};
150}]);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.