Added users support

This commit is contained in:
2025-08-19 07:24:18 +02:00
parent 541b181c87
commit 20b62e7312
18 changed files with 592 additions and 35 deletions

View File

@@ -1,5 +1,6 @@
class ApplicationController < ActionController::Base
before_action :set_locale
before_action :require_login
private
@@ -8,27 +9,37 @@ class ApplicationController < ActionController::Base
session[:locale] = I18n.locale
end
# Optional: Make locale persist across requests via URL helpers
def default_url_options
{ locale: I18n.locale }
end
def set_company
# This should be handled by your authentication system
# But for now, we'll use a placeholder
company_id = session[:company_id]
unless company_id && Company.exists?(company_id)
# If no company in session or it doesn't exist, use the first company
company_id = Company.first&.id
session[:company_id] = company_id
end
@company = Company.find(company_id) if company_id
def current_user
@current_user ||= User.find(session[:user_id]) if session[:user_id]
end
def logged_in?
!!current_user
end
def require_login
return if logged_in?
flash[:alert] = t('sessions.login_required')
redirect_to login_path
end
def set_company
return unless logged_in?
@company = current_user.company
return if @company
redirect_to companies_path, alert: 'No company found. Please create a company first.'
end
def current_company
@company
end
helper_method :current_company
helper_method :current_user, :logged_in?, :current_company
end