2 * ================================================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ================================================================================
21 * Created by nnaffar on 11/22/2015.
27 constructor($q, $log, $http, conf, uuid, utilsService) {
33 this.utilsService = utilsService;
37 let deferred = this.$q.defer();
38 //this.$log.info('AdminsService::get all applications admins list');
42 url: this.conf.api.accountAdmins,
44 'X-ECOMP-RequestID':this.uuid.generate()
48 // If response comes back as a redirected HTML page which IS NOT a success
49 if (this.utilsService.isValidJSON(res)=== false) {
50 this.$log.error('AdminsService::getAccountAdmins Failed');
51 deferred.reject("AdminsService::getAccountAdmins Failed");
53 // this.$log.info('AdminsService::getAccountAdmins Succeeded');
54 deferred.resolve(res.data);
58 this.$log.error('AdminsService::getAccountAdmins Failed', status);
59 deferred.reject(status);
62 return deferred.promise;
65 getAdminAppsRoles(orgUserId) {
66 let deferred = this.$q.defer();
67 //this.$log.info('AdminsService::getAdminAppsRoles.adminAppsRoles');
71 url: this.conf.api.adminAppsRoles,
72 params: {user: orgUserId},
75 'X-ECOMP-RequestID':this.uuid.generate()
78 // If response comes back as a redirected HTML page which IS NOT a success
79 if (this.utilsService.isValidJSON(res)=== false) {
80 this.$log.error('AdminsService::getAdminAppsRoles.adminAppsRoles Failed');
81 deferred.reject("AdminsService::getAdminAppsRoles.adminAppsRoles Failed");
83 // this.$log.info('AdminsService::getAdminAppsRoles.adminAppsRoles Succeeded');
84 deferred.resolve(res.data);
88 this.$log.error('AdminsService::getAdminAppsRoles.adminAppsRoles Failed', status);
89 deferred.reject(status);
92 return deferred.promise;
95 getRolesByApp(appId) {
96 let deferred = this.$q.defer();
97 this.$log.info('AdminsService::getRolesByApp');
98 let url = this.conf.api.adminAppsRoles + '/' + appId;
104 'X-ECOMP-RequestID':this.uuid.generate()
107 // If response comes back as a redirected HTML page which IS NOT a success
108 if (Object.keys(res.data).length == 0) {
109 deferred.reject("AdminsService::getAdminAppsRoles.getRolesByApp Failed");
111 this.$log.info('AdminsService::getAdminAppsRoles.getRolesByApp Succeeded');
112 deferred.resolve(res.data);
116 deferred.reject(status);
119 return deferred.promise;
122 updateAdminAppsRoles(newAdminAppRoles) {
123 let deferred = this.$q.defer();
124 // this.$log.info('AdminsService::updateAdminAppsRoles');
127 url: this.conf.api.adminAppsRoles,
128 data: newAdminAppRoles,
130 'X-ECOMP-RequestID':this.uuid.generate()
133 if (this.utilsService.isValidJSON(res)=== false) {
134 this.$log.error('AdminsService::updateAdminAppsRoles Failed');
135 deferred.reject("AdminsService::updateAdminAppsRoles Failed");
137 //this.$log.info('AdminsService::updateAdminAppsRoles success:');
138 deferred.resolve(res.data);
143 this.$log.error('AdminsService::updateAdminAppsRoles: rejection:' + status);
144 deferred.reject(status);
147 return deferred.promise;
151 * Tests the specified password against complexity requirements.
152 * Returns an explanation message if the test fails; null if it passes.
154 isComplexPassword(str) {
156 let message = 'Password is too simple. Minimum length is '+ minLength + ', '
157 + 'and it must use letters, digits and special characters.';
161 let hasLetter = false;
162 let hasDigit = false;
163 let hasSpecial = false;
165 for (i = 0, len = str.length; i < len; i++) {
166 code = str.charCodeAt(i);
167 if (code > 47 && code < 58) // numeric (0-9)
169 else if ((code > 64 && code < 91) || (code > 96 && code < 123)) // A-Z, a-z
175 if (str.length < minLength || !hasLetter || !hasDigit || !hasSpecial)
182 addNewUser(newUser,checkDuplicate) {
183 // this.$log.info(newContactUs)
184 let deferred = this.$q.defer();
185 // this.$log.info('ContactUsService:: add Contact Us' + JSON.stringify(newContactUs));
188 firstName:newUser.firstName,
189 middleInitial:newUser.middleName,
190 lastName:newUser.lastName,
191 email:newUser.emailAddress,
192 loginId:newUser.loginId,
193 loginPwd:newUser.loginPwd,
196 url: this.conf.api.saveNewUser + "?isCheck=" + checkDuplicate,
200 'X-ECOMP-RequestID':this.uuid.generate()
204 // this.$log.info('ContactUsService:: add Contact Us res' ,res);
205 // If response comes back as a redirected HTML page which IS NOT a success
206 if (res==null || Object.keys(res.data).length == 0 || res.data.message == 'failure') {
207 deferred.reject("Add new User failed");
208 this.$log.error('adminService:: add New User failed');
210 deferred.resolve(res.data);
213 deferred.reject(errRes);
215 return deferred.promise;
219 AdminsService.$inject = ['$q', '$log', '$http', 'conf','uuid4', 'utilsService'];
220 angular.module('ecompApp').service('adminsService', AdminsService)