-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Disable account signup depending on Settings variable
When account creation is disabled, redirect to the homepage with an alert. When enabled, let Devise do its thing. This implementation relies on a small routing change that lets Hyku override two methods in `Devise::RegistrationsController`. Fixes #1203
- Loading branch information
Showing
9 changed files
with
83 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module Hyku | ||
class RegistrationsController < Devise::RegistrationsController | ||
def new | ||
return super if Settings.devise.account_signup | ||
flash[:alert] = t(:'hyku.account_signup') | ||
redirect_to root_path | ||
end | ||
|
||
def create | ||
return super if Settings.devise.account_signup | ||
flash[:alert] = t(:'hyku.account_signup') | ||
redirect_to root_path | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,6 +50,7 @@ zh: | |
proprietor: | ||
accounts: | ||
nav: '帐号' | ||
account_signup: '帐户注册被禁用' | ||
admin: | ||
title: '行政' | ||
flash: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,3 +56,6 @@ google_analytics_id: | |
geonames_username: 'jcoyne' | ||
|
||
contact_email: "" | ||
|
||
devise: | ||
account_signup: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
RSpec.describe Hyku::RegistrationsController do | ||
before do | ||
allow(Settings.devise).to receive(:account_signup).and_return(account_signup_enabled) | ||
# Recommended by Devise: https://github.com/plataformatec/devise/wiki/How-To:-Test-controllers-with-Rails-3-and-4-%28and-RSpec%29 | ||
@request.env['devise.mapping'] = Devise.mappings[:user] | ||
end | ||
|
||
context 'with account signup enabled' do | ||
let(:account_signup_enabled) { true } | ||
describe '#new' do | ||
it 'renders the form' do | ||
get :new | ||
expect(response).to render_template('devise/registrations/new') | ||
end | ||
end | ||
describe '#create' do | ||
it 'processes the form' do | ||
post :create, params: { | ||
user: { | ||
email: "user@example.org", | ||
password: "password", | ||
password_confirmation: "password" | ||
} | ||
} | ||
expect(response).to redirect_to dashboard_path(locale: 'en') | ||
expect(flash[:notice]).to eq 'Welcome! You have signed up successfully.' | ||
end | ||
end | ||
end | ||
context 'with account signup disabled' do | ||
let(:account_signup_enabled) { false } | ||
describe '#new' do | ||
it 'redirects with a flash message' do | ||
get :new | ||
expect(response).to redirect_to root_path | ||
expect(flash[:alert]).to eq 'Account registration is disabled' | ||
end | ||
end | ||
describe '#create' do | ||
it 'redirects with a flash message' do | ||
post :create | ||
expect(response).to redirect_to root_path | ||
expect(flash[:alert]).to eq 'Account registration is disabled' | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
RSpec.describe Hyku::RegistrationsController, type: :routing do | ||
describe "routing" do | ||
it "routes to #new" do | ||
expect(get: "/users/sign_up").to route_to("hyku/registrations#new") | ||
end | ||
it "routes to #edit" do | ||
expect(get: "/users/edit").to route_to("hyku/registrations#edit") | ||
end | ||
end | ||
end |