Skip to content

Commit

Permalink
Created Client::BaseController to hide layout and logged_in filters
Browse files Browse the repository at this point in the history
This way increasing the chances of forgetting to ensure logging in.
  • Loading branch information
andrzejkrzywda committed Jan 7, 2024
1 parent afb025f commit 252f99e
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 16 deletions.
16 changes: 16 additions & 0 deletions rails_application/app/controllers/client/base_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module Client
class BaseController < ApplicationController

layout "client_panel"
before_action :ensure_logged_in

private

def ensure_logged_in
if ClientOrders::Client.find_by(uid: cookies[:client_id]).nil?
redirect_to logout_path
return
end
end
end
end
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module Client
class ClientsController < ApplicationController
layout "client_panel"
class ClientsController < BaseController

skip_before_action :ensure_logged_in, only: [:index, :login, :logout]

def index
if cookies[:client_id]
Expand Down Expand Up @@ -31,6 +32,7 @@ def logout
redirect_to clients_path
end

private

def correct_password?(client_id, password)
password_hash = Digest::SHA256.hexdigest(password)
Expand Down
13 changes: 1 addition & 12 deletions rails_application/app/controllers/client/orders_controller.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,5 @@
module Client
class OrdersController < ApplicationController

layout 'client_panel'

before_action :ensure_logged_in

def ensure_logged_in
if ClientOrders::Client.find_by(uid: cookies[:client_id]).nil?
redirect_to logout_path
return
end
end
class OrdersController < BaseController

def index
render html: ClientOrders::OrdersList.build(view_context, cookies[:client_id]), layout: true
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
module Client
class ProductsController < ApplicationController
layout 'client_panel'
class ProductsController < BaseController

def index
render html: PublicOffer::ProductsList.build(view_context), layout: true
Expand Down

0 comments on commit 252f99e

Please sign in to comment.