如何重定向Devise的注册和身份验证失败?

凯蒂

我要的是,如果有人进入签约或重定向到不同的网页默认的其他假设签署时错误信息mycontroller#index在我的应用我已经overiddingDevise::SessionsControllerDevise::RegistrationsController。我遵循此链接中的步骤设计重定向登录后失败,但仍然我被重定向到注册页面和登录页面。我正在使用Rails 3.2和Devise 3.4.1,这是我的代码...。我做错了什么或缺少什么?在此先感谢您。

会话控制器

class SessionsController < Devise::SessionsController

  def create
    resource = warden.authenticate!(:scope => resource_name, :recall => "#   {controller_path}#failure")
    sign_in_and_redirect(resource_name, resource)
  end

  def sign_in_and_redirect(resource_or_scope, resource=nil)
    scope = Devise::Mapping.find_scope!(resource_or_scope)
    resource ||= resource_or_scope
    sign_in(scope, resource) unless warden.user(scope) == resource
    return render :json => {:success => true}
  end

  def failure
    return render :json => {:success => false, :errors => ["Login failed."]}
  end
end

注册控制器

class RegistrationsController < Devise::RegistrationsController

  def create
    build_resource

    if resource.save
      if resource.active_for_authentication?
        set_flash_message :notice, :signed_up if is_navigational_format?
        sign_up(resource_name, resource)
        return render :json => {:success => true}
      else
        set_flash_message :notice, :"signed_up_but_#{resource.inactive_message}" if  is_navigational_format?
        expire_session_data_after_sign_in!
        return render :json => {:success => true}
      end
    else
      clean_up_passwords resource
      return render :json => {:success => false}


      redirect_to {:controller=>"deal",:action=>"confirm_and_pay"}
    end

  end

  def sign_up(resource_name, resource)
    sign_in(resource_name, resource)
  end

end

路线

devise_for :users, :skip => [:registrations, :sessions]
devise_scope :user do

  get 'signup' => 'devise/registrations#new', :as => :new_user_registration 
  post 'signup' => 'devise/registrations#create', :as => :user_registration 
  get 'users/cancel' => 'devise/registrations#cancel', :as => :cancel_user_registration 
  get 'users/edit' => 'devise/registrations#edit', :as => :edit_user_registration 
  put 'users' => 'devise/registrations#update' 
  delete 'users/cancel' => 'devise/registrations#destroy' ,:as=>:destroy_user_session
  get 'signin' => 'devise/sessions#new', :as => :new_user_session 
  post 'signin' => 'devise/sessions#create', :as => :user_session 
  get 'signout' => 'devise/sessions#destroy', :as => :destroy_user_session 
end

应用控制器

class ApplicationController < ActionController::Base

  protect_from_forgery

  def after_sign_up_path_for(resource)
    show_deals_path(resource)
  end

  def after_sign_in_path_for(resource)
    sign_in_url = url_for(:action => 'new', :controller => 'sessions', :only_path => false, :protocol => 'http')
    if request.referer == sign_in_url
      super
    else
      stored_location_for(resource) || request.referer || root_path
    end
  end
end

lib / custom_failure.rb

class CustomFailure < Devise::FailureApp
  def redirect_url
    redirect_to {:controller=>"mycontroller",:action=>"index"}
  end

  def respond
    if http_auth?
      http_auth
    else
      redirect
    end
  end
end

application.rb

