Devise with Confirmable - 用户尝试使用未经确认的电子邮件登录时,将用户重定向到自定义页面 [英] Devise with Confirmable - Redirect user to a custom page when users tries to sign in with an unconfirmed email

查看:116
本文介绍了Devise with Confirmable - 用户尝试使用未经确认的电子邮件登录时,将用户重定向到自定义页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

启用可确认模块后,Devise将不允许未经确认的用户在预定义的时间段过去之后登录。相反,用户将被重定向回登录页面,并显示闪烁的消息您必须在继续之前确认您的帐户。



这是一个不良的交互模式,如闪电通知没有提供足够的空间来向用户正确解释访问被拒绝的原因,确认您的帐户是指提供重新发送确认的链接,以及如何检查垃圾邮件文件夹等的指示。 p>

有没有办法改变这个行为来重定向到一个特定的URL?

解决方案

对不起,我以为你的意思是注册后不能登录。所以下面的工作原理是如何在注册后指导用户,并且您需要做什么来登录是创建一个自定义的Devise :: FailureApp



请参阅wiki页面: https://github.com/plataformatec/devise/wiki/How-To:-Redirect-to-a-specific-page-when-the-user-can-not-be-authenticated



然后在您的自定义FailureApp中从 redirect_url /plataformatec/devise/blob/master/lib/devise/failure_app.rbrel =noreferrer> https://github.com/plataformatec/devise/blob/master/lib/devise/failure_app.rb

  def redirect_url 
如果warden_message ==:未确认
custom_redirect_path
else
super
end
end

注册后自定义重定向: p>

T这是一个控制器方法 after_inactive_sign_up_path_for 在注册控制器中,您可以覆盖以完成此操作。



首先在您的路线中将需要指定使用您的自定义控制器:



config / routes.rb

  devise_for:users,:controllers => {:registrations => 用户/注册} 

第二个创建您的自定义控制器从普通控制器继承为了覆盖方法:



app / controllers / users / registrations_controller.rb

  class Users :: RegistrationsController< Devise :: RegistrationsController 

protected

def after_inactive_sign_up_path_for(resource)
signed_up_path
end

end

在这种情况下,我的App我的Devise模型是User,所以如果您的模型的名称不同,您可能需要更改该名称空间。我希望我的用户被重定向到 signed_up_path ,但您可以将其更改为所需的路径。


With the Confirmable module enabled, Devise will not allow an unconfirmed user to sign in after a predefined period of time has elapsed. Instead the user is redirected back to the sign in page with the flash message "You have to confirm your account before continuing".

This is an undesirable interaction model, as a flash notice does not provide adequate space to properly explain to the user why access has been denied, what "confirm your account" means, provide a link to resend the confirmation, and instructions on how to check your spam folder and so on.

Is there a way I can change this behaviour to redirect to a specific URL instead?

解决方案

Sorry at first I thought you meant after Sign Up not Sign In. So the down below works for how to direct users after Sign Up and what you need to do for Sign In is to create a custom Devise::FailureApp

See the wiki page: https://github.com/plataformatec/devise/wiki/How-To:-Redirect-to-a-specific-page-when-the-user-can-not-be-authenticated

Then within your custom FailureApp overwrite redirect_url method from https://github.com/plataformatec/devise/blob/master/lib/devise/failure_app.rb:

  def redirect_url
    if warden_message == :unconfirmed
      custom_redirect_path
    else
      super
    end
  end

For custom redirect after Sign Up:

There is a controller method after_inactive_sign_up_path_for within the RegistrationsController that you can overwrite to accomplish this.

First in your Routes you will need to specify to use your custom controller:

config/routes.rb:

  devise_for :users, :controllers => { :registrations => "users/registrations" }

Second you create your custom controller that inherits from the normal controller in order to overwrite the method:

app/controllers/users/registrations_controller.rb

class Users::RegistrationsController < Devise::RegistrationsController

  protected

  def after_inactive_sign_up_path_for(resource)
    signed_up_path
  end

end

In this case for my App my Devise model is User so you may want to change that namespace if your model is named differently. I wanted my users to be redirected to the signed_up_path, but you can change that to your desired path.

这篇关于Devise with Confirmable - 用户尝试使用未经确认的电子邮件登录时,将用户重定向到自定义页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