1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-07-26 00:29:40 +02:00

Opt-in to Current fully (#297)

This commit is contained in:
Dwight Watson 2024-02-05 10:36:46 +11:00 committed by GitHub
parent 23eaa3e066
commit d61a22b070
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 24 additions and 23 deletions

View file

@ -17,7 +17,7 @@ class AccountsController < ApplicationController
end
def create
@account = Account.new(account_params.merge(family: current_family))
@account = Account.new(account_params.merge(family: Current.family))
@account.accountable = account_params[:accountable_type].constantize.new
if @account.save

View file

@ -2,31 +2,21 @@ module Authentication
extend ActiveSupport::Concern
included do
helper_method :current_user
helper_method :current_family
helper_method :user_signed_in?
end
private
def authenticate_user!
redirect_to new_session_path unless user_signed_in?
end
def current_user
Current.user || authenticate_user_from_session
end
def current_family
current_user.family
end
def authenticate_user_from_session
User.find_by(id: session[:user_id])
if user = User.find_by(id: session[:user_id])
Current.user = user
else
redirect_to new_session_url
end
end
def user_signed_in?
current_user.present?
Current.user.present?
end
def login(user)

View file

@ -5,7 +5,7 @@ class PasswordsController < ApplicationController
end
def update
if current_user.update(password_params)
if Current.user.update(password_params)
redirect_to root_path, notice: t(".success")
else
render :edit, status: :unprocessable_entity