From 6a10257fd7230d08d9a64fc4877e85972375498d Mon Sep 17 00:00:00 2001 From: nztqa Date: Mon, 7 Aug 2017 17:40:50 +0900 Subject: Add change email address Set allow email change in admin panel --- models/accountSettings.js | 33 +++++++++++++++++++++++++++++++++ models/users.js | 22 ++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 models/accountSettings.js (limited to 'models') diff --git a/models/accountSettings.js b/models/accountSettings.js new file mode 100644 index 00000000..db4087c0 --- /dev/null +++ b/models/accountSettings.js @@ -0,0 +1,33 @@ +AccountSettings = new Mongo.Collection('accountSettings'); + +AccountSettings.attachSchema(new SimpleSchema({ + _id: { + type: String, + }, + booleanValue: { + type: Boolean, + optional: true, + }, + sort: { + type: Number, + decimal: true, + }, +})); + +AccountSettings.allow({ + update(userId) { + const user = Users.findOne(userId); + return user && user.isAdmin; + }, +}); + +if (Meteor.isServer) { + Meteor.startup(() => { + AccountSettings.upsert({ _id: 'accounts-allowEmailChange' }, { + $setOnInsert: { + booleanValue: false, + sort: 0, + }, + }); + }); +} diff --git a/models/users.js b/models/users.js index 29504aa8..c2238cde 100644 --- a/models/users.js +++ b/models/users.js @@ -334,6 +334,28 @@ Meteor.methods({ check(limit, Number); Meteor.user().setShowCardsCountAt(limit); }, + setEmail(email) { + check(email, String); + const existingUser = Users.findOne({ 'emails.address': email }, { fields: { _id: 1 } }); + if (existingUser) { + throw new Meteor.Error('email-already-taken'); + } else { + Users.update(this.userId, { + $set: { + emails: [{ + address: email, + verified: false, + }], + }, + }); + } + }, + setUsernameAndEmail(username, email) { + check(username, String); + check(email, String); + Meteor.call('setUsername', username); + Meteor.call('setEmail', email); + }, }); if (Meteor.isServer) { -- cgit v1.2.3-1-g7c22