Add ability to disable registrations
This commit is contained in:
parent
2001921163
commit
6cc8ebcba3
|
@ -1,9 +1,13 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class User::RegistrationsController < Devise::RegistrationsController
|
class User::RegistrationsController < Devise::RegistrationsController
|
||||||
|
before_action :redirect_if_registrations_disabled!, only: %w[create new]
|
||||||
|
|
||||||
def create
|
def create
|
||||||
if captcha_valid?
|
if captcha_valid?
|
||||||
super
|
super
|
||||||
else
|
else
|
||||||
respond_with_navigational(resource){ redirect_to new_user_registration_path }
|
respond_with_navigational(resource) { redirect_to new_user_registration_path }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -18,7 +22,7 @@ class User::RegistrationsController < Devise::RegistrationsController
|
||||||
resource.destroy
|
resource.destroy
|
||||||
set_flash_message :notice, :destroyed if is_flashing_format?
|
set_flash_message :notice, :destroyed if is_flashing_format?
|
||||||
yield resource if block_given?
|
yield resource if block_given?
|
||||||
respond_with_navigational(resource){ redirect_to after_sign_out_path_for(resource_name) }
|
respond_with_navigational(resource) { redirect_to after_sign_out_path_for(resource_name) }
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
@ -29,4 +33,8 @@ class User::RegistrationsController < Devise::RegistrationsController
|
||||||
|
|
||||||
verify_hcaptcha
|
verify_hcaptcha
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def redirect_if_registrations_disabled!
|
||||||
|
redirect_to root_path unless APP_CONFIG.dig(:features, :registration, :enabled)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -5,12 +5,18 @@
|
||||||
= render "layouts/messages"
|
= render "layouts/messages"
|
||||||
%h1= APP_CONFIG["site_name"]
|
%h1= APP_CONFIG["site_name"]
|
||||||
%p= t(".subtitle")
|
%p= t(".subtitle")
|
||||||
|
- if APP_CONFIG.dig(:features, :registration, :enabled)
|
||||||
%p
|
%p
|
||||||
%a.btn.btn-outline-light.btn-lg{ href: url_for(new_user_registration_path) }
|
%a.btn.btn-outline-light.btn-lg{ href: url_for(new_user_registration_path) }
|
||||||
= t(".register")
|
= t(".register")
|
||||||
%small
|
%small
|
||||||
= t(".already_member")
|
= t(".already_member")
|
||||||
= link_to t("voc.login"), new_user_session_path
|
= link_to t("voc.login"), new_user_session_path
|
||||||
|
- else
|
||||||
|
%p
|
||||||
|
%a.btn.btn-outline-light.btn-lg{ href: url_for(new_user_session_path) }
|
||||||
|
= t("voc.login")
|
||||||
|
|
||||||
.row.my-5.my-sm-10
|
.row.my-5.my-sm-10
|
||||||
.col-sm-6.order-5.order-sm-1.text-center.text-sm-right
|
.col-sm-6.order-5.order-sm-1.text-center.text-sm-right
|
||||||
%h2.mb-4= t(".questions.header")
|
%h2.mb-4= t(".questions.header")
|
||||||
|
@ -77,6 +83,7 @@
|
||||||
= t(".your_data.header")
|
= t(".your_data.header")
|
||||||
%p= t(".your_data.body", app_name: APP_CONFIG["site_name"])
|
%p= t(".your_data.body", app_name: APP_CONFIG["site_name"])
|
||||||
|
|
||||||
|
- if APP_CONFIG.dig(:features, :registration, :enabled)
|
||||||
.card
|
.card
|
||||||
.card-body
|
.card-body
|
||||||
%h2= t(".prompt.header")
|
%h2= t(".prompt.header")
|
||||||
|
|
|
@ -40,10 +40,11 @@
|
||||||
%input{ name: "qb-to", type: "hidden", value: user.id }/
|
%input{ name: "qb-to", type: "hidden", value: user.id }/
|
||||||
%button.btn.btn-primary{ name: "qb-ask",
|
%button.btn.btn-primary{ name: "qb-ask",
|
||||||
type: :button,
|
type: :button,
|
||||||
data: { loading_text: t(".load"), promote: user_signed_in? ? "false" : "true", "character-count-target": "action" } }
|
data: { loading_text: t(".load"), promote: user_signed_in? || !user_signed_in? && !APP_CONFIG.dig(:features, :registration, :enabled) ? "false" : "true", "character-count-target": "action" } }
|
||||||
Ask
|
Ask
|
||||||
- unless user_signed_in?
|
- unless user_signed_in?
|
||||||
- if user.privacy_allow_anonymous_questions?
|
- if user.privacy_allow_anonymous_questions?
|
||||||
|
- if APP_CONFIG.dig(:features, :registration, :enabled)
|
||||||
.d-none#question-box-promote
|
.d-none#question-box-promote
|
||||||
.row
|
.row
|
||||||
.col-12.text-center
|
.col-12.text-center
|
||||||
|
@ -60,4 +61,8 @@
|
||||||
%small= t(".promote.join", app_title: APP_CONFIG["site_name"])
|
%small= t(".promote.join", app_title: APP_CONFIG["site_name"])
|
||||||
- else
|
- else
|
||||||
.text-center
|
.text-center
|
||||||
|
- if APP_CONFIG.dig(:features, :registration, :enabled)
|
||||||
%strong= t(".status.non_anonymous_html", sign_in: link_to(t("voc.login"), new_user_session_path), sign_up: link_to(t("voc.register"), new_user_registration_path))
|
%strong= t(".status.non_anonymous_html", sign_in: link_to(t("voc.login"), new_user_session_path), sign_up: link_to(t("voc.register"), new_user_registration_path))
|
||||||
|
- else
|
||||||
|
%strong= t(".status.non_anonymous_no_registration_html", sign_in: link_to(t("voc.login"), new_user_session_path))
|
||||||
|
|
||||||
|
|
|
@ -14,4 +14,5 @@
|
||||||
.collapse.navbar-collapse#j2-main-navbar-collapse
|
.collapse.navbar-collapse#j2-main-navbar-collapse
|
||||||
%ul.nav.navbar-nav.ms-auto
|
%ul.nav.navbar-nav.ms-auto
|
||||||
= nav_entry t("voc.login"), new_user_session_path
|
= nav_entry t("voc.login"), new_user_session_path
|
||||||
|
- if APP_CONFIG.dig(:features, :registration, :enabled)
|
||||||
= nav_entry t("voc.register"), new_user_registration_path
|
= nav_entry t("voc.register"), new_user_registration_path
|
||||||
|
|
|
@ -52,6 +52,9 @@ features:
|
||||||
# Public timeline
|
# Public timeline
|
||||||
public:
|
public:
|
||||||
enabled: true
|
enabled: true
|
||||||
|
# Registrations
|
||||||
|
registration:
|
||||||
|
enabled: true
|
||||||
|
|
||||||
# Redis
|
# Redis
|
||||||
redis_url: "redis://localhost:6379"
|
redis_url: "redis://localhost:6379"
|
||||||
|
|
|
@ -146,6 +146,9 @@ en:
|
||||||
non_anonymous_html: |
|
non_anonymous_html: |
|
||||||
This user does not want to receive anonymous questions. <br/>
|
This user does not want to receive anonymous questions. <br/>
|
||||||
(%{sign_in} or %{sign_up})
|
(%{sign_in} or %{sign_up})
|
||||||
|
non_anonymous_no_registration_html: |
|
||||||
|
This user does not want to receive anonymous questions. <br/>
|
||||||
|
(%{sign_in})
|
||||||
comment:
|
comment:
|
||||||
show_reactions:
|
show_reactions:
|
||||||
title: "People who smiled this comment"
|
title: "People who smiled this comment"
|
||||||
|
|
|
@ -63,7 +63,7 @@ Rails.application.routes.draw do
|
||||||
# :registrations
|
# :registrations
|
||||||
get "settings/delete_account" => "devise/registrations#cancel", :as => :cancel_user_registration
|
get "settings/delete_account" => "devise/registrations#cancel", :as => :cancel_user_registration
|
||||||
post "/user/create" => "user/registrations#create", :as => :user_registration
|
post "/user/create" => "user/registrations#create", :as => :user_registration
|
||||||
get "/sign_up" => "devise/registrations#new", :as => :new_user_registration
|
get "/sign_up" => "user/registrations#new", :as => :new_user_registration
|
||||||
get "/settings/account" => "devise/registrations#edit", :as => :edit_user_registration
|
get "/settings/account" => "devise/registrations#edit", :as => :edit_user_registration
|
||||||
patch "/settings/account" => "devise/registrations#update", :as => :update_user_registration
|
patch "/settings/account" => "devise/registrations#update", :as => :update_user_registration
|
||||||
put "/settings/account" => "devise/registrations#update"
|
put "/settings/account" => "devise/registrations#update"
|
||||||
|
|
Loading…
Reference in New Issue