Rails Devise prevent login immediately after Signup without using Confirmable

跟風遠走 提交于 2019-11-30 16:33:07
Erez Rabih

What you need to do is to override Devise's RegistrationsController create method.

There is an excellent explanation for how to do it here.

This is Devise create action:

  # POST /resource
  def create
    build_resource

    if resource.save
      if resource.active_for_authentication?
        set_flash_message :notice, :signed_up if is_navigational_format?
        sign_in(resource_name, resource)
        respond_with resource, :location => after_sign_up_path_for(resource)
      else
        set_flash_message :notice, :"signed_up_but_#{resource.inactive_message}" if is_navigational_format?
        expire_session_data_after_sign_in!
        respond_with resource, :location => after_inactive_sign_up_path_for(resource)
      end
    else
      clean_up_passwords resource
      respond_with resource
    end
  end

After you override the controller, just remove sign_in(resource_name, resource)

You can also set the method after_sign_up_path_for(resource) to fit your needs

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