Better authentication allowing non user model eg administrator model base

This commit is contained in:
2015-03-04 15:23:01 +01:00
parent b0491aa997
commit aa11f4de80
5 changed files with 15 additions and 9 deletions
@@ -1,6 +1,6 @@
module Cmtool
class ApplicationController < ::ApplicationController
before_filter :authenticate_user!, :authorize_user, :check_environment, :set_locale
before_filter :authorize_user, :check_environment, :set_locale
layout 'cmtool/application'
private
@@ -21,6 +21,12 @@ module Cmtool
end
end
unless method_defined? :cmtool_user
def cmtool_user
current_user
end
end
def check_environment
@cmtool_warnings ||= []
@cmtool_warnings << 'no_host_specified' unless ( Rails.application.config.action_mailer.default_url_options[:host] rescue false) ||
@@ -35,10 +35,6 @@ module Cmtool
end
@user = ::User.find(params[:id])
if @user.update_attributes(user)
if user['password']
# Sign in after changing current logged in password
sign_in(@user, :bypass => true) if @user == current_user
end
redirect_to cmtool.users_path, :notice => I18n.t('cmtool.action.update.successful', :model => ::User.model_name.human)
else
render :action => 'edit'
+3 -3
View File
@@ -7,13 +7,13 @@
li.toggle-topbar.menu-icon
a href="#"
span Menu
- if user_signed_in?
- if cmtool_user.present?
section.top-bar-section
ul.right
li.has-dropdown
a href="#" = current_user.email
a href="#" = cmtool_user.email
ul.dropdown
li.log-out= link_to t('helpers.links.logout'), main_app.destroy_user_session_path, method: :delete
li.log-out= link_to t('helpers.links.logout'), main_app.root_path
ul.left
- Cmtool::Menu.items.each do |menu_item|
- if menu_item.group?
@@ -1,5 +1,5 @@
#user-info
#user-info-email= link_to current_user.email, cmtool.user_path(current_user)
#user-info-email= link_to cmtool_user.email, cmtool.user_path(current_user)
#user-info-sign-in-out class: user_signed_in? ? 'signed-in' : 'signed-out'
- if user_signed_in?
= link_to t('devise.sessions.sign_out'), cmtool.destroy_user_session_path