Add ability to disable registrations

This commit is contained in:
Andreas Nedbal 2024-08-09 05:53:37 +02:00 committed by Andreas Nedbal
parent 2001921163
commit 6cc8ebcba3
7 changed files with 60 additions and 33 deletions

View File

@ -1,4 +1,8 @@
# frozen_string_literal: true
class User::RegistrationsController < Devise::RegistrationsController
before_action :redirect_if_registrations_disabled!, only: %w[create new]
def create
if captcha_valid?
super
@ -29,4 +33,8 @@ class User::RegistrationsController < Devise::RegistrationsController
verify_hcaptcha
end
def redirect_if_registrations_disabled!
redirect_to root_path unless APP_CONFIG.dig(:features, :registration, :enabled)
end
end

View File

@ -5,12 +5,18 @@
= render "layouts/messages"
%h1= APP_CONFIG["site_name"]
%p= t(".subtitle")
- if APP_CONFIG.dig(:features, :registration, :enabled)
%p
%a.btn.btn-outline-light.btn-lg{ href: url_for(new_user_registration_path) }
= t(".register")
%small
= t(".already_member")
= 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
.col-sm-6.order-5.order-sm-1.text-center.text-sm-right
%h2.mb-4= t(".questions.header")
@ -77,6 +83,7 @@
= t(".your_data.header")
%p= t(".your_data.body", app_name: APP_CONFIG["site_name"])
- if APP_CONFIG.dig(:features, :registration, :enabled)
.card
.card-body
%h2= t(".prompt.header")

View File

@ -40,10 +40,11 @@
%input{ name: "qb-to", type: "hidden", value: user.id }/
%button.btn.btn-primary{ name: "qb-ask",
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
- unless user_signed_in?
- if user.privacy_allow_anonymous_questions?
- if APP_CONFIG.dig(:features, :registration, :enabled)
.d-none#question-box-promote
.row
.col-12.text-center
@ -60,4 +61,8 @@
%small= t(".promote.join", app_title: APP_CONFIG["site_name"])
- else
.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))
- else
%strong= t(".status.non_anonymous_no_registration_html", sign_in: link_to(t("voc.login"), new_user_session_path))

View File

@ -14,4 +14,5 @@
.collapse.navbar-collapse#j2-main-navbar-collapse
%ul.nav.navbar-nav.ms-auto
= 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

View File

@ -52,6 +52,9 @@ features:
# Public timeline
public:
enabled: true
# Registrations
registration:
enabled: true
# Redis
redis_url: "redis://localhost:6379"

View File

@ -146,6 +146,9 @@ en:
non_anonymous_html: |
This user does not want to receive anonymous questions. <br/>
(%{sign_in} or %{sign_up})
non_anonymous_no_registration_html: |
This user does not want to receive anonymous questions. <br/>
(%{sign_in})
comment:
show_reactions:
title: "People who smiled this comment"

View File

@ -63,7 +63,7 @@ Rails.application.routes.draw do
# :registrations
get "settings/delete_account" => "devise/registrations#cancel", :as => :cancel_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
patch "/settings/account" => "devise/registrations#update", :as => :update_user_registration
put "/settings/account" => "devise/registrations#update"