BigW Consortium Gitlab

registrations_controller.rb 1.69 KB
Newer Older
Marin Jankovski committed
1
class RegistrationsController < Devise::RegistrationsController
2
  before_action :signup_enabled?
3
  include Recaptcha::Verify
Marin Jankovski committed
4

5 6 7 8
  def new
    redirect_to(new_user_session_path)
  end

9
  def create
10
    if !Gitlab::Recaptcha.load_configurations! || verify_recaptcha
11 12 13 14 15 16 17
      # 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

18 19 20 21 22 23 24 25
      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

26
  def destroy
27
    DeleteUserService.new(current_user).execute(current_user)
28 29 30 31 32 33

    respond_to do |format|
      format.html { redirect_to new_user_session_path, notice: "Account successfully removed." }
    end
  end

34 35 36 37 38 39
  protected

  def build_resource(hash=nil)
    super
  end

40 41
  def after_sign_up_path_for(user)
    user.confirmed_at.present? ? dashboard_projects_path : users_almost_there_path
42 43
  end

44
  def after_inactive_sign_up_path_for(_resource)
Phil Hughes committed
45
    users_almost_there_path
46 47
  end

Marin Jankovski committed
48 49 50
  private

  def signup_enabled?
51
    unless current_application_settings.signup_enabled?
52
      redirect_to(new_user_session_path)
53
    end
Marin Jankovski committed
54
  end
55 56 57 58

  def sign_up_params
    params.require(:user).permit(:username, :email, :name, :password, :password_confirmation)
  end
59 60 61 62 63 64

  def resource_name
    :user
  end

  def resource
Stan Hu committed
65
    @resource ||= User.new(sign_up_params)
66 67 68 69 70
  end

  def devise_mapping
    @devise_mapping ||= Devise.mappings[:user]
  end
71
end