소스 검색

Updated users methods to get user id from client on updating user data, is aimed to support admin update other user profile

Thuan Pham Quoc 7 년 전
부모
커밋
e3b7f85cc3
2개의 변경된 파일13개의 추가작업 그리고 12개의 파일을 삭제
  1. 5 5
      client/components/users/userHeader.js
  2. 8 7
      models/users.js

+ 5 - 5
client/components/users/userHeader.js

@@ -42,7 +42,7 @@ Template.editProfilePopup.events({
     isChangeUserName = username !== Meteor.user().username;
     isChangeUserName = username !== Meteor.user().username;
     isChangeEmail = email.toLowerCase() !== Meteor.user().emails[0].address.toLowerCase();
     isChangeEmail = email.toLowerCase() !== Meteor.user().emails[0].address.toLowerCase();
     if (isChangeUserName && isChangeEmail) {
     if (isChangeUserName && isChangeEmail) {
-      Meteor.call('setUsernameAndEmail', username, email.toLowerCase(), function(error) {
+      Meteor.call('setUsernameAndEmail', username, email.toLowerCase(), Meteor.userId(), function (error) {
         const usernameMessageElement = tpl.$('.username-taken');
         const usernameMessageElement = tpl.$('.username-taken');
         const emailMessageElement = tpl.$('.email-taken');
         const emailMessageElement = tpl.$('.email-taken');
         if (error) {
         if (error) {
@@ -61,7 +61,7 @@ Template.editProfilePopup.events({
         }
         }
       });
       });
     } else if (isChangeUserName) {
     } else if (isChangeUserName) {
-      Meteor.call('setUsername', username, function(error) {
+      Meteor.call('setUsername', username, Meteor.userId(), function (error) {
         const messageElement = tpl.$('.username-taken');
         const messageElement = tpl.$('.username-taken');
         if (error) {
         if (error) {
           messageElement.show();
           messageElement.show();
@@ -71,7 +71,7 @@ Template.editProfilePopup.events({
         }
         }
       });
       });
     } else if (isChangeEmail) {
     } else if (isChangeEmail) {
-      Meteor.call('setEmail', email.toLowerCase(), function(error) {
+      Meteor.call('setEmail', email.toLowerCase(), Meteor.userId(), function (error) {
         const messageElement = tpl.$('.email-taken');
         const messageElement = tpl.$('.email-taken');
         if (error) {
         if (error) {
           messageElement.show();
           messageElement.show();
@@ -105,7 +105,7 @@ Template.editNotificationPopup.events({
 
 
 // XXX For some reason the useraccounts autofocus isnt working in this case.
 // XXX For some reason the useraccounts autofocus isnt working in this case.
 // See https://github.com/meteor-useraccounts/core/issues/384
 // See https://github.com/meteor-useraccounts/core/issues/384
-Template.changePasswordPopup.onRendered(function() {
+Template.changePasswordPopup.onRendered(function () {
   this.find('#at-field-current_password').focus();
   this.find('#at-field-current_password').focus();
 });
 });
 
 
@@ -116,7 +116,7 @@ Template.changeLanguagePopup.helpers({
         tag: code,
         tag: code,
         name: lang.name === 'br' ? 'Brezhoneg' : lang.name,
         name: lang.name === 'br' ? 'Brezhoneg' : lang.name,
       };
       };
-    }).sort(function(a, b) {
+    }).sort(function (a, b) {
       if (a.name === b.name) {
       if (a.name === b.name) {
         return 0;
         return 0;
       } else {
       } else {

+ 8 - 7
models/users.js

@@ -325,13 +325,13 @@ Users.mutations({
 });
 });
 
 
 Meteor.methods({
 Meteor.methods({
-  setUsername(username) {
+  setUsername(username, userId) {
     check(username, String);
     check(username, String);
     const nUsersWithUsername = Users.find({ username }).count();
     const nUsersWithUsername = Users.find({ username }).count();
     if (nUsersWithUsername > 0) {
     if (nUsersWithUsername > 0) {
       throw new Meteor.Error('username-already-taken');
       throw new Meteor.Error('username-already-taken');
     } else {
     } else {
-      Users.update(this.userId, { $set: { username } });
+      Users.update(userId, {$set: {username}});
     }
     }
   },
   },
   toggleSystemMessages() {
   toggleSystemMessages() {
@@ -342,13 +342,13 @@ Meteor.methods({
     check(limit, Number);
     check(limit, Number);
     Meteor.user().setShowCardsCountAt(limit);
     Meteor.user().setShowCardsCountAt(limit);
   },
   },
-  setEmail(email) {
+  setEmail(email, userId) {
     check(email, String);
     check(email, String);
     const existingUser = Users.findOne({ 'emails.address': email }, { fields: { _id: 1 } });
     const existingUser = Users.findOne({ 'emails.address': email }, { fields: { _id: 1 } });
     if (existingUser) {
     if (existingUser) {
       throw new Meteor.Error('email-already-taken');
       throw new Meteor.Error('email-already-taken');
     } else {
     } else {
-      Users.update(this.userId, {
+      Users.update(userId, {
         $set: {
         $set: {
           emails: [{
           emails: [{
             address: email,
             address: email,
@@ -358,11 +358,12 @@ Meteor.methods({
       });
       });
     }
     }
   },
   },
-  setUsernameAndEmail(username, email) {
+  setUsernameAndEmail(username, email, userId) {
     check(username, String);
     check(username, String);
     check(email, String);
     check(email, String);
-    Meteor.call('setUsername', username);
-    Meteor.call('setEmail', email);
+    check(userId, String);
+    Meteor.call('setUsername', username, userId);
+    Meteor.call('setEmail', email, userId);
   },
   },
 });
 });