config.autoload_paths += %W(#{config.root}/lib)
Shirakia

如果要在登录失败链接遵循Devise重定向,则应将其添加到config / initializers / devise.rb中

config.warden do |manager|
  manager.failure_app = CustomFailure
end

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

Laravel身份验证重定向失败

来自分类Dev

身份验证重定向失败

来自分类Dev

Django 身份验证注册视图登录重定向

来自分类Dev

如果Passport身份验证失败,如何在重定向中保留表单数据?

来自分类Dev

Next.js + Redux身份验证和重定向

来自分类Dev

使用 Devise,如何自定义失败的身份验证?

来自分类Dev

在Laravel中进行身份验证后如何重定向?

来自分类Dev

身份验证后如何重定向回主页

来自分类Dev

如何防止 cookie 身份验证重定向到登录

来自分类Dev

如何将我的注册页面从表单身份验证重定向到登录页面中排除

来自分类Dev

dotnetcore 2.2 MVC 应用程序和 ADFS 之间的 PING_PONG:身份验证失败 + 重定向

来自分类Dev

身份验证失败:Devise + OmniAuth + Facebook

来自分类Dev

Rails Devise将经过身份验证的用户重定向到特定路径

来自分类Dev

Rails / Devise(设计令牌身份验证)在解锁帐户时重定向

来自分类Dev

身份验证的URL重定向

来自分类Dev

CodeIgniter社区身份验证重定向

来自分类Dev

Laravel 身份验证无法重定向

来自分类Dev

使用Google Oauth 2.0进行身份验证与注册的重定向URI不匹配

来自分类Dev

Laravel 5重定向到身份验证/登录会导致失败

来自分类Dev

LibGit2Sharp:获取失败,并显示“重定向或身份验证重放过多”

来自分类Dev

泽西岛客户端:詹金斯重定向时身份验证失败

来自分类Dev

使用Spring将重定向设置为自定义身份验证失败处理程序

来自分类Dev

Spring Security Lgoin始终重定向到身份验证失败URL

来自分类Dev

设计:在用户身份验证失败时重定向到不同的路径

来自分类Dev

Django注册和身份验证

来自分类Dev

Ember简单身份验证:身份验证后如何重定向回最后访问的路由?

来自分类Dev

Node.js和PassportJs:如果身份验证失败,则不会在passport.authenticate之后重定向中间件

来自分类Dev

Yii将管理员和通过身份验证的用户重定向到所需页面

来自分类Dev

在OAuth2身份验证调用和重定向调用之间传递值

Related 相关文章

  1. 1

    Laravel身份验证重定向失败

  2. 2

    身份验证重定向失败

  3. 3

    Django 身份验证注册视图登录重定向

  4. 4

    如果Passport身份验证失败,如何在重定向中保留表单数据?

  5. 5

    Next.js + Redux身份验证和重定向

  6. 6

    使用 Devise,如何自定义失败的身份验证?

  7. 7

    在Laravel中进行身份验证后如何重定向?

  8. 8

    身份验证后如何重定向回主页

  9. 9

    如何防止 cookie 身份验证重定向到登录

  10. 10

    如何将我的注册页面从表单身份验证重定向到登录页面中排除

  11. 11

    dotnetcore 2.2 MVC 应用程序和 ADFS 之间的 PING_PONG:身份验证失败 + 重定向

  12. 12

    身份验证失败:Devise + OmniAuth + Facebook

  13. 13

    Rails Devise将经过身份验证的用户重定向到特定路径

  14. 14

    Rails / Devise(设计令牌身份验证)在解锁帐户时重定向

  15. 15

    身份验证的URL重定向

  16. 16

    CodeIgniter社区身份验证重定向

  17. 17

    Laravel 身份验证无法重定向

  18. 18

    使用Google Oauth 2.0进行身份验证与注册的重定向URI不匹配

  19. 19

    Laravel 5重定向到身份验证/登录会导致失败

  20. 20

    LibGit2Sharp:获取失败,并显示“重定向或身份验证重放过多”

  21. 21

    泽西岛客户端:詹金斯重定向时身份验证失败

  22. 22

    使用Spring将重定向设置为自定义身份验证失败处理程序

  23. 23

    Spring Security Lgoin始终重定向到身份验证失败URL

  24. 24

    设计:在用户身份验证失败时重定向到不同的路径

  25. 25

    Django注册和身份验证

  26. 26

    Ember简单身份验证:身份验证后如何重定向回最后访问的路由?

  27. 27

    Node.js和PassportJs:如果身份验证失败,则不会在passport.authenticate之后重定向中间件

  28. 28

    Yii将管理员和通过身份验证的用户重定向到所需页面

  29. 29

    在OAuth2身份验证调用和重定向调用之间传递值

热门标签

归档