2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ===================================================================
8 * Unless otherwise specified, all software contained herein is licensed
9 * under the Apache License, Version 2.0 (the "License");
10 * you may not use this software except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * Unless otherwise specified, all documentation contained herein is licensed
22 * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
23 * you may not use this documentation except in compliance with the License.
24 * You may obtain a copy of the License at
26 * https://creativecommons.org/licenses/by/4.0/
28 * Unless required by applicable law or agreed to in writing, documentation
29 * distributed under the License is distributed on an "AS IS" BASIS,
30 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31 * See the License for the specific language governing permissions and
32 * limitations under the License.
34 * ============LICENSE_END============================================
39 * Created by nnaffar on 11/22/2015.
45 constructor($q, $log, $http, conf, uuid, utilsService) {
51 this.utilsService = utilsService;
55 let deferred = this.$q.defer();
56 //this.$log.info('AdminsService::get all applications admins list');
60 url: this.conf.api.accountAdmins,
62 'X-ECOMP-RequestID':this.uuid.generate()
66 // If response comes back as a redirected HTML page which IS NOT a success
67 if (this.utilsService.isValidJSON(res)=== false) {
68 this.$log.error('AdminsService::getAccountAdmins Failed');
69 deferred.reject("AdminsService::getAccountAdmins Failed");
71 // this.$log.info('AdminsService::getAccountAdmins Succeeded');
72 deferred.resolve(res.data);
76 this.$log.error('AdminsService::getAccountAdmins Failed', status);
77 deferred.reject(status);
80 return deferred.promise;
83 getAdminAppsRoles(orgUserId) {
84 let deferred = this.$q.defer();
85 //this.$log.info('AdminsService::getAdminAppsRoles.adminAppsRoles');
89 url: this.conf.api.adminAppsRoles,
90 params: {user: orgUserId},
93 'X-ECOMP-RequestID':this.uuid.generate()
96 // If response comes back as a redirected HTML page which IS NOT a success
97 if (this.utilsService.isValidJSON(res)=== false) {
98 this.$log.error('AdminsService::getAdminAppsRoles.adminAppsRoles Failed');
99 deferred.reject("AdminsService::getAdminAppsRoles.adminAppsRoles Failed");
101 // this.$log.info('AdminsService::getAdminAppsRoles.adminAppsRoles Succeeded');
102 deferred.resolve(res.data);
106 this.$log.error('AdminsService::getAdminAppsRoles.adminAppsRoles Failed', status);
107 deferred.reject(status);
110 return deferred.promise;
113 getRolesByApp(appId) {
114 let deferred = this.$q.defer();
115 this.$log.info('AdminsService::getRolesByApp');
116 let url = this.conf.api.adminAppsRoles + '/' + appId;
122 'X-ECOMP-RequestID':this.uuid.generate()
125 // If response comes back as a redirected HTML page which IS NOT a success
126 if (Object.keys(res.data).length == 0) {
127 deferred.reject("AdminsService::getAdminAppsRoles.getRolesByApp Failed");
129 this.$log.info('AdminsService::getAdminAppsRoles.getRolesByApp Succeeded');
130 deferred.resolve(res.data);
134 deferred.reject(status);
137 return deferred.promise;
140 updateAdminAppsRoles(newAdminAppRoles) {
141 let deferred = this.$q.defer();
142 // this.$log.info('AdminsService::updateAdminAppsRoles');
145 url: this.conf.api.adminAppsRoles,
146 data: newAdminAppRoles,
148 'X-ECOMP-RequestID':this.uuid.generate()
151 if (this.utilsService.isValidJSON(res)=== false) {
152 this.$log.error('AdminsService::updateAdminAppsRoles Failed');
153 deferred.reject("AdminsService::updateAdminAppsRoles Failed");
155 //this.$log.info('AdminsService::updateAdminAppsRoles success:');
156 deferred.resolve(res.data);
161 this.$log.error('AdminsService::updateAdminAppsRoles: rejection:' + status);
162 deferred.reject(status);
165 return deferred.promise;
169 * Tests the specified password against complexity requirements.
170 * Returns an explanation message if the test fails; null if it passes.
172 isComplexPassword(str) {
174 let message = 'Password is too simple. Minimum length is '+ minLength + ', '
175 + 'and it must use letters, digits and special characters.';
179 let hasLetter = false;
180 let hasDigit = false;
181 let hasSpecial = false;
183 for (i = 0, len = str.length; i < len; i++) {
184 code = str.charCodeAt(i);
185 if (code > 47 && code < 58) // numeric (0-9)
187 else if ((code > 64 && code < 91) || (code > 96 && code < 123)) // A-Z, a-z
193 if (str.length < minLength || !hasLetter || !hasDigit || !hasSpecial)
200 addNewUser(newUser,checkDuplicate) {
201 // this.$log.info(newContactUs)
202 let deferred = this.$q.defer();
203 // this.$log.info('ContactUsService:: add Contact Us' + JSON.stringify(newContactUs));
206 firstName:newUser.firstName,
207 middleInitial:newUser.middleName,
208 lastName:newUser.lastName,
209 email:newUser.emailAddress,
210 loginId:newUser.loginId,
211 loginPwd:newUser.loginPwd,
214 url: this.conf.api.saveNewUser + "?isCheck=" + checkDuplicate,
218 'X-ECOMP-RequestID':this.uuid.generate()
222 // this.$log.info('ContactUsService:: add Contact Us res' ,res);
223 // If response comes back as a redirected HTML page which IS NOT a success
224 if (res==null || Object.keys(res.data).length == 0 || res.data.message == 'failure') {
225 deferred.reject("Add new User failed");
226 this.$log.error('adminService:: add New User failed');
228 deferred.resolve(res.data);
231 deferred.reject(errRes);
233 return deferred.promise;
237 AdminsService.$inject = ['$q', '$log', '$http', 'conf','uuid4', 'utilsService'];
238 angular.module('ecompApp').service('adminsService', AdminsService)