wiwa1978
wiwa1978

Reputation: 2707

Meteor Users: add user by admin user only

I'm using the useraccounts package in my Meteor app. I want an admin to be able to add a new user (and disable signing up through the frontend). Therefore, I have added a Collection with a SimpleSchema as per the suggestion of meteor-collection2. I'm alos using AutoForm to create an 'Add user' page.

<template name="addCustomerProfile">
  <div class="container">
    <h1>Edit document</h1>
    {{#if isReady 'updateCustomerProfile'}}
       {{#autoForm collection="Users" id="userForm" type="insert" }}
        <fieldset>
          {{> afQuickField name='emails.0.address'}}
          {{> afQuickField name='emails.0.verified'}}
          {{> afQuickField name='services.password'}}
          {{> afQuickField name='username'}}
          {{> afQuickField name='profile.firstName'}}
        </fieldset>
        <button type="submit" class="btn btn-primary">Add User</button>
      {{/autoForm}}
    {{else}}
      Nothing
    {{/if}}
   </div>
</template>

I can add users whenever the 'services.password' is not added to the form, but obviously no default password is set for the user in the Mongo database in that case. How can I add a field so the admin can set a default password for that user (which the user will then be able to change later on).

Upvotes: 0

Views: 207

Answers (1)

corvid
corvid

Reputation: 11207

Why not just forbidClientAccountCreation and sendEnrollmentEmail?

Accounts.config({
  forbidClientAccountCreation: true
});

Meteor.methods({
  'inviteUser': function (doc) {
    check(doc, YourForm);
    let userId = Accounts.createUser(doc);
    Accounts.sendEnrollmentEmail(userId);
  }
});

Upvotes: 0

Related Questions