Aen*_*Tan 2 ruby authentication ruby-on-rails devise ruby-on-rails-3
我有一堆代码将来自登录用户的访客/懒惰注册帐户的内容移交给我在创建新会话时运行的新帐户.
class SessionsController < Devise::SessionsController
def new
super
end
def create
super
logging_in # this is the method which will run
end
def destroy
super
end
end
Run Code Online (Sandbox Code Playgroud)
它在用户登录时有效.但是当Devise在确认后记录用户时,上述操作无法运行.如果我希望在用户登录后运行该方法,我应该在哪里放置?是通过登录还是确认.
谢谢纳什.这就是我做到的.
class ConfirmationsController < Devise::ConfirmationsController
def new
super
end
def create
super
end
def show
self.resource = resource_class.confirm_by_token(params[:confirmation_token])
if resource.errors.empty?
set_flash_message(:notice, :confirmed) if is_navigational_format?
sign_in(resource_name, resource)
logging_in # Here it is
respond_with_navigational(resource){ redirect_to after_confirmation_path_for(resource_name, resource) }
else
respond_with_navigational(resource.errors, :status => :unprocessable_entity){ render :new }
end
end
protected
def after_resending_confirmation_instructions_path_for(resource_name)
new_session_path(resource_name)
end
def after_confirmation_path_for(resource_name, resource)
after_sign_in_path_for(resource)
end
end
Run Code Online (Sandbox Code Playgroud)
它需要在sign_in我的logging_in方法使用之后添加current_user.
| 归档时间: |
|
| 查看次数: |
1468 次 |
| 最近记录: |