Whitelisting with devise

后端 未结 3 1667
栀梦
栀梦 2020-12-09 06:15

I am using devise to manage user authentication in my rails app. Devise is really great for that.

However I have a special requirement for my application: A user mus

3条回答
  •  感动是毒
    2020-12-09 07:07

    I did create my own controller as suggested:

    class Users::RegistrationsController < Devise::RegistrationsController
        def create
            email = params[:user][:email]
            if Admin::Whitelist.find_by_email(email) != nil
                super
            else
                build_resource
    
                set_flash_message :error, "You are not permitted to sign up yet. If you have already payed your registration fee, try again later."
                render_with_scope :new
            end
        end
    end
    

    I placed it in app/users/registrations_controller.rb. Then I had to copy the devise registration views into app/views/users/registrations because the default views were not used.

    It is working now, thanks for your help

提交回复
热议问题