mirror of
https://github.com/TracksApp/tracks.git
synced 2026-02-03 06:21:49 +01:00
Restore functionality for creating an admin user on first run. Fixes #429.
Also improved the messaging in this situation. git-svn-id: http://www.rousette.org.uk/svn/tracks-repos/trunk@411 a4c988fc-2ded-0310-b66e-134b36920a42
This commit is contained in:
parent
ddc6d57c17
commit
b1b03b2c8a
6 changed files with 28 additions and 8 deletions
|
|
@ -25,7 +25,7 @@ class LoginController < ApplicationController
|
|||
end
|
||||
when :get
|
||||
if User.no_users_yet?
|
||||
redirect_to :action => 'signup'
|
||||
redirect_to :controller => 'users', :action => 'new'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@ class UsersController < ApplicationController
|
|||
end
|
||||
|
||||
before_filter :admin_login_required, :only => [ :index, :destroy ]
|
||||
skip_before_filter :login_required, :only => [ :new, :create ]
|
||||
prepend_before_filter :login_optional, :only => [ :new, :create ]
|
||||
|
||||
def index
|
||||
@page_title = "TRACKS::Manage Users"
|
||||
|
|
@ -19,13 +21,15 @@ class UsersController < ApplicationController
|
|||
|
||||
def new
|
||||
if User.no_users_yet?
|
||||
@page_title = "Sign up as the admin user"
|
||||
@page_title = "TRACKS::Sign up as the admin user"
|
||||
@heading = "Welcome to TRACKS. To get started, please create an admin account:"
|
||||
@user = get_new_user
|
||||
elsif @user && @user.is_admin?
|
||||
@page_title = "Sign up a new user"
|
||||
@page_title = "TRACKS::Sign up a new user"
|
||||
@heading = "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"
|
||||
@page_title = "TRACKS::No signups"
|
||||
@admin_email = User.find_admin.preference.admin_email
|
||||
render :action => "nosignup", :layout => "login"
|
||||
return
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
<%= render_flash %>
|
||||
|
||||
<h3><%= @page_title -%></h3>
|
||||
<h3><%= @heading -%></h3>
|
||||
|
||||
<table>
|
||||
<tr>
|
||||
|
|
@ -22,7 +22,7 @@
|
|||
</tr>
|
||||
<tr>
|
||||
<td></td>
|
||||
<td><input type="submit" value="Signup »" class="primary" /></td>
|
||||
<td><input type="submit" id="signup" value="Signup »" class="primary" /></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
|
|
|
|||
|
|
@ -66,6 +66,22 @@ module LoginSystem
|
|||
return false
|
||||
end
|
||||
|
||||
def login_optional
|
||||
|
||||
if session['user_id'] and authorize?(get_current_user)
|
||||
return true
|
||||
end
|
||||
|
||||
http_user, http_pass = get_basic_auth_data
|
||||
if user = User.authenticate(http_user, http_pass)
|
||||
session['user_id'] = user.id
|
||||
get_current_user
|
||||
return true
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
def get_current_user
|
||||
if @user.nil? && session['user_id']
|
||||
@user = User.find session['user_id'], :include => :preference
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ class LoginControllerTest < Test::Unit::TestCase
|
|||
def test_login_with_no_users_redirects_to_signup
|
||||
User.delete_all
|
||||
get :login
|
||||
assert_redirected_to :controller => 'login', :action => 'signup'
|
||||
assert_redirected_to :controller => 'users', :action => 'new'
|
||||
end
|
||||
|
||||
def test_logout
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ class CreateUserControllerTest < ActionController::IntegrationTest
|
|||
|
||||
def test_fails_with_401_if_not_authorized_user
|
||||
authenticated_post_xml_to_user_create @@foobar_postdata, 'nobody', 'nohow'
|
||||
assert_401_unauthorized
|
||||
assert_401_unauthorized_admin
|
||||
end
|
||||
|
||||
def test_fails_with_401_if_not_admin_user
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue