[UI] Handling users and passwords
[validation.git] / ui / src / main / webapp / app / BluvalUI / UpdatePassword / UpdatePasswordController.js
1 /*
2  * Copyright (c) 2019 AT&T Intellectual Property. All rights reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 var app = angular.module('UpdatePassword');
18 app
19         .controller(
20                 'UpdatePasswordController',
21                 function($scope, restAPISvc) {
22
23                     initialize();
24
25                     function initialize() {
26                         $scope.definedLoginId = '';
27                         $scope.definedOldLoginPwd = '';
28                         $scope.definedNewLoginPwd = '';
29                     }
30
31                     $scope.register = function() {
32                         if (!$scope.definedLoginId
33                                 || !$scope.definedOldLoginPwd
34                                 || !$scope.definedNewLoginPwd) {
35                             confirm("You must specify all data fields");
36                             return;
37                         }
38                         var userInfo = {
39                             "loginId" : $scope.definedLoginId,
40                             "loginPwd" : $scope.definedOldLoginPwd
41                         };
42                         var userData = {
43                             "user" : userInfo,
44                             "newPwd" : $scope.definedNewLoginPwd
45                         };
46
47                         restAPISvc
48                                 .postRestAPI(
49                                         "/api/v1/user/updatepassword",
50                                         userData,
51                                         function(data) {
52                                             if (data) {
53                                                 var confirmText = "The password has been updated successfully.";
54                                                 confirm(confirmText);
55                                             } else {
56                                                 confirm("Error when updating the password");
57                                             }
58                                             initialize();
59                                         });
60                     }
61                 });