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
|
||||
before_action :redirect_if_registrations_disabled!, only: %w[create new]
|
||||
|
||||
def create
|
||||
if captcha_valid?
|
||||
super
|
||||
else
|
||||
respond_with_navigational(resource){ redirect_to new_user_registration_path }
|
||||
respond_with_navigational(resource) { redirect_to new_user_registration_path }
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -18,7 +22,7 @@ class User::RegistrationsController < Devise::RegistrationsController
|
|||
resource.destroy
|
||||
set_flash_message :notice, :destroyed if is_flashing_format?
|
||||
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
|
||||
|
||||
private
|
||||
|
@ -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
|
||||
|
|
|
@ -5,12 +5,18 @@
|
|||
= render "layouts/messages"
|
||||
%h1= APP_CONFIG["site_name"]
|
||||
%p= t(".subtitle")
|
||||
%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
|
||||
- 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,12 +83,13 @@
|
|||
= t(".your_data.header")
|
||||
%p= t(".your_data.body", app_name: APP_CONFIG["site_name"])
|
||||
|
||||
.card
|
||||
.card-body
|
||||
%h2= t(".prompt.header")
|
||||
%p= t(".prompt.body")
|
||||
%p
|
||||
%a.btn.btn-primary.btn-lg{ href: url_for(new_user_registration_path) }
|
||||
= t(".register")
|
||||
- if APP_CONFIG.dig(:features, :registration, :enabled)
|
||||
.card
|
||||
.card-body
|
||||
%h2= t(".prompt.header")
|
||||
%p= t(".prompt.body")
|
||||
%p
|
||||
%a.btn.btn-primary.btn-lg{ href: url_for(new_user_registration_path) }
|
||||
= t(".register")
|
||||
|
||||
= render "shared/links"
|
||||
|
|
|
@ -40,24 +40,29 @@
|
|||
%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?
|
||||
.d-none#question-box-promote
|
||||
.row
|
||||
.col-12.text-center
|
||||
%strong= t(".promote.message")
|
||||
.row
|
||||
.col-sm-5.offset-sm-1
|
||||
.d-grid
|
||||
%button.btn.btn-primary#create-account= t(".promote.create")
|
||||
.col-sm-5
|
||||
.d-grid
|
||||
%button.btn.btn-default#new-question= t(".promote.another")
|
||||
.row
|
||||
.col-xs-12.col-sm-10.offset-sm-1.text-center
|
||||
%small= t(".promote.join", app_title: APP_CONFIG["site_name"])
|
||||
- if APP_CONFIG.dig(:features, :registration, :enabled)
|
||||
.d-none#question-box-promote
|
||||
.row
|
||||
.col-12.text-center
|
||||
%strong= t(".promote.message")
|
||||
.row
|
||||
.col-sm-5.offset-sm-1
|
||||
.d-grid
|
||||
%button.btn.btn-primary#create-account= t(".promote.create")
|
||||
.col-sm-5
|
||||
.d-grid
|
||||
%button.btn.btn-default#new-question= t(".promote.another")
|
||||
.row
|
||||
.col-xs-12.col-sm-10.offset-sm-1.text-center
|
||||
%small= t(".promote.join", app_title: APP_CONFIG["site_name"])
|
||||
- else
|
||||
.text-center
|
||||
%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))
|
||||
- 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))
|
||||
|
||||
|
|
|
@ -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
|
||||
= nav_entry t("voc.register"), new_user_registration_path
|
||||
- if APP_CONFIG.dig(:features, :registration, :enabled)
|
||||
= nav_entry t("voc.register"), new_user_registration_path
|
||||
|
|
|
@ -52,6 +52,9 @@ features:
|
|||
# Public timeline
|
||||
public:
|
||||
enabled: true
|
||||
# Registrations
|
||||
registration:
|
||||
enabled: true
|
||||
|
||||
# Redis
|
||||
redis_url: "redis://localhost:6379"
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Reference in New Issue