nexus site path corrected
[portal.git] / ecomp-portal-FE / client / app / views / header / user-edit / edit-user.controller.js
1 /*-
2  * ================================================================================
3  * eCOMP Portal
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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  * ================================================================================
19  */
20 'use strict';
21
22 (function () {
23     class EditUserController {
24         constructor($scope,$log, message, $q, $http, conf,contactUsService,confirmBoxService,userProfileService,adminsService) {
25                 
26                 $scope.newUser ={
27                                 firstName:'',
28                                 lastName:'',
29                                 emailAddress:'',
30                                 middleName:'',
31                                 loginId:'',
32                                 loginPwd:'',
33                 };
34                 
35                 $scope.userId = $scope.ngDialogData.loginId;
36                 $scope.updateRemoteApp = $scope.ngDialogData.updateRemoteApp;
37                 try {
38                 userProfileService.getCurrentUserProfile($scope.userId)
39                 .then(res=> {
40                    $scope.newUser.firstName = res.firstName;
41                    $scope.newUser.lastName = res.lastName;
42                    $scope.newUser.emailAddress = res.email;
43                    $scope.newUser.middleName = res.middleInitial;
44                    $scope.newUser.loginId = res.loginId;
45                    $scope.newUser.loginPwd = res.loginPwd;
46                    $scope.newUser.loginPwdCheck = res.loginPwd;
47                    
48                 }).catch(err=> {
49                   $log.error('HeaderCtrl::LoginSnippetCtrl:get Current User Profile error: ' + err);
50                 });
51             } catch (err) {
52                 $log.error('HeaderCtrl::LoginSnippetCtrl:getFunctionalMenuStaticInfo failed: ' + err);
53             }           
54                 
55             $scope.changePwdText = function(){
56                 $scope.newUser.loginPwdCheck = '';
57             }
58                 
59                 $scope.closeDialog = function(){
60                         $scope.closeThisDialog( $scope.widgetData);
61                 }
62                 
63                 $scope.updateUserFun = function(){
64                 
65                    if ($scope.newUser.firstName==''||$scope.newUser.lastName==''||$scope.newUser.loginPwd=='') {
66                                         var warningMsg = "Please enter missing values";
67                                         confirmBoxService.showInformation(warningMsg).then(isConfirmed => {return;});
68                                         return;
69                            } else if ($scope.newUser.loginPwd != $scope.newUser.loginPwdCheck) {
70                            var warningMsg = "Passwords do not match, please try again.";
71                            confirmBoxService.showInformation(warningMsg).then(isConfirmed => {return;});
72                            return;
73                    } else {
74                            
75                            // check password length complexity.
76                            var warningMsg = adminsService.isComplexPassword($scope.newUser.loginPwd);
77                            if (warningMsg != null) {
78                                    confirmBoxService.showInformation(warningMsg).then(isConfirmed => {return;});
79                                    return;
80                            }
81                         
82                         adminsService.addNewUser($scope.newUser,'No').then(res=> {
83                                
84                                        $scope.closeThisDialog();
85                                         
86                                    confirmBoxService.showInformation('Update User Info successfully');
87                                                    userProfileService.broadCastUpdatedUserInfo();
88
89                                    
90                                    if($scope.updateRemoteApp){
91                                                   //need update remote app's database
92                                                   var remoteAppId = $scope.ngDialogData.appId;
93                                                   if(remoteAppId!=null){
94                                                                                           
95                                                            userProfileService.updateRemoteUserProfile($scope.userId,remoteAppId).then(res=> {
96                                                                                                 
97                                                          
98                                                                }).catch(err=> {
99                                                                    $log.error('userProfileService: update user profile in remote app  error:: ', err);
100                                                                    confirmBoxService.showInformation('Update User in remote app failed: ' + err);
101                                                                   
102                                                                }).finally(() => {
103                                                                    
104                                                                });
105                                                   
106                                                   
107                                                   }
108                                            
109                                        }
110                          
111                                }).catch(err=> {
112                                    $log.error('adminsService: addNewUser error:: ', err);
113                                   // $scope.errMsg=err;
114                                    confirmBoxService.showInformation('Add New User failed: ' + err);
115                                   
116                                }).finally(() => {
117                                    //this.isLoadingTable = false;
118                                    
119                                });
120                         
121                 }
122          }
123                 
124                 
125         }        
126     }
127     EditUserController.$inject = ['$scope','$log',  'message', '$q', '$http', 'conf','contactUsService','confirmBoxService','userProfileService','adminsService'];
128     angular.module('ecompApp').controller('editUserController', EditUserController);
129
130  
131 })();
132 function validateUrl(value){
133     return /^(https?|ftp):\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?)(:\d*)?)(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)?(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(\#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/i.test(value);
134   }