Devise: Can't turn off require_no_authentication?

此生再无相见时 提交于 2019-12-22 12:51:16

问题


When i try to restrict access to signup, it seems impossible. I tried

class RegistrationsController < Devise::RegistrationsController
  skip_before_filter :require_no_authentication
end

in app/registrations_controller.rb and changed routes to

devise_for :accounts, :controllers => { :registrations => "registrations" }

This does not work. Any suggestions why and what i could do/where i should look would be appreciated.

EDIT:

Does not work means: when i try to access /accounts/sign_up while being signed out, it actually works, but i should be redirected to sign_in.

WORKAROUND:

class RegistrationsController < Devise::RegistrationsController
  skip_before_filter :require_no_authentication

  private

  def authenticate_account!(opts={})
    opts[:scope] = :account
    warden.authenticate!(opts) # if !devise_controller? || opts.delete(:force)
  end
end

This removes the hardcoded check that skips authentication for EVERY Devise-controller. The code comes from lib/devise/controllers/helpers.rb.


回答1:


So you want to change after sign-out path.

If you haven't set your root to devise sign in then

class ApplicationController < ActionController::Base
  private

  # Overwriting the sign_out redirect path method
  def after_sign_out_path_for(resource_or_scope)
    new_user_session_path
  end
end


来源:https://stackoverflow.com/questions/20766081/devise-cant-turn-off-require-no-authentication

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!