Skip to content

armgit / maybe

Public Imported from GitHub
0

The personal finance app for everyone

Centralize auth (#598)

Zach Gollwitzer0a0289846eb4
diff --git a/app/controllers/accounts_controller.rb b/app/controllers/accounts_controller.rb
index 0a533420..314f9722 100644
--- a/app/controllers/accounts_controller.rb
+++ b/app/controllers/accounts_controller.rb
@@ -1,6 +1,5 @@
class AccountsController < ApplicationController
include Filterable
- before_action :authenticate_user!
before_action :set_account, only: %i[ show update destroy sync ]
def new
diff --git a/app/controllers/concerns/authentication.rb b/app/controllers/concerns/authentication.rb
index 3fddee29..51ebafe6 100644
--- a/app/controllers/concerns/authentication.rb
+++ b/app/controllers/concerns/authentication.rb
@@ -2,7 +2,13 @@ module Authentication
extend ActiveSupport::Concern
included do
- helper_method :user_signed_in?
+ before_action :authenticate_user!
+ end
+
+ class_methods do
+ def skip_authentication(**options)
+ skip_before_action :authenticate_user!, **options
+ end
end
private
@@ -15,10 +21,6 @@ module Authentication
end
end
- def user_signed_in?
- Current.user.present?
- end
-
def login(user)
Current.user = user
reset_session
diff --git a/app/controllers/pages_controller.rb b/app/controllers/pages_controller.rb
index 92754f5b..7c10feb5 100644
--- a/app/controllers/pages_controller.rb
+++ b/app/controllers/pages_controller.rb
@@ -1,6 +1,5 @@
class PagesController < ApplicationController
include Filterable
- before_action :authenticate_user!
def dashboard
snapshot = Current.family.snapshot(@period)
diff --git a/app/controllers/password_resets_controller.rb b/app/controllers/password_resets_controller.rb
index b32811d2..7b8b7091 100644
--- a/app/controllers/password_resets_controller.rb
+++ b/app/controllers/password_resets_controller.rb
@@ -1,4 +1,6 @@
class PasswordResetsController < ApplicationController
+ skip_authentication
+
layout "auth"
before_action :set_user_by_token, only: :update
diff --git a/app/controllers/passwords_controller.rb b/app/controllers/passwords_controller.rb
index 56b24b60..eac86a07 100644
--- a/app/controllers/passwords_controller.rb
+++ b/app/controllers/passwords_controller.rb
@@ -1,6 +1,4 @@
class PasswordsController < ApplicationController
- before_action :authenticate_user!
-
def edit
end
diff --git a/app/controllers/registrations_controller.rb b/app/controllers/registrations_controller.rb
index 40d13f16..f8e84f4b 100644
--- a/app/controllers/registrations_controller.rb
+++ b/app/controllers/registrations_controller.rb
@@ -1,4 +1,6 @@
class RegistrationsController < ApplicationController
+ skip_authentication
+
layout "auth"
before_action :set_user, only: :create
diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb
index 4bf52314..9f546b98 100644
--- a/app/controllers/sessions_controller.rb
+++ b/app/controllers/sessions_controller.rb
@@ -1,4 +1,6 @@
class SessionsController < ApplicationController
+ skip_authentication only: %i[new create]
+
layout "auth"
def new
diff --git a/app/controllers/settings_controller.rb b/app/controllers/settings_controller.rb
index be273f7b..b990f90b 100644
--- a/app/controllers/settings_controller.rb
+++ b/app/controllers/settings_controller.rb
@@ -1,6 +1,4 @@
class SettingsController < ApplicationController
- before_action :authenticate_user!
-
def edit
end
diff --git a/app/controllers/transactions_controller.rb b/app/controllers/transactions_controller.rb
index 9a9b62c0..99ff1ca8 100644
--- a/app/controllers/transactions_controller.rb
+++ b/app/controllers/transactions_controller.rb
@@ -1,5 +1,4 @@
class TransactionsController < ApplicationController
- before_action :authenticate_user!
before_action :set_transaction, only: %i[ show edit update destroy ]
def index
diff --git a/app/controllers/valuations_controller.rb b/app/controllers/valuations_controller.rb
index bc1dd052..71b72f35 100644
--- a/app/controllers/valuations_controller.rb
+++ b/app/controllers/valuations_controller.rb
@@ -1,6 +1,4 @@
class ValuationsController < ApplicationController
- before_action :authenticate_user!
-
def create
@account = Current.family.accounts.find(params[:account_id])