-/*-\r
- * ================================================================================\r
- * ECOMP Portal\r
- * ================================================================================\r
- * Copyright (C) 2017 AT&T Intellectual Property\r
- * ================================================================================\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- * \r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- * \r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- * ================================================================================\r
- */\r
-/**\r
- * Created by nnaffar on 11/22/2015.\r
- */\r
-'use strict';\r
-\r
-(function () {\r
- class AdminsService {\r
- constructor($q, $log, $http, conf, uuid, utilsService) {\r
- this.$q = $q;\r
- this.$log = $log;\r
- this.$http = $http;\r
- this.conf = conf;\r
- this.uuid = uuid;\r
- this.utilsService = utilsService;\r
- }\r
-\r
- getAccountAdmins() {\r
- let deferred = this.$q.defer();\r
- //this.$log.info('AdminsService::get all applications admins list');\r
- this.$http({\r
- method: "GET",\r
- cache: false,\r
- url: this.conf.api.accountAdmins,\r
- headers: {\r
- 'X-ECOMP-RequestID':this.uuid.generate()\r
- }\r
- })\r
- .then( res => {\r
- // If response comes back as a redirected HTML page which IS NOT a success\r
- if (this.utilsService.isValidJSON(res)=== false) {\r
- this.$log.error('AdminsService::getAccountAdmins Failed');\r
- deferred.reject("AdminsService::getAccountAdmins Failed");\r
- } else {\r
- // this.$log.info('AdminsService::getAccountAdmins Succeeded');\r
- deferred.resolve(res.data);\r
- }\r
- })\r
- .catch( status => {\r
- this.$log.error('AdminsService::getAccountAdmins Failed', status);\r
- deferred.reject(status);\r
- });\r
- \r
- return deferred.promise;\r
- }\r
-\r
- getAdminAppsRoles(orgUserId) {\r
- let deferred = this.$q.defer();\r
- //this.$log.info('AdminsService::getAdminAppsRoles.adminAppsRoles');\r
-\r
- this.$http({\r
- method: "GET",\r
- url: this.conf.api.adminAppsRoles,\r
- params: {user: orgUserId},\r
- cache: false,\r
- headers: {\r
- 'X-ECOMP-RequestID':this.uuid.generate()\r
- }\r
- }).then( res => {\r
- // If response comes back as a redirected HTML page which IS NOT a success\r
- if (this.utilsService.isValidJSON(res)=== false) {\r
- this.$log.error('AdminsService::getAdminAppsRoles.adminAppsRoles Failed');\r
- deferred.reject("AdminsService::getAdminAppsRoles.adminAppsRoles Failed");\r
- } else {\r
- // this.$log.info('AdminsService::getAdminAppsRoles.adminAppsRoles Succeeded');\r
- deferred.resolve(res.data);\r
- }\r
- })\r
- .catch( status => {\r
- this.$log.error('AdminsService::getAdminAppsRoles.adminAppsRoles Failed', status);\r
- deferred.reject(status);\r
- });\r
-\r
- return deferred.promise;\r
- }\r
- /*Author: Rui*/\r
- getRolesByApp(appId) {\r
- let deferred = this.$q.defer();\r
- this.$log.info('AdminsService::getRolesByApp');\r
- let url = this.conf.api.adminAppsRoles + '/' + appId;\r
- this.$http({\r
- method: "GET",\r
- url: url,\r
- cache: false,\r
- headers: {\r
- 'X-ECOMP-RequestID':this.uuid.generate()\r
- }\r
- }).then( res => {\r
- // If response comes back as a redirected HTML page which IS NOT a success\r
- if (Object.keys(res.data).length == 0) {\r
- deferred.reject("AdminsService::getAdminAppsRoles.getRolesByApp Failed");\r
- } else {\r
- this.$log.info('AdminsService::getAdminAppsRoles.getRolesByApp Succeeded');\r
- deferred.resolve(res.data);\r
- }\r
- })\r
- .catch( status => {\r
- deferred.reject(status);\r
- });\r
- \r
- return deferred.promise;\r
- }\r
- \r
- updateAdminAppsRoles(newAdminAppRoles) {\r
- let deferred = this.$q.defer();\r
- // this.$log.info('AdminsService::updateAdminAppsRoles');\r
- this.$http({\r
- method: "PUT",\r
- url: this.conf.api.adminAppsRoles,\r
- data: newAdminAppRoles,\r
- headers: {\r
- 'X-ECOMP-RequestID':this.uuid.generate()\r
- }\r
- }).then( res => {\r
- if (this.utilsService.isValidJSON(res)=== false) {\r
- this.$log.error('AdminsService::updateAdminAppsRoles Failed');\r
- deferred.reject("AdminsService::updateAdminAppsRoles Failed");\r
- } else {\r
- //this.$log.info('AdminsService::updateAdminAppsRoles success:');\r
- deferred.resolve(res.data);\r
- }\r
-\r
- })\r
- .catch( status => {\r
- this.$log.error('AdminsService::updateAdminAppsRoles: rejection:' + status);\r
- deferred.reject(status);\r
- });\r
-\r
- return deferred.promise;\r
- }\r
- \r
- /**\r
- * Tests the specified password against complexity requirements.\r
- * Returns an explanation message if the test fails; null if it passes.\r
- */\r
- isComplexPassword(str) {\r
- let minLength = 8;\r
- let message = 'Password is too simple. Minimum length is '+ minLength + ', '\r
- + 'and it must use letters, digits and special characters.';\r
- if (str == null)\r
- return message;\r
-\r
- let hasLetter = false;\r
- let hasDigit = false;\r
- let hasSpecial = false;\r
- var code, i, len;\r
- for (i = 0, len = str.length; i < len; i++) {\r
- code = str.charCodeAt(i);\r
- if (code > 47 && code < 58) // numeric (0-9)\r
- hasDigit = true;\r
- else if ((code > 64 && code < 91) || (code > 96 && code < 123)) // A-Z, a-z\r
- hasLetter = true;\r
- else\r
- hasSpecial = true;\r
- } // for\r
-\r
- if (str.length < minLength || !hasLetter || !hasDigit || !hasSpecial)\r
- return message;\r
- \r
- // All is well.\r
- return null;\r
- }\r
- \r
- addNewUser(newUser,checkDuplicate) {\r
- // this.$log.info(newContactUs)\r
- let deferred = this.$q.defer();\r
- // this.$log.info('ContactUsService:: add Contact Us' + JSON.stringify(newContactUs));\r
- \r
- var newUserObj={\r
- firstName:newUser.firstName,\r
- middleInitial:newUser.middleName,\r
- lastName:newUser.lastName,\r
- email:newUser.emailAddress,\r
- loginId:newUser.loginId,\r
- loginPwd:newUser.loginPwd, \r
- };\r
- this.$http({\r
- url: this.conf.api.saveNewUser + "?isCheck=" + checkDuplicate,\r
- method: 'POST',\r
- cache: false,\r
- headers: {\r
- 'X-ECOMP-RequestID':this.uuid.generate()\r
- },\r
- data: newUserObj\r
- }).then(res => {\r
- // this.$log.info('ContactUsService:: add Contact Us res' ,res);\r
- // If response comes back as a redirected HTML page which IS NOT a success\r
- if (res==null || Object.keys(res.data).length == 0 || res.data.message == 'failure') {\r
- deferred.reject("Add new User failed");\r
- this.$log.error('adminService:: add New User failed');\r
- } else {\r
- deferred.resolve(res.data);\r
- }\r
- }).catch(errRes => {\r
- deferred.reject(errRes);\r
- });\r
- return deferred.promise;\r
- }\r
- \r
- }\r
- AdminsService.$inject = ['$q', '$log', '$http', 'conf','uuid4', 'utilsService'];\r
- angular.module('ecompApp').service('adminsService', AdminsService)\r
-})();\r
+/*-
+ * ================================================================================
+ * ECOMP Portal
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ================================================================================
+ */
+/**
+ * Created by nnaffar on 11/22/2015.
+ */
+'use strict';
+
+(function () {
+ class AdminsService {
+ constructor($q, $log, $http, conf, uuid, utilsService) {
+ this.$q = $q;
+ this.$log = $log;
+ this.$http = $http;
+ this.conf = conf;
+ this.uuid = uuid;
+ this.utilsService = utilsService;
+ }
+
+ getAccountAdmins() {
+ let deferred = this.$q.defer();
+ //this.$log.info('AdminsService::get all applications admins list');
+ this.$http({
+ method: "GET",
+ cache: false,
+ url: this.conf.api.accountAdmins,
+ headers: {
+ 'X-ECOMP-RequestID':this.uuid.generate()
+ }
+ })
+ .then( res => {
+ // If response comes back as a redirected HTML page which IS NOT a success
+ if (this.utilsService.isValidJSON(res)=== false) {
+ this.$log.error('AdminsService::getAccountAdmins Failed');
+ deferred.reject("AdminsService::getAccountAdmins Failed");
+ } else {
+ // this.$log.info('AdminsService::getAccountAdmins Succeeded');
+ deferred.resolve(res.data);
+ }
+ })
+ .catch( status => {
+ this.$log.error('AdminsService::getAccountAdmins Failed', status);
+ deferred.reject(status);
+ });
+
+ return deferred.promise;
+ }
+
+ getAdminAppsRoles(orgUserId) {
+ let deferred = this.$q.defer();
+ //this.$log.info('AdminsService::getAdminAppsRoles.adminAppsRoles');
+
+ this.$http({
+ method: "GET",
+ url: this.conf.api.adminAppsRoles,
+ params: {user: orgUserId},
+ cache: false,
+ headers: {
+ 'X-ECOMP-RequestID':this.uuid.generate()
+ }
+ }).then( res => {
+ // If response comes back as a redirected HTML page which IS NOT a success
+ if (this.utilsService.isValidJSON(res)=== false) {
+ this.$log.error('AdminsService::getAdminAppsRoles.adminAppsRoles Failed');
+ deferred.reject("AdminsService::getAdminAppsRoles.adminAppsRoles Failed");
+ } else {
+ // this.$log.info('AdminsService::getAdminAppsRoles.adminAppsRoles Succeeded');
+ deferred.resolve(res.data);
+ }
+ })
+ .catch( status => {
+ this.$log.error('AdminsService::getAdminAppsRoles.adminAppsRoles Failed', status);
+ deferred.reject(status);
+ });
+
+ return deferred.promise;
+ }
+ /*Author: Rui*/
+ getRolesByApp(appId) {
+ let deferred = this.$q.defer();
+ this.$log.info('AdminsService::getRolesByApp');
+ let url = this.conf.api.adminAppsRoles + '/' + appId;
+ this.$http({
+ method: "GET",
+ url: url,
+ cache: false,
+ headers: {
+ 'X-ECOMP-RequestID':this.uuid.generate()
+ }
+ }).then( res => {
+ // If response comes back as a redirected HTML page which IS NOT a success
+ if (Object.keys(res.data).length == 0) {
+ deferred.reject("AdminsService::getAdminAppsRoles.getRolesByApp Failed");
+ } else {
+ this.$log.info('AdminsService::getAdminAppsRoles.getRolesByApp Succeeded');
+ deferred.resolve(res.data);
+ }
+ })
+ .catch( status => {
+ deferred.reject(status);
+ });
+
+ return deferred.promise;
+ }
+
+ updateAdminAppsRoles(newAdminAppRoles) {
+ let deferred = this.$q.defer();
+ // this.$log.info('AdminsService::updateAdminAppsRoles');
+ this.$http({
+ method: "PUT",
+ url: this.conf.api.adminAppsRoles,
+ data: newAdminAppRoles,
+ headers: {
+ 'X-ECOMP-RequestID':this.uuid.generate()
+ }
+ }).then( res => {
+ if (this.utilsService.isValidJSON(res)=== false) {
+ this.$log.error('AdminsService::updateAdminAppsRoles Failed');
+ deferred.reject("AdminsService::updateAdminAppsRoles Failed");
+ } else {
+ //this.$log.info('AdminsService::updateAdminAppsRoles success:');
+ deferred.resolve(res.data);
+ }
+
+ })
+ .catch( status => {
+ this.$log.error('AdminsService::updateAdminAppsRoles: rejection:' + status);
+ deferred.reject(status);
+ });
+
+ return deferred.promise;
+ }
+
+ /**
+ * Tests the specified password against complexity requirements.
+ * Returns an explanation message if the test fails; null if it passes.
+ */
+ isComplexPassword(str) {
+ let minLength = 8;
+ let message = 'Password is too simple. Minimum length is '+ minLength + ', '
+ + 'and it must use letters, digits and special characters.';
+ if (str == null)
+ return message;
+
+ let hasLetter = false;
+ let hasDigit = false;
+ let hasSpecial = false;
+ var code, i, len;
+ for (i = 0, len = str.length; i < len; i++) {
+ code = str.charCodeAt(i);
+ if (code > 47 && code < 58) // numeric (0-9)
+ hasDigit = true;
+ else if ((code > 64 && code < 91) || (code > 96 && code < 123)) // A-Z, a-z
+ hasLetter = true;
+ else
+ hasSpecial = true;
+ } // for
+
+ if (str.length < minLength || !hasLetter || !hasDigit || !hasSpecial)
+ return message;
+
+ // All is well.
+ return null;
+ }
+
+ addNewUser(newUser,checkDuplicate) {
+ // this.$log.info(newContactUs)
+ let deferred = this.$q.defer();
+ // this.$log.info('ContactUsService:: add Contact Us' + JSON.stringify(newContactUs));
+
+ var newUserObj={
+ firstName:newUser.firstName,
+ middleInitial:newUser.middleName,
+ lastName:newUser.lastName,
+ email:newUser.emailAddress,
+ loginId:newUser.loginId,
+ loginPwd:newUser.loginPwd,
+ };
+ this.$http({
+ url: this.conf.api.saveNewUser + "?isCheck=" + checkDuplicate,
+ method: 'POST',
+ cache: false,
+ headers: {
+ 'X-ECOMP-RequestID':this.uuid.generate()
+ },
+ data: newUserObj
+ }).then(res => {
+ // this.$log.info('ContactUsService:: add Contact Us res' ,res);
+ // If response comes back as a redirected HTML page which IS NOT a success
+ if (res==null || Object.keys(res.data).length == 0 || res.data.message == 'failure') {
+ deferred.reject("Add new User failed");
+ this.$log.error('adminService:: add New User failed');
+ } else {
+ deferred.resolve(res.data);
+ }
+ }).catch(errRes => {
+ deferred.reject(errRes);
+ });
+ return deferred.promise;
+ }
+
+ }
+ AdminsService.$inject = ['$q', '$log', '$http', 'conf','uuid4', 'utilsService'];
+ angular.module('ecompApp').service('adminsService', AdminsService)
+})();