Skip to content
Snippets Groups Projects
registrations_controller.rb 1.68 KiB
Newer Older
  • Learn to ignore specific revisions
  • Marin Jankovski's avatar
    Marin Jankovski committed
    class RegistrationsController < Devise::RegistrationsController
    
      before_action :signup_enabled?
    
      def new
        redirect_to(new_user_session_path)
      end
    
    
        if !Gitlab::Recaptcha.load_configurations! || verify_recaptcha
    
          # To avoid duplicate form fields on the login page, the registration form
          # names fields using `new_user`, but Devise still wants the params in
          # `user`.
          if params["new_#{resource_name}"].present? && params[resource_name].blank?
            params[resource_name] = params.delete(:"new_#{resource_name}")
          end
    
    
          super
        else
          flash[:alert] = "There was an error with the reCAPTCHA code below. Please re-enter the code."
          flash.delete :recaptcha_error
          render action: 'new'
        end
      end
    
    
    Marin Jankovski's avatar
    Marin Jankovski committed
      def destroy
    
        DeleteUserService.new(current_user).execute(current_user)
    
    Marin Jankovski's avatar
    Marin Jankovski committed
    
        respond_to do |format|
          format.html { redirect_to new_user_session_path, notice: "Account successfully removed." }
        end
      end
    
    
      def build_resource(hash = nil)
    
        user.confirmed? ? dashboard_projects_path : users_almost_there_path
    
      def after_inactive_sign_up_path_for(_resource)
    
    Phil Hughes's avatar
    Phil Hughes committed
        users_almost_there_path
    
    Marin Jankovski's avatar
    Marin Jankovski committed
      private
    
      def signup_enabled?
    
        unless current_application_settings.signup_enabled?
    
          redirect_to(new_user_session_path)
    
    Marin Jankovski's avatar
    Marin Jankovski committed
      end
    
    
      def sign_up_params
        params.require(:user).permit(:username, :email, :name, :password, :password_confirmation)
      end
    
    Stan Hu's avatar
    Stan Hu committed
        @resource ||= User.new(sign_up_params)
    
      end
    
      def devise_mapping
        @devise_mapping ||= Devise.mappings[:user]
      end