![](/img/trans.png)
[英]How can an admin add another user or admin accounts in ruby devise without logging them in?
[英]How to check if a user's password is correct without logging them in with Devise?
我正在编写一个时钟系统,其中用户可以通过在特定计算机上输入username
和password
来有效打孔其时钟。 时钟用户将首先登录。 我只需要通过检查username
输入的username
和password
是否正确来注册该用户。 我如何在Devise
做到这一点?
我不想实际登录 ,只检查他们是谁。 时钟用户是始终登录的唯一用户。
如果您使用gem devise。 尝试
User.find(1).valid_password?('password123') # returns true/false
文件中的代码:devise / lib / devise / models / database_authenticatable.rb
Devise为您提供了两种内置方法 ,可让您精确地做到这一点:
user = User.find_for_authentication(username: params[:username])
user.valid_password?(params[:password])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.