导轨设计参数
有没有一种设计方法可以让我简单地发送包含用户密码名称或电子邮件的网址,并注册用户或启动新会话,而不是通过表单实际登录(我想简单地发送用户名和密码并登录用户或注册他)
Is there a way in devise that i can simply send in a url that contains a users password name or email and it registers the user or starts a new sessions, rather than actually logging in through the form (I want to simply send in username and password and login the user or register him)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
出于多种原因,这通常是一个坏主意,但如果您的用例需要它,没有什么可以阻止您这样做。
由于 Devise 用户记录只是标准的 Active Record 记录,因此您可以像任何其他对象一样在它们上使用查找器:
u = User.find(:first, :conditions => {:username => 'foo'})
并像创建任何其他对象一样创建它们:
Devise 提供了一个
valid_password?
实例方法,您可以使用它来检查检索到的对象的密码:u.valid_password?('monkey')
并且从任何控制器,您都可以使用检索到的用户对象调用
sign_in
:sign_in(:user, u)
代码>This is a generally a bad idea for numerous reasons, but if your use case demands it, there's nothing stopping you from doing it.
Since Devise user records are just standard Active Record records, you can use finders on them like any other object:
u = User.find(:first, :conditions => {:username => 'foo'})
And create them mostly like any other object:
Devise provides a
valid_password?
instance method you can use to check the password of a retrieved object:u.valid_password?('monkey')
And from any controller, you can call
sign_in
with a retrieved user object:sign_in(:user, u)
看一下 Devise 的“TokenAuthenticable”模块,它为用户提供了唯一的登录密钥,尽管它与他们的电子邮件或密码不同。
Take a look at Devise's "TokenAuthenticable" module which gives a user a unique login key, although it's not the same as their email or password.
您可以在不使用设备的情况下完成所有这些事情。在任何其他情况下,您应该重写设计安全系统。
You can do all that things without using devise. In any other case you should rewrite devise security system.