浏览代码

Merge branch 'thuanpq-allow-changing-user-password-in-admin-panel' into devel

Change password of any user in Standalone Wekan Admin Panel. Thanks to thuanpq !
Lauri Ojansivu 7 年之前
父节点
当前提交
fcf7c02c69
共有 4 个文件被更改,包括 27 次插入9 次删除
  1. 8 0
      CHANGELOG.md
  2. 4 3
      client/components/settings/peopleBody.jade
  3. 8 6
      client/components/settings/peopleBody.js
  4. 7 0
      models/users.js

+ 8 - 0
CHANGELOG.md

@@ -1,3 +1,11 @@
+# Upcoming Wekan release
+
+This release adds the following new features:
+
+* [Change password of any user in Standalone Wekan Admin Panel](https://github.com/wekan/wekan/pull/1372).
+
+Thanks to GitHub user thuanpq for contributions.
+
 # v0.60 2017-11-29 Wekan release
 
 This release adds the following new features:

+ 4 - 3
client/components/settings/peopleBody.jade

@@ -67,9 +67,6 @@ template(name="editUserPopup")
       span.error.hide.username-taken
         | {{_ 'error-username-taken'}}
       input.js-profile-username(type="text" value=user.username)
-    label
-      | {{_ 'initials'}}
-      input.js-profile-initials(type="text" value=user.profile.initials)
     label
       | {{_ 'email'}}
       span.error.hide.email-taken
@@ -85,5 +82,9 @@ template(name="editUserPopup")
       select.select-active.js-profile-isactive
         option(value="false") {{_ 'yes'}}
         option(value="true" selected="{{user.loginDisabled}}") {{_ 'no'}}
+    hr
+    label
+      | {{_ 'password'}}
+      input.js-profile-password(type="password")
 
     input.primary.wide(type="submit" value="{{_ 'save'}}")

+ 8 - 6
client/components/settings/peopleBody.js

@@ -87,24 +87,26 @@ Template.editUserPopup.events({
     const user = Users.findOne(this.userId);
     const fullname = tpl.find('.js-profile-fullname').value.trim();
     const username = tpl.find('.js-profile-username').value.trim();
-    const initials = tpl.find('.js-profile-initials').value.trim();
+    const password = tpl.find('.js-profile-password').value;
     const isAdmin = tpl.find('.js-profile-isadmin').value.trim();
     const isActive = tpl.find('.js-profile-isactive').value.trim();
     const email = tpl.find('.js-profile-email').value.trim();
-    let isChangeUserName = false;
-    let isChangeEmail = false;
+
+    const isChangePassword = password.length > 0;
+    const isChangeUserName = username !== user.username;
+    const isChangeEmail = email.toLowerCase() !== user.emails[0].address.toLowerCase();
 
     Users.update(this.userId, {
       $set: {
         'profile.fullname': fullname,
-        'profile.initials': initials,
         'isAdmin': isAdmin === 'true',
         'loginDisabled': isActive === 'true',
       },
     });
 
-    isChangeUserName = username !== user.username;
-    isChangeEmail = email.toLowerCase() !== user.emails[0].address.toLowerCase();
+    if(isChangePassword){
+      Meteor.call('setPassword', password, this.userId);
+    }
 
     if (isChangeUserName && isChangeEmail) {
       Meteor.call('setUsernameAndEmail', username, email.toLowerCase(), this.userId, function (error) {

+ 7 - 0
models/users.js

@@ -372,6 +372,13 @@ Meteor.methods({
     Meteor.call('setUsername', username, userId);
     Meteor.call('setEmail', email, userId);
   },
+  setPassword(newPassword, userId) {
+    check(userId, String);
+    check(newPassword, String);
+    if(Meteor.user().isAdmin){
+      Accounts.setPassword(userId, newPassword);
+    }
+  },
 });
 
 if (Meteor.isServer) {