You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kylin.apache.org by ni...@apache.org on 2019/12/18 10:46:47 UTC

[kylin] branch master updated: KYLIN-4212 add user profile page allowing to change password (#915)

This is an automated email from the ASF dual-hosted git repository.

nic pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/kylin.git


The following commit(s) were added to refs/heads/master by this push:
     new 27df350  KYLIN-4212 add user profile page allowing to change password (#915)
27df350 is described below

commit 27df350527f8810dec685f2b91e3080cb2ac3295
Author: Congling Xia <xi...@xiaomi.com>
AuthorDate: Wed Dec 18 18:46:38 2019 +0800

    KYLIN-4212 add user profile page allowing to change password (#915)
    
    * KYLIN-4212 add user profile page allowing to change password
    
    * set controller in template rather than in routes.json
    
    * KYLIN-4212 Code reivew
---
 webapp/app/index.html                     |  1 +
 webapp/app/js/controllers/userProfile.js  | 72 +++++++++++++++++++++++++++++++
 webapp/app/partials/admin/change_pwd.html | 10 +++++
 webapp/app/partials/header.html           |  1 +
 webapp/app/partials/user/profile.html     | 49 +++++++++++++++++++++
 webapp/app/routes.json                    |  8 ++++
 6 files changed, 141 insertions(+)

diff --git a/webapp/app/index.html b/webapp/app/index.html
index 193f903..4b020e0 100644
--- a/webapp/app/index.html
+++ b/webapp/app/index.html
@@ -227,6 +227,7 @@
 <script src="js/controllers/adminStreaming.js"></script>
 <script src="js/controllers/instances.js"></script>
 <script src="js/controllers/userGroup.js"></script>
+<script src="js/controllers/userProfile.js"></script>
 <!-- endref -->
 
 <!-- ref:remove -->
diff --git a/webapp/app/js/controllers/userProfile.js b/webapp/app/js/controllers/userProfile.js
new file mode 100644
index 0000000..fb0522d
--- /dev/null
+++ b/webapp/app/js/controllers/userProfile.js
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+*/
+
+'use strict';
+
+KylinApp.controller('UserProfileCtrl', function ($scope, $modal, AuthenticationService, UserService, ResponseUtil, kylinConfig) {
+  $scope.currentUser = {};
+
+  // for password changing
+  var changePwdCtrl = function ($scope, $modalInstance, SweetAlert) {
+    $scope.userPattern = /^[\w.@]+$/;
+    $scope.pwdPattern = /^(?=.*\d)(?=.*[a-z])(?=.*[~!@#$%^&*(){}|:"<>?[\];',./`]).{8,}$/;
+    $scope.dialogActionLoading = false;
+    $scope.saveNewPassword = function () {
+      $scope.dialogActionLoading = true;
+      UserService.changePwd($scope.changePwdUser, function () {
+        $modalInstance.dismiss('cancel');
+        SweetAlert.swal('Change password successfully', null, 'success');
+        $scope.dialogActionLoading = false;
+        $scope.logout();
+      }, function (e) {
+        $scope.dialogActionLoading = false;
+        ResponseUtil.handleError(e);
+      });
+    };
+    $scope.cancel = function () {
+      $modalInstance.dismiss('cancel');
+    }
+  };
+  var initChangePwdUserWithCurrent = function () {
+    return {
+      username: $scope.currentUser.username,
+      password: '',
+      repeatPassword: '',
+      newPassword: ''
+    }
+  };
+  $scope.changePwd = function () {
+    $scope.changePwdUser = initChangePwdUserWithCurrent();
+    $scope.currentPwdNeeded = true;
+    $modal.open({
+      templateUrl: 'changePwd.html',
+      controller: changePwdCtrl,
+      scope: $scope
+    });
+  };
+
+  AuthenticationService.ping(function (data) {
+    $scope.currentUser = data.userDetails;
+  });
+
+  kylinConfig.init().$promise.then(function() {
+    $scope.securityType = kylinConfig.getSecurityType();
+    $scope.allowUseUserAndGroupModule = ['testing', 'custom'].indexOf($scope.securityType) >= 0;
+  })
+});
+
diff --git a/webapp/app/partials/admin/change_pwd.html b/webapp/app/partials/admin/change_pwd.html
index c3ab320..07a5ac0 100644
--- a/webapp/app/partials/admin/change_pwd.html
+++ b/webapp/app/partials/admin/change_pwd.html
@@ -38,6 +38,16 @@
                     >&nbsp;The user name is invalid</span>
         </div>
       </div>
+      <div class="form-group" ng-if="currentPwdNeeded">
+        <label><b>User Current Password</b></label>
+        <div class="clearfix">
+          <input required name="curr_pwd_input" type="password" class="form-control" ng-model="changePwdUser.password"
+                 placeholder="Your current password"/>
+          <span class="text-warning"
+                ng-if="change_pwd_form.curr_pwd_input.$error.required && change_pwd_form.curr_pwd_input.$dirty"
+          >&nbsp;The password is required</span>
+        </div>
+      </div>
       <div class="form-group">
         <label><b>User New Password</b></label>
         <div class="clearfix">
diff --git a/webapp/app/partials/header.html b/webapp/app/partials/header.html
index 72b7b50..5cc7806 100644
--- a/webapp/app/partials/header.html
+++ b/webapp/app/partials/header.html
@@ -76,6 +76,7 @@
             </a>
             <ul class="user-menu dropdown-menu-right dropdown-menu dropdown-yellow dropdown-caret dropdown-close"
                 role="menu">
+              <li><a href="user/profile"><i class="ace-icon fa fa-user"></i> Profile</a></li>
               <li><a ng-click="logout()"><i class="ace-icon fa fa-power-off"></i> Logout</a></li>
             </ul>
           </li>
diff --git a/webapp/app/partials/user/profile.html b/webapp/app/partials/user/profile.html
new file mode 100644
index 0000000..5ee723c
--- /dev/null
+++ b/webapp/app/partials/user/profile.html
@@ -0,0 +1,49 @@
+<!--
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements.  See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership.  The ASF licenses this file
+* to you 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.
+-->
+<div class="container" style="margin-top:50px;" ng-controller="UserProfileCtrl">
+  <div class="row">
+    <h3>Basic Information</h3>
+    <form class="form-horizontal">
+      <div class="form-group">
+        <label class="col-sm-2 control-label">Username</label>
+        <div class="col-sm-10">
+          <p class="form-control-static">{{currentUser.username}}</p>
+        </div>
+      </div>
+      <div class="form-group">
+        <label class="col-sm-2 control-label">Groups</label>
+        <div class="col-sm-10" style="margin-top: 5px;">
+            <span class="label label-primary" style="margin-right:5px;"
+                  ng-repeat="auth in currentUser.authorities">{{auth.authority}}</span>
+        </div>
+      </div>
+    </form>
+  </div>
+  <div class="row" ng-if="allowUseUserAndGroupModule">
+    <h3>Security</h3>
+    <form class="form-horizontal">
+      <div class="form-group">
+        <label class="col-sm-2 control-label">Password</label>
+        <div class="col-sm-10">
+          <button ng-click="changePwd()">Change Password</button>
+        </div>
+      </div>
+    </form>
+  </div>
+</div>
+<div ng-include="'partials/admin/change_pwd.html'"></div>
diff --git a/webapp/app/routes.json b/webapp/app/routes.json
index 32b60ea..7558f6c 100644
--- a/webapp/app/routes.json
+++ b/webapp/app/routes.json
@@ -141,5 +141,13 @@
       "tab": "admin",
       "controller": "StreamingReceiverCtrl"
     }
+  },
+  {
+    "url": "/user/profile",
+    "params": {
+      "templateUrl": "partials/user/profile.html",
+      "tab": "user",
+      "controller": "UserProfileCtrl"
+    }
   }
 ]