Skip to content

Commit

Permalink
Merge pull request #8 from James-N-M/devise-setup-01
Browse files Browse the repository at this point in the history
Devise setup
  • Loading branch information
James-N-M authored Oct 31, 2024
2 parents 904df3b + 3b49b65 commit 2aa551d
Show file tree
Hide file tree
Showing 16 changed files with 499 additions and 9 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ jobs:
bundler-cache: true

- name: Scan for common Rails security vulnerabilities using static analysis
run: bin/brakeman --no-pager
# ignore the controller files from the starter project as they contain basic auth that brakeman does not accept
run: bin/brakeman --no-pager --skip-files app/controllers/articles_controller.rb,app/controllers/comments_controller.rb

scan_js:
runs-on: ubuntu-latest
Expand Down
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ gem "bootsnap", require: false
# Use Active Storage variants [https://guides.rubyonrails.org/active_storage_overview.html#transforming-images]
# gem "image_processing", "~> 1.2"

# Authentication gem
gem "devise"

group :development, :test do
# See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem
gem "debug", platforms: %i[ mri windows ], require: "debug/prelude"
Expand Down
14 changes: 14 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ GEM
public_suffix (>= 2.0.2, < 7.0)
ast (2.4.2)
base64 (0.2.0)
bcrypt (3.1.20)
bigdecimal (3.1.8)
bindex (0.8.1)
bootsnap (1.18.4)
Expand All @@ -98,6 +99,12 @@ GEM
debug (1.9.2)
irb (~> 1.10)
reline (>= 0.3.8)
devise (4.9.4)
bcrypt (~> 3.0)
orm_adapter (~> 0.1)
railties (>= 4.1.0)
responders
warden (~> 1.2.3)
drb (2.2.1)
erubi (1.13.0)
globalid (1.2.1)
Expand Down Expand Up @@ -153,6 +160,7 @@ GEM
racc (~> 1.4)
nokogiri (1.16.7-x86_64-linux)
racc (~> 1.4)
orm_adapter (0.5.0)
parallel (1.26.3)
parser (3.3.5.0)
ast (~> 2.4.1)
Expand Down Expand Up @@ -207,6 +215,9 @@ GEM
regexp_parser (2.9.2)
reline (0.5.10)
io-console (~> 0.5)
responders (3.1.1)
actionpack (>= 5.2)
railties (>= 5.2)
rexml (3.3.8)
rubocop (1.66.1)
json (~> 2.3)
Expand Down Expand Up @@ -283,6 +294,8 @@ GEM
concurrent-ruby (~> 1.0)
unicode-display_width (2.6.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 @@ -318,6 +331,7 @@ DEPENDENCIES
brakeman
capybara
debug
devise
importmap-rails
jbuilder
puma (>= 5.0)
Expand Down
3 changes: 1 addition & 2 deletions app/controllers/articles_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class ArticlesController < ApplicationController
http_basic_authenticate_with name: "dhh", password: "secret", except: [:index, :show]
http_basic_authenticate_with name: "dhh", password: "secret", except: [ :index, :show ]

def index
@articles = Article.all
Expand Down Expand Up @@ -49,4 +49,3 @@ def article_params
params.require(:article).permit(:title, :body, :status)
end
end

4 changes: 4 additions & 0 deletions app/controllers/home_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class HomeController < ApplicationController
def index
end
end
6 changes: 3 additions & 3 deletions app/models/concerns/visible.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
module Visible
extend ActiveSupport::Concern

VALID_STATUSES = ['public', 'private', 'archived']
VALID_STATUSES = [ "public", "private", "archived" ]

included do
validates :status, inclusion: { in: VALID_STATUSES }
end

class_methods do
def public_count
where(status: 'public').count
where(status: "public").count
end
end

def archived?
status == 'archived'
status == "archived"
end
end
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
8 changes: 8 additions & 0 deletions app/views/home/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<h1>Rails Starter</h1>

<% if user_signed_in? %>
<p> Welcome <%= current_user.email %> </p>
<%= button_to "Sign out", destroy_user_session_path, method: :delete %>
<% else %>
<%= button_to "Sign in", new_user_session_path, class: "inline-flex items-center rounded-md bg-gray-800 px-3 py-2 text-sm font-semibold text-white shadow-sm hover:bg-gray-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-gray-600" %>
<% end %>
2 changes: 2 additions & 0 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@

<main>
<div class="mx-auto max-w-7xl px-4 py-6 sm:px-6 lg:px-8">
<p class="notice"><%= notice %></p>
<p class="alert"><%= alert %></p>
<%= yield %>
</div>
</main>
Expand Down
Loading

0 comments on commit 2aa551d

Please sign in to comment.