Skip to content
This repository has been archived by the owner on Apr 3, 2024. It is now read-only.

Commit

Permalink
install devise, require auth to access admin, controller tests
Browse files Browse the repository at this point in the history
  • Loading branch information
yshmarov committed Mar 24, 2024
1 parent d80af66 commit a329139
Show file tree
Hide file tree
Showing 12 changed files with 497 additions and 5 deletions.
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,5 @@ group :test do
gem "capybara"
gem "selenium-webdriver"
end

gem "devise", "~> 4.9"
14 changes: 14 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ GEM
public_suffix (>= 2.0.2, < 6.0)
ast (2.4.2)
base64 (0.2.0)
bcrypt (3.1.20)
bigdecimal (3.1.7)
bindex (0.8.1)
bootsnap (1.18.3)
Expand All @@ -124,6 +125,12 @@ GEM
debug (1.9.1)
irb (~> 1.10)
reline (>= 0.3.8)
devise (4.9.3)
bcrypt (~> 3.0)
orm_adapter (~> 0.1)
railties (>= 4.1.0)
responders
warden (~> 1.2.3)
drb (2.2.1)
erubi (1.12.0)
globalid (1.2.1)
Expand Down Expand Up @@ -178,6 +185,7 @@ GEM
racc (~> 1.4)
nokogiri (1.16.3-x86_64-linux)
racc (~> 1.4)
orm_adapter (0.5.0)
parallel (1.24.0)
parser (3.3.0.5)
ast (~> 2.4.1)
Expand Down Expand Up @@ -220,6 +228,9 @@ GEM
regexp_parser (2.9.0)
reline (0.4.3)
io-console (~> 0.5)
responders (3.1.1)
actionpack (>= 5.2)
railties (>= 5.2)
rexml (3.2.6)
rubocop (1.62.1)
json (~> 2.3)
Expand Down Expand Up @@ -282,6 +293,8 @@ GEM
concurrent-ruby (~> 1.0)
unicode-display_width (2.5.0)
useragent (0.16.10)
warden (1.2.9)
rack (>= 2.0.9)
web-console (4.2.1)
actionview (>= 6.0.0)
activemodel (>= 6.0.0)
Expand Down Expand Up @@ -309,6 +322,7 @@ DEPENDENCIES
brakeman
capybara
debug
devise (~> 4.9)
importmap-rails
jbuilder
pg (~> 1.1)
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/home_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
class HomeController < ApplicationController
before_action :authenticate_user!, only: [:admin]

Check failure on line 2 in app/controllers/home_controller.rb

View workflow job for this annotation

GitHub Actions / lint

Layout/SpaceInsideArrayLiteralBrackets: Use space inside array brackets.

Check failure on line 2 in app/controllers/home_controller.rb

View workflow job for this annotation

GitHub Actions / lint

Layout/SpaceInsideArrayLiteralBrackets: Use space inside array brackets.

def index
end

Expand Down
6 changes: 6 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class User < ApplicationRecord
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :validatable
end
14 changes: 13 additions & 1 deletion app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,19 @@
</head>

<body>
<main class="container mx-auto mt-28 px-5 flex">
<%= link_to 'Home', root_path %>
<%= link_to 'Admin', admin_path %>
<% if signed_in? %>
<%= link_to current_user.email, edit_user_registration_path %>
<%= button_to "Log out", destroy_user_session_path, method: :delete, data: { turbo: "false" } %>
<% else %>
<%= link_to "Log in", new_user_session_path %>
<%= link_to "Register", new_user_registration_path %>
<% end %>
<hr>
<main class="p-8">
<p class="bg-green-500"><%= notice %></p>
<p class="bg-red-500"><%= alert %></p>
<%= yield %>
</main>
</body>
Expand Down
1 change: 1 addition & 0 deletions config/environments/development.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require "active_support/core_ext/integer/time"

Rails.application.configure do
config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }

Check failure on line 4 in config/environments/development.rb

View workflow job for this annotation

GitHub Actions / lint

Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
# Settings specified here will take precedence over those in config/application.rb.

# In the development environment your application's code is reloaded any time
Expand Down
Loading

0 comments on commit a329139

Please sign in to comment.