Rails 3-创建帐户后自动登录用户 [英] Rails 3 - logging in a user automatically after creating the account
问题描述
在我的users_controller
中,我有两种方法signup_process
和login
.我想在成功调用signup_process
后自动为用户调用login
.
In my users_controller
I have two methods signup_process
and login
. I would like to call login
automatically for a user after a successful signup_process
call.
这可能吗?在其他语言框架中,我通常只直接通过传递用户名和密码的signup_process
动作来调用login
控制器动作-但是我认为这在Rails中是不受欢迎的.
Is this possible? In other language frameworks I would usually just call the login
controller action direct from the signup_process
action passing the username and password - but I think that is frowned upon in Rails.
是否有其他方法可以将用户数据从我的控制器发布到users.login
操作?
Is there some way instead to post the user data to the users.login
action from my controller?
这必须是一种常见的模式-我想念什么? :)
This must be a common pattern - what am I missing? :)
提前谢谢!
推荐答案
不确定皱眉的意思,但这是一种方法
Not sure what you mean by frowned upon, but here's one way
class UsersController < ...
def signup
// Do some stuff
do_login(username, password)
// render or redirect as you wish
end
def login
do_login(username,password)
// render or redirect as you wish
end
private
def do_login(username,password)
// do the actual login processing
// can even render or redirect here if it's common to both setup and login
end
end
那你想做什么吗?
这篇关于Rails 3-创建帐户后自动登录用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!