最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - MeteorJS how to add users from command prompt - Stack Overflow

programmeradmin1浏览0评论

How can I add users to my app outside of the deployed app itself? I don't want to allow users the ability to create accounts inside the app. Can I create some usernames and passwords from the mand line and then give those to a few users to test the application?

Let me know if you need more information or if I am being unclear. Thank you very much for your time.

How can I add users to my app outside of the deployed app itself? I don't want to allow users the ability to create accounts inside the app. Can I create some usernames and passwords from the mand line and then give those to a few users to test the application?

Let me know if you need more information or if I am being unclear. Thank you very much for your time.

Share Improve this question asked May 28, 2015 at 20:31 user95227user95227 1,9633 gold badges22 silver badges39 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 8

Granted that you have theaccounts-password package installed. (You probably do since you already have login set up.)

You can launch meteor shell and enter

Accounts.createUser({username: 'john', password: '12345'})

This will take care of all the bcrypting for you. You should also be able to script this.

The relevant documentation with more option parameters is here.

You can add users from the mand prompt but its not that easy.

Essentially you need to run something like this from mongo. For the sake of simplicity I'm not going to add in bcrypt code to make passwords.

Instead you can use a generic meteor password (default). For this create a meteor app, add in accounts-password and create a user account. Use the services.password.bcrypt value for all users). When you create a user account this bcrypt has represents the created user's password.

Then you can create a default script:

var user = {
  "createdAt": new Date(),
  "emails": [ ],
  "username": "<username>",
  "profile": {
    "name": "<Name>"
  },
  "services": {
    "password": {
      "bcrypt": "$2a$10$eUVSifclpbABCDEFGHIJKLmnopqr12323112ABBBCEDOINg2A7q0e"
    },
    "resume": {
      "loginTokens": [ ]
    }
  }
}

db.users.add(user);

Then you can run this script (be sure to replace the and values. Also the _id if you can with a random string. This way mongodb will generate the _id as an ObjectID.

Then you can run this script (if you called it myjsfile.js) from the mand prompt (if mongo is on the local port 3001):

mongo localhost:3001/meteor myjsfile.js
发布评论

评论列表(0)

  1. 暂无评论