mirror of
https://github.com/TracksApp/tracks.git
synced 2026-02-03 06:21:49 +01:00
Clean up logic that checks to see if a user is an admin.
git-svn-id: http://www.rousette.org.uk/svn/tracks-repos/trunk@378 a4c988fc-2ded-0310-b66e-134b36920a42
This commit is contained in:
parent
0e6c6f9f77
commit
dd54b925a9
2 changed files with 9 additions and 20 deletions
|
|
@ -69,11 +69,7 @@ class ApplicationController < ActionController::Base
|
|||
@user = User.find(session['user_id']) if session['user_id']
|
||||
@prefs = @user.preference unless @user.nil?
|
||||
end
|
||||
|
||||
def get_admin_user
|
||||
@admin = User.find(:first, :conditions => [ "is_admin = ?", true ])
|
||||
end
|
||||
|
||||
|
||||
def parse_date_per_user_prefs( s )
|
||||
return nil if s.blank?
|
||||
Date.strptime(s, @user.preference.date_format)
|
||||
|
|
|
|||
|
|
@ -82,16 +82,13 @@ class LoginController < ApplicationController
|
|||
if User.no_users_yet?
|
||||
@page_title = "Sign up as the admin user"
|
||||
@user = get_new_user
|
||||
else
|
||||
admin = User.find_admin
|
||||
if current_user_is admin
|
||||
@page_title = "Sign up a new user"
|
||||
@user = get_new_user
|
||||
else # all other situations (i.e. a non-admin is logged in, or no one is logged in, but we have some users)
|
||||
@page_title = "No signups"
|
||||
@admin_email = admin.preference.admin_email
|
||||
render :action => "nosignup"
|
||||
end
|
||||
elsif @user && @user.is_admin?
|
||||
@page_title = "Sign up a new user"
|
||||
@user = get_new_user
|
||||
else # all other situations (i.e. a non-admin is logged in, or no one is logged in, but we have some users)
|
||||
@page_title = "No signups"
|
||||
@admin_email = User.find_admin.preference.admin_email
|
||||
render :action => "nosignup"
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -158,11 +155,7 @@ class LoginController < ApplicationController
|
|||
end
|
||||
user
|
||||
end
|
||||
|
||||
def current_user_is(user)
|
||||
session['user_id'] && session['user_id'] == user.id
|
||||
end
|
||||
|
||||
|
||||
def should_expire_sessions?
|
||||
session['noexpiry'] != "on"
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue