docbrown/app/controllers/registrations_controller.rb
Julianna Tetreault 8d00e27b69
Remove Creator Onboarding Feature Flags from Codebase (#15982)
* Removes FeatureFlag.enabled?(:creator_onboarding) from codebase

* Removes FeatureFlag.enabled?(:creator_onboarding) from specs

* Further cleanup, removal, and spec fixes

* Fixes the user_request_confirmation_spec.rb

* Reverts change to confirmation email button

* Revert revert after looking at designs again :(

* Removes redundant logo_png field from config + fixes test

* Rewords an expectation in user_uses_the_editor_spec.rb

* Revert removal of logo_png from Config images

* Removes CSS class from user_uses_the_editor_spec.rb

* Removes test from user_uses_the_editor_sepc.rb

* Removes unnecessary else from _logo.html.erb

* Adds back removed system spec

* Removes SVG-related code from _logo.html.erb

* Removes AsyncInfoController#use_creator_onboarding

* Fixes spec failues due to removed code

* Removes svg-related code (that I thought I removed already :/ )

* Re-removes FeatureFlag and logo_svg from _images.html.erb

* Remove newest instances of FeatureFlag(:creator_onboarding)

* remove instances where we use the creator_onboarding field from the base_data

* fix: redirect to the correct path in the reguistrations controller based on whether the user is a creator or not

Co-authored-by: Ridhwana <ridhwana.khan16@gmail.com>
2022-01-31 11:30:43 -07:00

87 lines
2.6 KiB
Ruby

class RegistrationsController < Devise::RegistrationsController
prepend_before_action :require_no_authentication, only: []
def new
return redirect_to root_path(signin: "true") if user_signed_in?
if URI(request.referer || "").host == URI(request.base_url).host
store_location_for(:user, request.referer)
end
super
end
def create
authorize(params, policy_class: RegistrationPolicy)
unless recaptcha_verified?
flash[:notice] = "You must complete the recaptcha ✅"
return redirect_to new_user_registration_path(state: "email_signup")
end
build_devise_resource
if resource.persisted?
update_first_user_permissions(resource)
if ForemInstance.smtp_enabled?
redirect_to confirm_email_path(email: resource.email)
else
sign_in(resource)
if resource.roles.includes(:creator).any?
redirect_to new_admin_creator_setting_path
else
redirect_to root_path
end
end
else
render action: "by_email"
end
end
private
def update_first_user_permissions(resource)
return unless Settings::General.waiting_on_first_user
resource.add_role(:creator)
resource.add_role(:super_admin)
resource.add_role(:trusted)
resource.skip_confirmation!
Settings::General.waiting_on_first_user = false
Users::CreateMascotAccount.call
Discover::RegisterWorker.perform_async # Register Forem instance on https://discover.forem.com
end
def recaptcha_verified?
if ReCaptcha::CheckRegistrationEnabled.call
recaptcha_params = { secret_key: Settings::Authentication.recaptcha_secret_key }
params["g-recaptcha-response"] && verify_recaptcha(recaptcha_params)
else
true
end
end
def check_allowed_email(resource)
domain = resource.email.split("@").last
return true if Settings::Authentication.acceptable_domain?(domain: domain)
resource.email = nil
# Alright, this error message isn't quite correct. Is the email
# from a blocked domain? Or an explicitly allowed domain. I
# think this is enough.
resource.errors.add(:email, "is not included in allowed domains.")
end
def build_devise_resource
build_resource(sign_up_params)
resource.registered_at = Time.current
resource.build_setting(editor_version: "v2")
resource.remote_profile_image_url = Users::ProfileImageGenerator.call if resource.profile_image.blank?
if Settings::General.waiting_on_first_user
resource.password_confirmation = resource.password
end
check_allowed_email(resource) if resource.email.present?
resource.save if resource.email.present?
end
end