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