-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #91 from Freika/disable-registration
Disable registration and implement user creation in the settings page
- Loading branch information
Showing
19 changed files
with
156 additions
and
39 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
0.8.0 | ||
0.8.1 |
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
Large diffs are not rendered by default.
Oops, something went wrong.
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,32 @@ | ||
# frozen_string_literal: true | ||
|
||
class Settings::UsersController < ApplicationController | ||
before_action :authenticate_user! | ||
before_action :authenticate_first_user! | ||
|
||
def create | ||
@user = User.new( | ||
email: user_params[:email], | ||
password: 'password', | ||
password_confirmation: 'password' | ||
) | ||
|
||
if @user.save | ||
redirect_to settings_url, notice: "User was successfully created, email is #{@user.email}, password is \"password\"." | ||
else | ||
redirect_to settings_url, notice: 'User could not be created.', status: :unprocessable_entity | ||
end | ||
end | ||
|
||
private | ||
|
||
def user_params | ||
params.require(:user).permit(:email) | ||
end | ||
|
||
def authenticate_first_user! | ||
return if current_user == User.first | ||
|
||
redirect_to settings_users_url, notice: 'You are not authorized to perform this action.', status: :unauthorized | ||
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
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
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
9 changes: 9 additions & 0 deletions
9
db/migrate/20240630093005_add_fog_of_war_to_default_settings.rb
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,9 @@ | ||
# frozen_string_literal: true | ||
|
||
class AddFogOfWarToDefaultSettings < ActiveRecord::Migration[7.1] | ||
def change | ||
change_column_default :users, :settings, | ||
from: { meters_between_routes: '1000', minutes_between_routes: '60' }, | ||
to: { fog_of_war_meters: '100', meters_between_routes: '1000', minutes_between_routes: '60' } | ||
end | ||
end |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,11 @@ | ||
# frozen_string_literal: true | ||
|
||
return if User.any? | ||
|
||
User.create!( | ||
email: 'user@domain.com', | ||
password: 'password', | ||
password_confirmation: 'password' | ||
) | ||
|
||
puts "User created: #{User.first.email} / password: 'password'" |
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
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,44 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
|
||
RSpec.describe '/settings/users', type: :request do | ||
before do | ||
sign_in create(:user) | ||
end | ||
|
||
describe 'POST /create' do | ||
context 'with valid parameters' do | ||
let(:valid_attributes) { { email: 'user@domain.com' } } | ||
|
||
it 'creates a new User' do | ||
expect do | ||
post settings_users_url, params: { user: valid_attributes } | ||
end.to change(User, :count).by(1) | ||
end | ||
|
||
it 'redirects to the created settings_user' do | ||
post settings_users_url, params: { user: valid_attributes } | ||
|
||
expect(response).to redirect_to(settings_url) | ||
expect(flash[:notice]).to eq("User was successfully created, email is #{valid_attributes[:email]}, password is \"password\".") | ||
end | ||
end | ||
|
||
context 'with invalid parameters' do | ||
let(:invalid_attributes) { { email: nil } } | ||
|
||
it 'does not create a new User' do | ||
expect do | ||
post settings_users_url, params: { user: invalid_attributes } | ||
end.to change(User, :count).by(0) | ||
end | ||
|
||
it 'renders a response with 422 status (i.e. to display the "new" template)' do | ||
post settings_users_url, params: { user: invalid_attributes } | ||
|
||
expect(response).to have_http_status(:unprocessable_entity) | ||
end | ||
end | ||
end | ||
end |