We've moved discussions to Discord

Remove Sign-up Ability [SOLVED]

Dan Tappin
  can you provide some guidance on how to remove the ability for new users to sign-up?  I can remove :registerable from the User devise section however this breaks the user profile update code etc.
Michelle Hartley
Remove the sign up button from views/static/index.html.erb. 
Dan Tappin
I have done that already. That doesn’t stop anyone from still getting to that form and signing up. I want to disable the registration completely.

I have and idea how this should be done but I was hoping  might might be able to drop some pointers.
Michelle Hartley

You could try ... Might work but I haven't tried it yet.
Add devise_for :users, :skip => [:registrations] to routes
In views/devise/shared/_links.html.erb remove new_registration_path
Write your own create/edit user actions. 



Chris Oliver
Yeah, looks like you can just disable the registration routes and then manually add the edit registration ones.

https://stackoverflow.com/questions/39773890/how-to-remove-disable-sign-up-from-devise
Dan Tappin
  I followed that:

  # User account
  devise_for :users,
             controllers: {
               masquerades: 'jumpstart/masquerades',
#               omniauth_callbacks: 'users/omniauth_callbacks',
#               registrations: 'users/registrations',
             }
             
  as :user do
    get 'users/edit' =>  'devise/registrations#edit', as: 'edit_user_registration'
    put 'users' => 'devise/registrations#update', as: 'user_registration'
  end...

and...

#  devise :database_authenticatable, :registerable, :recoverable, :rememberable, :validatable, :confirmable, :invitable, :masqueradable, :omniauthable
  devise :database_authenticatable, :recoverable, :rememberable, :validatable, :confirmable, :invitable, :masqueradable

When I go to edit my profile it throws a validation error:

I looked in your `users/registrations_controller.rb`:

class Users::RegistrationsController < Devise::RegistrationsController
  protected

  def build_resource(hash = {})
    self.resource = resource_class.new_with_session(hash, session)

    # Jumpstart: Skip email confirmation on registration.
    #   Require confirmation when user changes their email only
    self.resource.skip_confirmation!
  end

  def update_resource(resource, params)
    # Jumpstart: Allow user to edit their profile without password
    resource.update_without_password(params)
  end
end

I am guessing 'update_resource(resource, params)' is not overriding the default method now?
Dan Tappin
Yup... that was it.  Don't use the devise controllers - user the User which overrides the Devise ones.

  as :user do
    get 'users/edit' =>  'users/registrations#edit', as: 'edit_user_registration'
    put 'users' => 'users/registrations#update', as: 'user_registration'
  end
Dan Tappin
  can you provide some guidance on how to remove the ability for new users to sign-up?  I can remove :registerable from the User devise section however this breaks the user profile update code etc.
Michelle Hartley
Remove the sign up button from views/static/index.html.erb. 
Dan Tappin
I have done that already. That doesn’t stop anyone from still getting to that form and signing up. I want to disable the registration completely.

I have and idea how this should be done but I was hoping  might might be able to drop some pointers.
Michelle Hartley

You could try ... Might work but I haven't tried it yet.
Add devise_for :users, :skip => [:registrations] to routes
In views/devise/shared/_links.html.erb remove new_registration_path
Write your own create/edit user actions. 



Chris Oliver
Yeah, looks like you can just disable the registration routes and then manually add the edit registration ones.

https://stackoverflow.com/questions/39773890/how-to-remove-disable-sign-up-from-devise
Dan Tappin
  I followed that:

  # User account
  devise_for :users,
             controllers: {
               masquerades: 'jumpstart/masquerades',
#               omniauth_callbacks: 'users/omniauth_callbacks',
#               registrations: 'users/registrations',
             }
             
  as :user do
    get 'users/edit' =>  'devise/registrations#edit', as: 'edit_user_registration'
    put 'users' => 'devise/registrations#update', as: 'user_registration'
  end...

and...

#  devise :database_authenticatable, :registerable, :recoverable, :rememberable, :validatable, :confirmable, :invitable, :masqueradable, :omniauthable
  devise :database_authenticatable, :recoverable, :rememberable, :validatable, :confirmable, :invitable, :masqueradable

When I go to edit my profile it throws a validation error:

I looked in your `users/registrations_controller.rb`:

class Users::RegistrationsController < Devise::RegistrationsController
  protected

  def build_resource(hash = {})
    self.resource = resource_class.new_with_session(hash, session)

    # Jumpstart: Skip email confirmation on registration.
    #   Require confirmation when user changes their email only
    self.resource.skip_confirmation!
  end

  def update_resource(resource, params)
    # Jumpstart: Allow user to edit their profile without password
    resource.update_without_password(params)
  end
end

I am guessing 'update_resource(resource, params)' is not overriding the default method now?
Dan Tappin
Yup... that was it.  Don't use the devise controllers - user the User which overrides the Devise ones.

  as :user do
    get 'users/edit' =>  'users/registrations#edit', as: 'edit_user_registration'
    put 'users' => 'users/registrations#update', as: 'user_registration'
  end
Notifications
You’re not receiving notifications from this thread.
© 2023 Jumpstart Pro by GoRails, LLC