diff --git a/app/controllers/registrations_controller.rb b/app/controllers/registrations_controller.rb
index 59f0783dd4..3349b33b71 100644
--- a/app/controllers/registrations_controller.rb
+++ b/app/controllers/registrations_controller.rb
@@ -22,23 +22,20 @@ def destroy
end
def create
- unless params[:owner_slug].blank?
- @owner = User.where(slug: params[:owner_slug]).first
- end
+ @owner = User.find_by(slug: params[:owner_slug]) if params[:owner_slug].present?
- #merge the new user information into the guest user id to change into normal user
- if current_user && current_user.guest?
+ # Merge the new user information into the guest user id to change into normal user
+ if current_user&.guest?
@user = current_user
@user.update(sign_up_params)
@user.guest = false
-
else
@user = build_resource(sign_up_params)
end
- #this is the default Devise code
+ # This is the default Devise code
yield resource if block_given?
-
+
if check_recaptcha(model: @user) && @user.save
# Record the `joined` deed based on Ahoy Visit
join_collection = joined_from_collection(current_visit.id)
@@ -61,7 +58,7 @@ def create
if session[:guest_user_id]
session[:guest_user_id] = nil
end
-
+
if @user.owner
@user.account_type="Trial"
@user.save
@@ -73,7 +70,8 @@ def create
if @validatable
@minimum_password_length = resource_class.password_length.min
end
- respond_with resource
+
+ after_failed_sign_up_action_for(params[:registration_type]&.to_sym)
end
end
@@ -95,7 +93,6 @@ def update
end
end
-
def set_saml
institution = saml_provider_param
redirect_to user_omniauth_authorize_path(institution) #go to users/auth/saml/instution_name
@@ -114,7 +111,7 @@ def alert_bento()
def after_sign_up_path_for(resource)
if @user.owner
# Always send new owners to their dashboard for analytics purposes
- "#{dashboard_owner_path}#freetrial"
+ "#{dashboard_owner_path}#freetrial"
else
# New users should be returned to where they were or to their dashboard/watchlist
if session[:user_return_to] && !landing_pages.include?(session[:user_return_to])
@@ -131,6 +128,15 @@ def after_update_path_for(resource)
edit_registration_path(resource)
end
+ def after_failed_sign_up_action_for(registration_type)
+ case registration_type
+ when :free_trial
+ render :new_trial
+ else
+ render :new
+ end
+ end
+
def check_recaptcha(options)
return verify_recaptcha(options) if RECAPTCHA_ENABLED
true
diff --git a/app/models/user.rb b/app/models/user.rb
index d656a51f75..7da009f26a 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -150,8 +150,9 @@ def email_does_not_match_denylist
end
end
-
def update_display_name
+ self.real_name = nil if self.real_name.blank?
+
if self.owner
self.display_name = self.real_name
else
@@ -287,9 +288,9 @@ def like_owner?(obj)
def display_name
if self.guest
- "Guest"
+ 'Guest'
else
- self[:display_name] || self[:login]
+ self[:display_name].presence || self[:login]
end
end
diff --git a/app/views/devise/registrations/new_trial.html.slim b/app/views/devise/registrations/new_trial.html.slim
index fd058cf80a..4867812a55 100644
--- a/app/views/devise/registrations/new_trial.html.slim
+++ b/app/views/devise/registrations/new_trial.html.slim
@@ -9,8 +9,7 @@ section.signon
==t('.just_want_to_transcribe', sign_up_here: (link_to t('.sign_up_here'), new_user_registration_path))
-
- =form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f|
+ =form_for(resource, as: resource_name, url: registration_path(resource_name, registration_type: :free_trial)) do |f|
=devise_error_messages!
.signon_field
=f.label :login, t('.login')
@@ -37,4 +36,4 @@ section.signon
=f.check_box :activity_email, checked: true
=f.label :receive_activity_emails, t('devise.receive_activity_emails')
- =f.button t('devise.create_account'), class: 'big'
\ No newline at end of file
+ =f.button t('devise.create_account'), class: 'big'