Class: Users::RegistrationsController

Inherits:
Devise::RegistrationsController
  • Object
show all
Defined in:
app/controllers/users/registrations_controller.rb

Instance Method Summary collapse

Instance Method Details

#cancel ⇒ Object

GET /resource/cancel Forces the session data which is usually expired after sign in to be expired now. This is useful if the user wants to cancel oauth signing in/up in the middle of the process, removing all OAuth session data.



83
84
85
86
# File 'app/controllers/users/registrations_controller.rb', line 83

def cancel
  authorize :"users/registrations"
  super
end

#create ⇒ Object

POST /users



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'app/controllers/users/registrations_controller.rb', line 33

def create
  authorize User
  if Altcha.verify(params.permit(:altcha)[:altcha])
    super do |user|
      opts = {}
      opts [:approved] = false if SiteSettings.approve_signups
      if SiteSettings.autocreate_creator_for_new_users
        creator_username = params.dig(:user, :creators_attributes, "0", :slug).presence || params.dig(:user, :creators_attributes, "0", :name)&.parameterize
        opts[:username] ||= "u;#{creator_username}" if creator_username
      end
      opts.compact!
      user.update(opts) unless opts.empty?
    end
    if @user.persisted?
      ModeratorMailer.with(user: @user).new_approval.deliver_later if SiteSettings.approve_signups && SiteSettings.email_configured?
    end
  else
    build_resource
    clean_up_passwords(resource)
    flash[:alert] = t(".altcha_failed")
    render :new, status: :unprocessable_content
  end
end

#destroy ⇒ Object

DELETE /resource



73
74
75
76
# File 'app/controllers/users/registrations_controller.rb', line 73

def destroy
  authorize current_user
  super
end

#edit ⇒ Object

GET /resource/edit



23
24
25
26
27
28
29
30
# File 'app/controllers/users/registrations_controller.rb', line 23

def edit
  authorize current_user
  if @first_use
    render "first_use"
  else
    super
  end
end

#new ⇒ Object

GET /resource/sign_up



17
18
19
20
# File 'app/controllers/users/registrations_controller.rb', line 17

def new
  authorize User
  super
end

#update ⇒ Object

PUT /resource



58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'app/controllers/users/registrations_controller.rb', line 58

def update
  authorize current_user
  if @first_use
    if current_user.update(.merge(reset_password_token: nil))
       current_user
      redirect_to root_path, notice: t("devise.registrations.update.setup_complete")
    else
      render "first_use", status: :unprocessable_content
    end
  else
    super
  end
end