Skip to content

Commit

Permalink
Add devise and ability to sign in into admin CMS pages
Browse files Browse the repository at this point in the history
  • Loading branch information
murny committed Aug 14, 2024
1 parent d9caec8 commit a33bfd0
Show file tree
Hide file tree
Showing 18 changed files with 511 additions and 14 deletions.
2 changes: 0 additions & 2 deletions .bundle/config

This file was deleted.

2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,5 @@ end

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem "tzinfo-data", platforms: [:mingw, :mswin, :x64_mingw, :jruby]

gem "devise", "~> 4.9"
14 changes: 14 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ GEM
public_suffix (>= 2.0.2, < 6.0)
ast (2.4.2)
base64 (0.2.0)
bcrypt (3.1.20)
bigdecimal (3.1.8)
bindex (0.8.1)
bootsnap (1.18.4)
Expand All @@ -123,6 +124,12 @@ GEM
cssbundling-rails (1.4.1)
railties (>= 6.0.0)
date (3.3.4)
devise (4.9.4)
bcrypt (~> 3.0)
orm_adapter (~> 0.1)
railties (>= 4.1.0)
responders
warden (~> 1.2.3)
drb (2.2.1)
erubi (1.13.0)
execjs (2.9.1)
Expand Down Expand Up @@ -212,6 +219,7 @@ GEM
racc (~> 1.4)
nokogiri (1.16.7-x86_64-linux)
racc (~> 1.4)
orm_adapter (0.5.0)
parallel (1.26.2)
parser (3.3.4.2)
ast (~> 2.4.1)
Expand Down Expand Up @@ -272,6 +280,9 @@ GEM
regexp_parser (2.9.2)
reline (0.5.9)
io-console (~> 0.5)
responders (3.1.1)
actionpack (>= 5.2)
railties (>= 5.2)
rexml (3.3.5)
strscan
rollbar (3.5.2)
Expand Down Expand Up @@ -357,6 +368,8 @@ GEM
uglifier (4.2.0)
execjs (>= 0.3.0, < 3)
unicode-display_width (2.5.0)
warden (1.2.9)
rack (>= 2.0.9)
web-console (4.2.1)
actionview (>= 6.0.0)
activemodel (>= 6.0.0)
Expand Down Expand Up @@ -385,6 +398,7 @@ DEPENDENCIES
capybara (>= 2.15)
comfortable_mexican_sofa!
cssbundling-rails
devise (~> 4.9)
htmlentities
image_processing (~> 1.13)
jbuilder (~> 2.12)
Expand Down
4 changes: 4 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# frozen_string_literal: true

class ApplicationController < ActionController::Base
# Devise helper method for controlling where you go after signing in (by default it's the root_url)
def after_sign_in_path_for(resource)
comfy_admin_cms_path
end
end
6 changes: 6 additions & 0 deletions app/models/admin.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class Admin < ApplicationRecord
# Include default devise modules. Others available are:
# :confirmable, :lockable, :registerable, :timeoutable, :trackable and :omniauthable
devise :database_authenticatable,
:recoverable, :rememberable, :validatable
end
3 changes: 3 additions & 0 deletions config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@

config.action_mailer.perform_caching = false

# Set host to be used by links generated in mailer templates.
config.action_mailer.default_url_options = {host: "localhost", port: 3000}

# Print deprecation notices to the Rails logger.
config.active_support.deprecation = :log

Expand Down
3 changes: 3 additions & 0 deletions config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@

config.action_mailer.perform_caching = false

# Set host to be used by links generated in mailer templates.
config.action_mailer.default_url_options = {host: "library.ualberta.ca"}

# Ignore bad email addresses and do not raise email delivery errors.
# Set this to true and configure the email server for immediate delivery to raise delivery errors.
# config.action_mailer.raise_delivery_errors = false
Expand Down
3 changes: 3 additions & 0 deletions config/environments/staging.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@

config.action_mailer.perform_caching = false

# Set host to be used by links generated in mailer templates.
config.action_mailer.default_url_options = {host: "library.ualberta.ca"}

# Ignore bad email addresses and do not raise email delivery errors.
# Set this to true and configure the email server for immediate delivery to raise delivery errors.
# config.action_mailer.raise_delivery_errors = false
Expand Down
3 changes: 3 additions & 0 deletions config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@

config.action_mailer.perform_caching = false

# Set host to be used by links generated in mailer templates.
config.action_mailer.default_url_options = {host: "example.com"}

# Tell Action Mailer not to deliver emails to the real world.
# The :test delivery method accumulates sent emails in the
# ActionMailer::Base.deliveries array.
Expand Down
23 changes: 12 additions & 11 deletions config/initializers/comfortable_mexican_sofa.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

ComfortableMexicanSofa.configure do |config|
# Title of the admin area
# config.cms_title = 'ComfortableMexicanSofa CMS Engine'
config.cms_title = "U of A Library CMS"

# Controller that is inherited from CmsAdmin::BaseController
# config.base_controller = 'ApplicationController'

# Module responsible for authentication. You can replace it with your own.
# It simply needs to have #authenticate method. See http_auth.rb for reference.
# config.admin_auth = 'ComfyAdminAuthentication'
config.admin_auth = "ComfyAdminAuthentication"

# Module responsible for authorization on admin side. It should have #authorize
# method that returns true or false based on params and loaded instance
Expand Down Expand Up @@ -81,15 +81,16 @@

# Default credentials for ComfortableMexicanSofa::AccessControl::AdminAuthentication
# YOU REALLY WANT TO CHANGE THIS BEFORE PUTTING YOUR SITE LIVE
ComfortableMexicanSofa::AccessControl::AdminAuthentication.username = Rails.application.secrets.cms_user
ComfortableMexicanSofa::AccessControl::AdminAuthentication.password = Rails.application.secrets.cms_password

# Uncomment this module and `config.admin_auth` above to use custom admin authentication
# module ComfyAdminAuthentication
# def authenticate
# return true
# end
# end
# ComfortableMexicanSofa::AccessControl::AdminAuthentication.username = Rails.application.secrets.cms_user
# ComfortableMexicanSofa::AccessControl::AdminAuthentication.password = Rails.application.secrets.cms_password

module ComfyAdminAuthentication
def authenticate
unless current_admin
redirect_to new_admin_session_path
end
end
end

# Uncomment this module and `config.admin_authorization` above to use custom admin authorization
# module ComfyAdminAuthorization
Expand Down
Loading

0 comments on commit a33bfd0

Please sign in to comment.