Add auth and ruby update

This commit is contained in:
david 2024-09-22 21:57:05 +02:00
parent 5d50194f39
commit fbf6923835
43 changed files with 614 additions and 64 deletions

View file

@ -4,6 +4,7 @@ class ApplicationController < ActionController::Base
include Pagy::Backend
# allow_browser versions: :modern
helper_method :sidebar?
before_action :initialize_navbar
@ -12,15 +13,26 @@ class ApplicationController < ActionController::Base
def initialize_navbar
return unless request.get?
@navbar_items = [
{ label: "Dashboard", icon: :speedometer2, path: :root },
{ label: Report.model_name.human(count: 2), icon: :'journal-text', path: :reports },
{ label: Checklist.model_name.human(count: 2), icon: :'list-check', path: :checklists },
{ label: Check.model_name.human(count: 2), icon: :check2, path: :checks },
{ label: Link.model_name.human(count: 2), icon: :link, path: :links },
{ label: LinkCategory.model_name.human(count: 2), icon: :folder, path: :link_categories }
]
@navbar_items = if rodauth.logged_in?
[
{ label: "Dashboard", icon: :speedometer2, path: :root },
{ label: Report.model_name.human(count: 2), icon: :'journal-text', path: :reports },
{ label: I18n.t("backoffice"), icon: :gear, path: :backoffice, active: %w[backoffice checklists checks links link_categories].include?(controller_name) },
{ label: Account.model_name.human, icon: :person, path: profile_path }
]
else
[ { label: "Login", icon: :'door-closed', path: rodauth.login_path, label_class: "text-info" } ]
end
@nav_path = controller_name
@search_url = nil
@sidebar_items = initialize_sidebar_items
end
def sidebar?
@sidebar_items && @sidebar_items.any?
end
def initialize_sidebar_items
[]
end
end

View file

@ -0,0 +1,6 @@
class BackofficeController < ApplicationController
include BackofficeMenu
def show
end
end

View file

@ -1,6 +1,8 @@
# frozen_string_literal: true
class ChecklistsController < ApplicationController
include BackofficeMenu
before_action :set_checklist, only: %i[show edit update destroy]
# GET /checklists

View file

@ -1,6 +1,8 @@
# frozen_string_literal: true
class ChecksController < ApplicationController
include BackofficeMenu
before_action :set_check, only: %i[show edit update destroy]
# GET /checks or /checks.json

View file

@ -0,0 +1,12 @@
module BackofficeMenu
extend ActiveSupport::Concern
def initialize_sidebar_items
[
{ label: "Einstellungen", icon: :sliders, path: :backoffice },
{ label: Checklist.model_name.human(count: 2), icon: :'list-check', path: :checklists },
{ label: Check.model_name.human(count: 2), icon: :check2, path: :checks },
{ label: Link.model_name.human(count: 2), icon: :link, path: :links },
{ label: LinkCategory.model_name.human(count: 2), icon: :folder, path: :link_categories } ]
end
end

View file

@ -2,5 +2,9 @@
class HomeController < ApplicationController
def show
if rodauth.logged_in?
else
render :root
end
end
end

View file

@ -1,6 +1,8 @@
# frozen_string_literal: true
class LinkCategoriesController < ApplicationController
include BackofficeMenu
before_action :set_link_category, only: %i[show edit update destroy]
# GET /link_categories

View file

@ -1,6 +1,8 @@
# frozen_string_literal: true
class LinksController < ApplicationController
include BackofficeMenu
before_action :set_link, only: %i[show edit update destroy]
# GET /links

View file

@ -0,0 +1,37 @@
class RodauthController < ApplicationController
# Used by Rodauth for rendering views, CSRF protection, running any
# registered action callbacks and rescue handlers, instrumentation etc.
# Controller callbacks and rescue handlers will run around Rodauth endpoints.
# before_action :verify_captcha, only: :login, if: -> { request.post? }
# rescue_from("SomeError") { |exception| ... }
# Layout can be changed for all Rodauth pages or only certain pages.
# layout "authentication"
# layout -> do
# case rodauth.current_route
# when :login, :create_account, :verify_account, :verify_account_resend,
# :reset_password, :reset_password_request
# "authentication"
# else
# "application"
# end
# end
#
before_action do
# Fix encoding in rodauth views.
response.headers["Content-Type"] = "text/html; charset=utf-8" if request.format.html?
end
def profile
end
private
def initialize_sidebar_items
[
{ label: "Profile", icon: :'person', path: profile_path, active: action_name == "profile" },
{ label: "Passwort ändern", icon: :'lock', path: rodauth.change_password_path, active: action_name == "change_password" },
{ label: "Logout", icon: :'box-arrow-right', path: rodauth.logout_path, active: action_name == "logout" }
]
end
end