Log In to Orbit
++ <% end %> + +
diff --git a/app/assets/javascripts/back_end.js b/app/assets/javascripts/back_end.js new file mode 100644 index 0000000..9bdcf86 --- /dev/null +++ b/app/assets/javascripts/back_end.js @@ -0,0 +1 @@ +//= require basic \ No newline at end of file diff --git a/app/assets/javascripts/sessions.js.coffee b/app/assets/javascripts/sessions.js.coffee new file mode 100644 index 0000000..24f83d1 --- /dev/null +++ b/app/assets/javascripts/sessions.js.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/sessions.css.scss b/app/assets/stylesheets/sessions.css.scss new file mode 100644 index 0000000..7bef9cf --- /dev/null +++ b/app/assets/stylesheets/sessions.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the sessions 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/admin/dashboards_controller.rb b/app/controllers/admin/dashboards_controller.rb index 329a92c..9fa0f23 100644 --- a/app/controllers/admin/dashboards_controller.rb +++ b/app/controllers/admin/dashboards_controller.rb @@ -1,4 +1,4 @@ -class Admin::DashboardsController < ApplicationController +class Admin::DashboardsController < OrbitAdminController layout "back_end" def index diff --git a/app/controllers/admin/items_controller.rb b/app/controllers/admin/items_controller.rb index afbc72d..e277159 100644 --- a/app/controllers/admin/items_controller.rb +++ b/app/controllers/admin/items_controller.rb @@ -1,4 +1,4 @@ -class Admin::ItemsController < ApplicationController +class Admin::ItemsController < OrbitAdminController include OrbitHelper layout "structure" diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 74aeaa1..ad71e4e 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -3,7 +3,7 @@ class ApplicationController < ActionController::Base # For APIs, you may want to use :null_session instead. protect_from_forgery with: :exception before_action :set_locale - helper_method :current_site + helper_method :current_site, :current_user def default_url_options(options={}) { locale: I18n.locale } @@ -24,4 +24,23 @@ class ApplicationController < ActionController::Base def current_site @current_site = Site.find_by(site_active: true) end + + private + + def current_user + @current_user ||= User.find(session[:user_id]) if session[:user_id] + end + + protected + + def authenticate_user + if session[:user_id] + # set current user object to @current_user object variable + @current_user = User.find(session[:user_id]) + return true + else + redirect_to new_session_path + return false + end + end end diff --git a/app/controllers/orbit_admin_controller.rb b/app/controllers/orbit_admin_controller.rb new file mode 100644 index 0000000..28f4a05 --- /dev/null +++ b/app/controllers/orbit_admin_controller.rb @@ -0,0 +1,3 @@ +class OrbitAdminController < ApplicationController + before_action :authenticate_user +end diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb new file mode 100644 index 0000000..2bf91f2 --- /dev/null +++ b/app/controllers/sessions_controller.rb @@ -0,0 +1,22 @@ +class SessionsController < ApplicationController + layout "authentication" + + def new + end + + def create + user = User.find_by(user_name: params[:user_name]) + if user && user.authenticate(params[:password]) + session[:user_id] = user.id + redirect_to admin_dashboards_path, :notice => "Logged in!" + else + flash.now.alert = "Invalid email or password" + render "new" + end + end + + def destroy + session[:user_id] = nil + redirect_to root_url, :notice => "Logged out!" + end +end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 4e2c07d..c7aa59a 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -10,8 +10,6 @@ module ApplicationHelper "/module/#{module_name}/show" end - - def render_menu # json_file = File.read(File.join(Rails.root, 'public', "menu.json")) # @items = JSON.parse(json_file) @@ -146,4 +144,5 @@ module ApplicationHelper def active_for_action(controller_name, action_name) ((controller.controller_name.eql?(controller_name) || request.fullpath.eql?(controller_name)) && controller.action_name.eql?(action_name)) ? 'active' : nil end + end diff --git a/app/helpers/sessions_helper.rb b/app/helpers/sessions_helper.rb new file mode 100644 index 0000000..309f8b2 --- /dev/null +++ b/app/helpers/sessions_helper.rb @@ -0,0 +1,2 @@ +module SessionsHelper +end diff --git a/app/models/user.rb b/app/models/user.rb index d999006..fa69d5a 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -6,7 +6,7 @@ class User field :user_name, type: String field :email, type: String - field :password_digest, type: + field :password_digest, type: String has_secure_password diff --git a/app/views/layouts/_left_menu.html.erb b/app/views/layouts/_left_menu.html.erb index 486bbda..d3ad656 100644 --- a/app/views/layouts/_left_menu.html.erb +++ b/app/views/layouts/_left_menu.html.erb @@ -6,10 +6,8 @@
diff --git a/app/views/layouts/_right_menu.html.erb b/app/views/layouts/_right_menu.html.erb index d4d4531..78ea05d 100644 --- a/app/views/layouts/_right_menu.html.erb +++ b/app/views/layouts/_right_menu.html.erb @@ -11,21 +11,23 @@