diff --git a/app/assets/javascripts/access.coffee b/app/assets/javascripts/access.coffee new file mode 100644 index 0000000..24f83d1 --- /dev/null +++ b/app/assets/javascripts/access.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/app/assets/stylesheets/access.scss b/app/assets/stylesheets/access.scss new file mode 100644 index 0000000..dd37c7b --- /dev/null +++ b/app/assets/stylesheets/access.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the access controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 2b456bb..15e73be 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,3 +1,14 @@ class ApplicationController < ActionController::Base protect_from_forgery with: :exception + + def authenticated? + session[:authenticated] == true + end + + def must_be_authenticated + unless authenticated? + session[:redirect_to] = request.path + redirect_to login_path + end + end end diff --git a/app/controllers/groups_controller.rb b/app/controllers/groups_controller.rb index 618964b..0db248a 100644 --- a/app/controllers/groups_controller.rb +++ b/app/controllers/groups_controller.rb @@ -1,5 +1,6 @@ class GroupsController < ApplicationController before_action :set_group, only: %i[edit update destroy] + before_action :must_be_authenticated, only: %i[new create edit update destroy] def new @group = Group.new diff --git a/app/controllers/site_controller.rb b/app/controllers/site_controller.rb new file mode 100644 index 0000000..b5d8ecb --- /dev/null +++ b/app/controllers/site_controller.rb @@ -0,0 +1,19 @@ +class SiteController < ApplicationController + def login + end + + def auth + if params[:username] == ENV["username"] && params[:password] == ENV["password"] + session[:authenticated] = true + redirect_to session[:redirect_to] || diffs_path + else + render :login + end + end + + def logout + session[:authenticated] = false + redirect_to :login + end + +end diff --git a/app/controllers/sites_controller.rb b/app/controllers/sites_controller.rb index 58d47b9..905118b 100644 --- a/app/controllers/sites_controller.rb +++ b/app/controllers/sites_controller.rb @@ -1,5 +1,6 @@ class SitesController < ApplicationController before_action :set_site, only: %i[show edit update destroy] + before_action :must_be_authenticated, only: %i[new create edit update destroy] def index @sites = Site.all.includes(:group).order(:group_id, :url) diff --git a/app/controllers/templates_controller.rb b/app/controllers/templates_controller.rb index 9b365ad..c15113e 100644 --- a/app/controllers/templates_controller.rb +++ b/app/controllers/templates_controller.rb @@ -1,5 +1,6 @@ class TemplatesController < ApplicationController before_action :set_template, only: %i[edit update destroy] + before_action :must_be_authenticated, only: %i[new create edit update destroy] def new @template = ::Template.new diff --git a/app/helpers/access_helper.rb b/app/helpers/access_helper.rb new file mode 100644 index 0000000..342c6ff --- /dev/null +++ b/app/helpers/access_helper.rb @@ -0,0 +1,2 @@ +module AccessHelper +end diff --git a/app/views/config/index.html.erb b/app/views/config/index.html.erb index 731cdd2..f49612f 100644 --- a/app/views/config/index.html.erb +++ b/app/views/config/index.html.erb @@ -12,8 +12,11 @@