docbrown/app/controllers/registrations_controller.rb
Lisa Sy 54c071856e
[deploy] Update top-header for logged-out user (#9874)
* Create first start at desktop top header updates

* Update mobile styling of top header

* Stylize sign in widget card

* Update nav menu and top bar

* Changes based on user being logged-in or not

* Uses user_signed_in? on top nav bar

* Fix lingering old cloudinary helper method

* Trigger CI

* Fixes specs

* Adds redirect_using_referer_spec, fixes other specs & cleanup

* Adds nav-menu.scss to layouts/_styles.html.erb for inline & small edit in referer check

* Remove logged-out styles to make it more uniform with logged in

* Remove nav-menu.scss file

* cleanup markup and JS a little

* Fixes FB auth specs to new login links

* Makes sure unauthenticated /new redirects back to editor

* CI fix Sing in with -> Continue with

* Update db/schema.rb

* Update db/schema.rb

* Update db/schema.rb

Co-authored-by: Fernando Valverde <fdov88@gmail.com>
Co-authored-by: ludwiczakpawel <ludwiczakpawel@gmail.com>
Co-authored-by: Ben Halpern <bendhalpern@gmail.com>
2020-08-31 18:12:22 -04:00

44 lines
1.3 KiB
Ruby

class RegistrationsController < Devise::RegistrationsController
prepend_before_action :require_no_authentication, only: []
def new
@registered_users_count = User.registered.estimated_count
if user_signed_in?
redirect_to root_path(signin: "true")
else
if URI(request.referer || "").host == URI(request.base_url).host
store_location_for(:user, request.referer)
end
super
end
end
def create
not_authorized unless SiteConfig.allow_email_password_registration || SiteConfig.waiting_on_first_user
not_authorized if SiteConfig.waiting_on_first_user && ENV["FOREM_OWNER_SECRET"].present? &&
ENV["FOREM_OWNER_SECRET"] != params[:user][:forem_owner_secret]
build_resource(sign_up_params)
resource.saw_onboarding = false
resource.editor_version = "v2"
resource.save if resource.email.present?
yield resource if block_given?
if resource.persisted?
update_first_user_permissions(resource)
redirect_to "/confirm-email?email=#{resource.email}"
else
render action: "by_email"
end
end
private
def update_first_user_permissions(resource)
return unless SiteConfig.waiting_on_first_user
resource.add_role(:super_admin)
resource.add_role(:single_resource_admin, Config)
SiteConfig.waiting_on_first_user = false
end
end