diff --git a/apps/meteor/app/authentication/server/startup/index.js b/apps/meteor/app/authentication/server/startup/index.js index 7debe1dfa4479..445044c8680ea 100644 --- a/apps/meteor/app/authentication/server/startup/index.js +++ b/apps/meteor/app/authentication/server/startup/index.js @@ -128,7 +128,7 @@ Accounts.emailTemplates.enrollAccount.html = function (user = {} /* , url*/) { Accounts.insertUserDoc = function (...args) { // Depends on meteor support for Async - return Promise.await(User.create(...args)); + return Promise.await(User.insertUserDoc(...args)); }; const validateLoginAttemptAsync = async function (login) { diff --git a/apps/meteor/app/cas/server/cas_server.js b/apps/meteor/app/cas/server/cas_server.js index a18736aeedfb1..6560ce745e47e 100644 --- a/apps/meteor/app/cas/server/cas_server.js +++ b/apps/meteor/app/cas/server/cas_server.js @@ -243,7 +243,7 @@ Accounts.registerLoginHandler('cas', async function (options) { // Create the user logger.debug(`User "${result.username}" does not exist yet, creating it`); - const userId = await User.create({ globalRoles: ['user'] }, newUser); + const userId = await User.insertUserDoc({ globalRoles: ['user'] }, newUser); // Fetch and use it user = await Users.findOneById(userId); diff --git a/apps/meteor/app/crowd/server/crowd.ts b/apps/meteor/app/crowd/server/crowd.ts index 899e0cfa450be..1332c3b3880c2 100644 --- a/apps/meteor/app/crowd/server/crowd.ts +++ b/apps/meteor/app/crowd/server/crowd.ts @@ -298,7 +298,7 @@ export class CROWD { // Attempt to create the new user try { - crowdUser._id = await User.createWithPassword(crowdUser); + crowdUser._id = await User.create(crowdUser); // sync the user data await this.syncDataToUser(crowdUser, crowdUser._id); diff --git a/apps/meteor/app/importer/server/classes/ImportDataConverter.ts b/apps/meteor/app/importer/server/classes/ImportDataConverter.ts index d9a85e319f002..339ddfb672b3b 100644 --- a/apps/meteor/app/importer/server/classes/ImportDataConverter.ts +++ b/apps/meteor/app/importer/server/classes/ImportDataConverter.ts @@ -290,11 +290,11 @@ export class ImportDataConverter { async insertUser(userData: IImportUser): Promise { const password = `${Date.now()}${userData.name || ''}${userData.emails.length ? userData.emails[0].toUpperCase() : ''}`; const userId = userData.emails.length - ? await User.createWithPassword({ + ? await User.create({ email: userData.emails[0], password, }) - : await User.createWithPassword({ + : await User.create({ username: userData.username, password, joinDefaultChannelsSilenced: true, diff --git a/apps/meteor/app/lib/server/functions/saveUser.js b/apps/meteor/app/lib/server/functions/saveUser.js index 194569e1df376..2338029a646e5 100644 --- a/apps/meteor/app/lib/server/functions/saveUser.js +++ b/apps/meteor/app/lib/server/functions/saveUser.js @@ -285,7 +285,7 @@ const saveNewUser = async function (userData, sendPassword) { createUser.email = userData.email; } - const _id = await User.createWithPassword(createUser); + const _id = await User.create(createUser); const updateUser = { $set: { diff --git a/apps/meteor/app/meteor-accounts-saml/server/lib/SAML.ts b/apps/meteor/app/meteor-accounts-saml/server/lib/SAML.ts index d7fa043cf06dd..6a17181cc17bf 100644 --- a/apps/meteor/app/meteor-accounts-saml/server/lib/SAML.ts +++ b/apps/meteor/app/meteor-accounts-saml/server/lib/SAML.ts @@ -162,7 +162,7 @@ export class SAML { } } - const userId = await User.create({ globalRoles: roles }, newUser); + const userId = await User.insertUserDoc({ globalRoles: roles }, newUser); user = await Users.findOneById(userId); if (user && userObject.channels && channelsAttributeUpdate !== true) { diff --git a/apps/meteor/app/slackbridge/server/RocketAdapter.js b/apps/meteor/app/slackbridge/server/RocketAdapter.js index 22d171608d33d..2edc50b8f563b 100644 --- a/apps/meteor/app/slackbridge/server/RocketAdapter.js +++ b/apps/meteor/app/slackbridge/server/RocketAdapter.js @@ -384,7 +384,7 @@ export default class RocketAdapter { newUser.joinDefaultChannels = false; } - rocketUserData.rocketId = await User.createWithPassword(newUser); + rocketUserData.rocketId = await User.create(newUser); const userUpdate = { utcOffset: rocketUserData.tz_offset / 3600, // Slack's is -18000 which translates to Rocket.Chat's after dividing by 3600, roles: isBot ? ['bot'] : ['user'], diff --git a/apps/meteor/server/methods/registerUser.ts b/apps/meteor/server/methods/registerUser.ts index 421249bf8741e..73123b63437fb 100644 --- a/apps/meteor/server/methods/registerUser.ts +++ b/apps/meteor/server/methods/registerUser.ts @@ -34,7 +34,7 @@ Meteor.methods({ const AllowAnonymousWrite = settings.get('Accounts_AllowAnonymousWrite'); const manuallyApproveNewUsers = settings.get('Accounts_ManuallyApproveNewUsers'); if (AllowAnonymousRead === true && AllowAnonymousWrite === true && !formData.email) { - const userId = await User.create( + const userId = await User.insertUserDoc( { globalRoles: ['anonymous'], }, @@ -104,7 +104,7 @@ Meteor.methods({ await Accounts.setPasswordAsync(importedUser._id, userData.password); userId = importedUser._id; } else { - userId = await User.createWithPassword(userData); + userId = await User.create(userData); } } catch (e) { if (e instanceof Meteor.Error) { diff --git a/apps/meteor/server/services/user/service.ts b/apps/meteor/server/services/user/service.ts index 5941acd6f1212..ac37d8880e234 100644 --- a/apps/meteor/server/services/user/service.ts +++ b/apps/meteor/server/services/user/service.ts @@ -274,7 +274,6 @@ export class UserService extends ServiceClassInternal implements IUserService { } private async validateNewUser(user: InsertionModel): Promise { - // validateNewUser await this.validateRegistrationDisabled(user); await this.validateDomainAllowList(user); } @@ -321,8 +320,6 @@ export class UserService extends ServiceClassInternal implements IUserService { throw new Meteor.Error(400, 'Need to set a username or email'); } - // #TODO: Check if username and email are not already in use. - const user = { ...(username ? { username } : {}), ...(email ? { emails: [{ address: email, verified: false }] } : {}), diff --git a/packages/core-services/src/types/IUserService.ts b/packages/core-services/src/types/IUserService.ts index 54a68f7b9d8fb..cc850aa387bde 100644 --- a/packages/core-services/src/types/IUserService.ts +++ b/packages/core-services/src/types/IUserService.ts @@ -30,6 +30,6 @@ export type CreateUserOptions = UserDocOptions & ({ username: string } | { email export interface IUserService { hashPassword(password: string | { algorithm: string; digest: string }): Promise; - create(options: UserDocOptions, doc: Partial>): Promise; - createWithPassword(options: CreateUserOptions): Promise; + insertUserDoc(options: UserDocOptions, doc: Partial>): Promise; + create(options: CreateUserOptions): Promise; }