GitLab wurde erfolgreich aktualisiert. Durch regelmäßige Updates bleibt das THM GitLab sicher. Danke für Ihre Geduld.

registrations_controller.rb 1.66 KB
Newer Older
Marin Jankovski's avatar
Marin Jankovski committed
1
class RegistrationsController < Devise::RegistrationsController
2
  include Recaptcha::Verify
Marin Jankovski's avatar
Marin Jankovski committed
3

4 5 6 7
  def new
    redirect_to(new_user_session_path)
  end

8
  def create
9 10 11 12 13 14
    # 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
15

16
    if !Gitlab::Recaptcha.load_configurations! || verify_recaptcha
17 18
      super
    else
19
      flash[:alert] = 'There was an error with the reCAPTCHA. Please solve the reCAPTCHA again.'
20 21 22
      flash.delete :recaptcha_error
      render action: 'new'
    end
23 24
  rescue Gitlab::Access::AccessDeniedError
    redirect_to(new_user_session_path)
25 26
  end

Marin Jankovski's avatar
Marin Jankovski committed
27
  def destroy
28
    Users::DestroyService.new(current_user).execute(current_user)
Marin Jankovski's avatar
Marin Jankovski committed
29 30

    respond_to do |format|
31 32 33
      format.html do
        session.try(:destroy)
        redirect_to new_user_session_path, notice: "Account successfully removed."
34
      end
Marin Jankovski's avatar
Marin Jankovski committed
35 36 37
    end
  end

38 39
  protected

40
  def build_resource(hash = nil)
41 42 43
    super
  end

44
  def after_sign_up_path_for(user)
45
    user.confirmed? ? dashboard_projects_path : users_almost_there_path
46 47
  end

48
  def after_inactive_sign_up_path_for(_resource)
Phil Hughes's avatar
Phil Hughes committed
49
    users_almost_there_path
50 51
  end

Marin Jankovski's avatar
Marin Jankovski committed
52 53
  private

54
  def sign_up_params
55
    params.require(:user).permit(:username, :email, :email_confirmation, :name, :password)
56
  end
57 58 59 60 61 62

  def resource_name
    :user
  end

  def resource
63
    @resource ||= Users::CreateService.new(current_user, sign_up_params).build
64 65 66 67 68
  end

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