Skip to content

Commit

Permalink
New option to disable signups (#422)
Browse files Browse the repository at this point in the history
* New option to disable signups

* Add option to Configuration docs
  • Loading branch information
pglombardo authored Oct 10, 2022
1 parent 85ba2f6 commit 41a771b
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 5 deletions.
1 change: 1 addition & 0 deletions Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ _All_ of the following environments need to be set (except SMTP authentication i
| PWP__HOST_DOMAIN | Used to build fully qualified URLs in emails. Where is your instance hosted? | `pwpush.com` |
| PWP__HOST_PROTOCOL | The protocol to access your Password Pusher instance. HTTPS advised. | `https` |
| PWP__MAIL__MAILER_SENDER | This is the "From" address in sent emails. | '"Company Name" <[email protected]>' |
| PWP__DISABLE_SIGNUPS| Once your user accounts are created, you can set this disable any further user account creation. Sign up links and related backend functionality is disabled when `true`. | `false` |

## Shell Example

Expand Down
2 changes: 1 addition & 1 deletion app/views/devise/shared/_links.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<%= link_to I18n.t('devise.general.login'), new_session_path(resource_name), class: 'nav-link px-2 text-muted' %>
</li>
<% end %>
<%- if devise_mapping.registerable? && controller_name != 'registrations' %>
<%- if devise_mapping.registerable? && controller_name != 'registrations' && !Settings.disable_signups %>
<li class="list-group-item list-group-item-action">
<%= link_to I18n.t('devise.general.sign_up'), new_registration_path(resource_name), class: 'nav-link px-2 text-muted' %>
</li>
Expand Down
8 changes: 5 additions & 3 deletions app/views/shared/_header.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,11 @@
<li class="nav-item">
<%= link_to _('Log In'), new_user_session_path, class: "nav-link lead" %>
</li>
<li class="nav-item">
<%= link_to _('Sign Up'), new_user_registration_path, class: "nav-link lead" %>
</li>
<% if !Settings.disable_signups %>
<li class="nav-item">
<%= link_to _('Sign Up'), new_user_registration_path, class: "nav-link lead" %>
</li>
<% end %>
<% end %>
<% end %>
<li class="nav-item dropdown">
Expand Down
8 changes: 7 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,15 @@
confirmations: 'users/confirmations'
}

if Settings.disable_signups
allowed_reg_routes = %i[edit update]
else
allowed_reg_routes = %i[new create edit update]
end

devise_scope :user do
resource :registration,
only: %i[new create edit update],
only: allowed_reg_routes,
path: 'users',
path_names: { new: 'sign_up' },
controller: 'users/registrations',
Expand Down
12 changes: 12 additions & 0 deletions config/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,18 @@ brand:
#
enable_logins: false

## Disable Signups
#
# Disallow new user accounts to be created in the application.
#
# Set this after you have your desired user accounts created. It will
# not allow any further user account creation.
#
# Environment variable override:
# PWP__DISABLE_SIGNUPS='false'
#
disable_signups: false

### Allow Anonymous
#
# By default, Password Pusher can be used by anonymous users to push
Expand Down

0 comments on commit 41a771b

Please sign in to comment.