diff --git a/app/controllers/admin/auth_controller.rb b/app/controllers/admin/auth_controller.rb index f063302..6c8f07f 100644 --- a/app/controllers/admin/auth_controller.rb +++ b/app/controllers/admin/auth_controller.rb @@ -1,16 +1,16 @@ # frozen_string_literal: true module Admin class AuthController < AdminController - skip_before_action :authorize_admin + skip_before_action :authorize_user def login end def auth - admin = User.find_by(email: auth_params[:email], role: 'admin') + user = User.find_by(email: auth_params[:email]) - if admin && admin.authenticate(auth_params[:password]) - session[:user] = admin.to_i + if user && user.authenticate(auth_params[:password]) + session[:user] = user.to_i redirect_to admin_path else redirect_to admin_login_path, diff --git a/app/controllers/admin/profile_controller.rb b/app/controllers/admin/profile_controller.rb index 0894a36..27b9761 100644 --- a/app/controllers/admin/profile_controller.rb +++ b/app/controllers/admin/profile_controller.rb @@ -5,11 +5,11 @@ module Admin end def edit - @user = current_admin + @user = current_user end def update - @user = current_admin + @user = current_user if @user.update_attributes(user_params) redirect_to admin_profile_path, diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb index 27eec24..39b9f06 100644 --- a/app/controllers/admin_controller.rb +++ b/app/controllers/admin_controller.rb @@ -1,22 +1,21 @@ # frozen_string_literal: true class AdminController < ApplicationController layout 'admin' - before_action :authorize_admin + before_action :authorize_user def dashboard @quizzes = Quiz.includes(:questions).all @users = User.order(:role, :name) end - def current_admin - user_args = { id: session[:user], role: 'admin' } - @current_admin ||= User.find_by(user_args) if session[:user] + def current_user + @current_user ||= User.find_by(id: session[:user]) if session[:user] end - helper_method :current_admin + helper_method :current_user private - def authorize_admin - redirect_to admin_login_path unless current_admin + def authorize_user + redirect_to admin_login_path unless current_user end end diff --git a/app/controllers/concerns/.keep b/app/controllers/concerns/.keep deleted file mode 100644 index e69de29..0000000 diff --git a/app/models/concerns/.keep b/app/models/concerns/.keep deleted file mode 100644 index e69de29..0000000 diff --git a/app/views/admin/profile/view.html.erb b/app/views/admin/profile/view.html.erb index 92ff9b1..1c1af5f 100644 --- a/app/views/admin/profile/view.html.erb +++ b/app/views/admin/profile/view.html.erb @@ -2,7 +2,7 @@ content_for :section_title, "Profile" %> -

Name: <%= current_admin.name %>

-

email: <%= current_admin.email %>

-

Role: <%= current_admin.role %>

+

Name: <%= current_user.name %>

+

email: <%= current_user.email %>

+

Role: <%= current_user.role %>

<%= link_to('Edit', admin_edit_profile_path, { class: 'btn' }) %> diff --git a/test/controllers/admin/auth_controller_test.rb b/test/controllers/admin/auth_controller_test.rb index 671f42a..c3cb40c 100644 --- a/test/controllers/admin/auth_controller_test.rb +++ b/test/controllers/admin/auth_controller_test.rb @@ -26,18 +26,16 @@ module Admin assert_redirected_to admin_url end - test "recruiter should not admin auth" do + test "recruiter should auth to dashboard" do post admin_auth_url, params: { auth: { email: 'pdr.recruiter@mailinator.com', password: 'password' } } - assert_redirected_to admin_login_url - assert_match(/incorrect.*email/, flash[:error]) + assert_redirected_to admin_url end - test "reviewer should not admin auth" do + test "reviewer should auth to dashboard" do post admin_auth_url, params: { auth: { email: 'fed.reviewer@mailinator.com', password: 'password' } } - assert_redirected_to admin_login_url - assert_match(/incorrect.*email/, flash[:error]) + assert_redirected_to admin_url end test "should get reset_request" do