Skip to content

Commit a4e5527

Browse files
committed
Refactor user registration flow in FirstRunsController to remove transaction block and streamline resource saving process. Update form helper in new.html.erb to use form_with for better compatibility. Remove unused boot_code attribute from User model.
1 parent f416dbe commit a4e5527

File tree

3 files changed

+14
-40
lines changed

3 files changed

+14
-40
lines changed

app/controllers/users/first_runs_controller.rb

Lines changed: 13 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -20,48 +20,24 @@ def create
2020
resource.skip_confirmation_notification! if resource.respond_to?(:skip_confirmation_notification!)
2121
resource.skip_confirmation! if resource.respond_to?(:skip_confirmation!)
2222

23-
result = User.transaction do
24-
# Re-check within a transaction to avoid race conditions with prevent_repeats
25-
if User.exists?
26-
redirect_to root_url
27-
:redirected
28-
end
29-
if resource.save
30-
# Ensure user is confirmed (reload to get fresh state)
31-
resource.reload
32-
resource.confirm if resource.respond_to?(:confirm) && !resource.confirmed?
33-
# Sign up the user (which includes signing them in)
34-
sign_up(resource_name, resource)
35-
redirect_to after_sign_up_path_for(resource), notice: _("Administrator account created successfully!")
36-
# Clear the boot code after the entire success flow completes
37-
FirstRunBootCode.clear!
38-
else
39-
clean_up_passwords resource
40-
set_minimum_password_length
41-
respond_with resource
42-
:invalid
43-
end
23+
if resource.save
24+
# Ensure user is confirmed (reload to get fresh state)
25+
resource.reload
26+
resource.confirm if resource.respond_to?(:confirm) && !resource.confirmed?
27+
# Sign up the user (which includes signing them in)
28+
sign_up(resource_name, resource)
29+
redirect_to after_sign_up_path_for(resource), notice: _("Administrator account created successfully!")
30+
# Clear the boot code after the entire success flow completes
31+
FirstRunBootCode.clear!
32+
else
33+
clean_up_passwords resource
34+
set_minimum_password_length
35+
respond_with resource
4436
end
45-
46-
nil if result == :redirected
4737
end
4838

4939
protected
5040

51-
# Override to permit boot_code parameter
52-
def configure_permitted_parameters
53-
super
54-
devise_parameter_sanitizer.permit(:sign_up, keys: [:boot_code])
55-
end
56-
57-
# Override to exclude boot_code from params passed to User model
58-
def sign_up_params
59-
params = super
60-
return params unless params
61-
62-
params.except(:boot_code)
63-
end
64-
6541
def build_resource(hash = {})
6642
super
6743

app/models/user.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
class User < ApplicationRecord
44
include Pwpush::TokenAuthentication
55

6-
attr_accessor :boot_code
7-
86
# Include default devise modules. Others available are:
97
# :timeoutable and :omniauthable
108
devise :database_authenticatable, :registerable,

app/views/users/first_runs/new.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<% title(_('First Run Setup')) %>
22
<h2 class='my-3'><%= _('First Run Setup') %></h2>
33

4-
<%= form_for(resource, as: resource_name, url: first_run_path) do |f| %>
4+
<%= form_with(model: resource, as: resource_name, url: first_run_path) do |f| %>
55
<%= render "devise/shared/error_messages", resource: resource %>
66

77
<% if FirstRunBootCode.needed? %>

0 commit comments

Comments
 (0)