创建一个没有自动登录 Meteor 的用户客户端
Creating a user client side without auto login Meteor
对于我使用 Meteor 制作的应用程序,我具有在客户端应用程序上添加用户的功能,但是如果我只是调用 Accounts.createUser
,它会自动登录到新用户的帐户。为了解决这个问题,我目前正在调用服务器端方法并仅在下面的 Meteor.call()
中传递数据。我很确定这会将密码作为纯文本传递给服务器,这是错误的。
有什么方法可以确保数据安全地发送到服务器方法,而无需自动登录用户?
Meteor.call('serverCreateUser', username, password, phone, email, admin)
I am pretty sure that this passes the password as plain text to the server which is bad.
使用标准的 Meteor 方法,是的。这就是为什么您应该始终在生产中使用 https!
但是您可以采用不同的方法。您实际上可以创建一个用户,而无需提供密码,那么任何人都无法使用该帐户登录。然后,您向该用户发送 enrollment email,要求用户设置初始密码,然后在通过网络发送之前对其进行哈希处理:
Meteor.methods({
'serverCreateUser' (username, phone, email) {
// server should consider based on server-only rules, whether
// a user will be an admin!
const userId = Accounts.createUser({ username, email })
// set profile fields
Meteor.users.update(userId, { $set: { phone })
// send enrollment mail
Accounts.sendEnrollmentEmail(userId)
// return new user id
return userId
}
})
当用户在客户端设置初始密码时,它将使用 Accounts.resetPassword
。
请注意,这仍然需要 https,因为散列密码仍然不是加密密码。
对于我使用 Meteor 制作的应用程序,我具有在客户端应用程序上添加用户的功能,但是如果我只是调用 Accounts.createUser
,它会自动登录到新用户的帐户。为了解决这个问题,我目前正在调用服务器端方法并仅在下面的 Meteor.call()
中传递数据。我很确定这会将密码作为纯文本传递给服务器,这是错误的。
有什么方法可以确保数据安全地发送到服务器方法,而无需自动登录用户?
Meteor.call('serverCreateUser', username, password, phone, email, admin)
I am pretty sure that this passes the password as plain text to the server which is bad.
使用标准的 Meteor 方法,是的。这就是为什么您应该始终在生产中使用 https!
但是您可以采用不同的方法。您实际上可以创建一个用户,而无需提供密码,那么任何人都无法使用该帐户登录。然后,您向该用户发送 enrollment email,要求用户设置初始密码,然后在通过网络发送之前对其进行哈希处理:
Meteor.methods({
'serverCreateUser' (username, phone, email) {
// server should consider based on server-only rules, whether
// a user will be an admin!
const userId = Accounts.createUser({ username, email })
// set profile fields
Meteor.users.update(userId, { $set: { phone })
// send enrollment mail
Accounts.sendEnrollmentEmail(userId)
// return new user id
return userId
}
})
当用户在客户端设置初始密码时,它将使用 Accounts.resetPassword
。
请注意,这仍然需要 https,因为散列密码仍然不是加密密码。