mirror of
https://github.com/TracksApp/tracks.git
synced 2026-01-10 19:28:51 +01:00
Fixed a regression in the trunk in which a fresh installation (with no users) generated an error on visiting /signup, because @user was nil.
My changes to signup are a little verbose, but they work. git-svn-id: http://www.rousette.org.uk/svn/tracks-repos/trunk@222 a4c988fc-2ded-0310-b66e-134b36920a42
This commit is contained in:
parent
e1cb2b0f29
commit
5a331c0a66
3 changed files with 21 additions and 8 deletions
|
|
@ -60,4 +60,8 @@ class ApplicationController < ActionController::Base
|
|||
@user = User.find(session['user_id']) if session['user_id']
|
||||
end
|
||||
|
||||
def get_admin_user
|
||||
@admin = User.find(:first, :conditions => [ "is_admin = ?", true ])
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -27,17 +27,26 @@ class LoginController < ApplicationController
|
|||
end
|
||||
|
||||
def signup
|
||||
admin_logged_in = User.find(:all,
|
||||
:conditions => [ "id = ? and is_admin = ?", @user.id, true ])
|
||||
unless (User.find_all.empty? || !admin_logged_in.empty? )
|
||||
if User.find_all.empty? # signup the first user as admin
|
||||
@page_title = "Sign up as the admin user"
|
||||
elsif session['user_id'] # we have someone logged in
|
||||
get_admin_user
|
||||
if session['user_id'] == @admin.id # logged in user is admin, so allow signup
|
||||
@page_title = "Sign up a new user"
|
||||
else
|
||||
@page_title = "No signups"
|
||||
@admin_email = @admin.preferences["admin_email"]
|
||||
render :action => "nosignup"
|
||||
return
|
||||
end
|
||||
else # no-one logged in, but we have some Users
|
||||
get_admin_user
|
||||
@page_title = "No signups"
|
||||
@admin_email = User.find(1).preferences["admin_email"]
|
||||
@admin_email = @admin.preferences["admin_email"]
|
||||
render :action => "nosignup"
|
||||
return
|
||||
end
|
||||
@signupname = User.find_all.empty? ? "as the admin":"a new"
|
||||
@page_title = "Sign up #{@signupname} user"
|
||||
|
||||
|
||||
if session['new_user']
|
||||
@user = session['new_user']
|
||||
session['new_user'] = nil
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ class LoginControllerTest < Test::Unit::TestCase
|
|||
def test_invalid_login
|
||||
post :login, {:user_login => 'cracker', :user_password => 'secret', :user_noexpiry => 'on'}
|
||||
assert_response :success
|
||||
assert_session_has_no :user
|
||||
assert_session_has_no :user_id
|
||||
assert_template "login"
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue