Accounts.config && Accounts.ui.config
- Accounts.config 是关于全局的账户系统配置。
主要配置项:- sendVerificationEmail:布尔值,对新用户发送验证邮件。
- forbidClientAccountCreation:布尔值。为真时,client 端调用的
Accounts.createUser
方法将被拒绝。如果使用的 accounts-ui 这个包,在 view 上的新建用户按钮也会不显示。 - restrictCreationByEmailDomain:字符串或函数。严格校验用户创建时的邮箱格式,
- 如果是字符串
Accounts.config({ restrictCreationByEmailDomain: 'school.edu' })
,只有邮箱 domain 满足school.edu
的才能创建成功。 - 如果是函数,则将邮箱作为参数传入,返回 true 时才能创建成功。
- 如果是字符串
- loginExpirationInDays:数值对象。登录有效期,默认90天,为 null 时登录用不失效。
- oauthSecretKey:使用 oauth-encryption 设置的 key。详细参考:https://github.com/meteor/meteor/tree/dc3cd6eb92f2bdd1bb44000cdd6abd1e5d0285b1/packages/oauth-encryption
- Accounts.ui.config 是accounts-ui 提供的
{{> loginButtons}}
的视图层面的配置。
主要配置项:- requestPermissions:
- requestOfflineToken:
- forceApprovalPrompt:
- passwordSignupFields:用户注册时,需要填写的数据字段。可选项
USERNAME_AND_EMAIL
,USERNAME_AND_OPTIONAL_EMAIL
,USERNAME_ONLY
,EMAIL_ONLY
(default).
publish and subscribe Meteor.users
未对Meteor.users 作数据发布处理,Server 会将当前登录用户的数据发布到 client 端。在 client 端使用 Meteor.users().find().fetch()
只能获取到当前登录用户的数据。
若 client 端需要其他的用户数据。需要在服务端进行发布。
In server:
1 | Meteor.publish("users", function() { return Meteor.users.find(); } |
In client:
1 | Meteor.subscribe("users"); Meteor.users().find().fetch(); //获取所有用户的数据 |
users filed in datebase
1 | { "_id" : "8CoDmspe8BmwHjAXD", "createdAt" : ISODate("2015-10-19T08:45:25.791Z"), "services" : { "password" : { "bcrypt" : "$2a$10$gElhcQhAx2tIZ9FjrFuB1euZEKhJLx5VYFGJL1HRGrWvBhC/RrMFS" }, "resume" : { "loginTokens" : [ { "when" : ISODate("2015-10-13T02:44:28.523Z"), "hashedToken" : "wSyL6wU0l4ABDFeNTNpPoi1MbiioJvQNCNLEglQ6Zgs=" } ] } }, "username" : "test", "emails" : [ { "address" : "test@qq.com", "verified" : false } ], "profile" : { } } |
标准的users 表中一条记录的结构,
- resume
模板
- 在模板中渲染某个数组指定下标的元素,如渲染用户系统数据的第一个邮箱
this.emails.[0].address