Rails Devise prevent login immediately after Signup without using Confirmable

谁说胖子不能爱 提交于 2019-11-29 23:21:55

问题


Use Case:

  1. Admin should be able to create user, and it should not attempt to login.
  2. Public User can crate account and after signup he should be redirected to sign-in page rather signing him in immediately.

Can somebody help me with this ?

Thanks :)


回答1:


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



来源:https://stackoverflow.com/questions/12541224/rails-devise-prevent-login-immediately-after-signup-without-using-confirmable

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