summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAzul <azul@leap.se>2014-04-04 15:40:22 +0200
committerAzul <azul@leap.se>2014-04-04 15:40:22 +0200
commitaeb5d8cf8dc6329906f14bf4595a229e002691c1 (patch)
tree000f3137aeb711a4008dd58f930f9c6b7d9d0e65
parent7b4f9ad334ec702449fdc683ea8fc312e06b2bd9 (diff)
redirect home when logged in visits /signup (#5446)
-rw-r--r--users/app/controllers/controller_extension/authentication.rb7
-rw-r--r--users/app/controllers/sessions_controller.rb3
-rw-r--r--users/app/controllers/users_controller.rb1
-rw-r--r--users/test/functional/users_controller_test.rb8
4 files changed, 17 insertions, 2 deletions
diff --git a/users/app/controllers/controller_extension/authentication.rb b/users/app/controllers/controller_extension/authentication.rb
index e83d6b2..03d3989 100644
--- a/users/app/controllers/controller_extension/authentication.rb
+++ b/users/app/controllers/controller_extension/authentication.rb
@@ -19,6 +19,13 @@ module ControllerExtension::Authentication
access_denied unless logged_in?
end
+ # some actions only make sense if you are not logged in yet.
+ # (login, signup). If a user tries to perform these they will
+ # be redirected to their dashboard.
+ def redirect_if_logged_in
+ redirect_to home_url if logged_in?
+ end
+
def access_denied
respond_to do |format|
format.html do
diff --git a/users/app/controllers/sessions_controller.rb b/users/app/controllers/sessions_controller.rb
index 0195f30..8919a4d 100644
--- a/users/app/controllers/sessions_controller.rb
+++ b/users/app/controllers/sessions_controller.rb
@@ -1,7 +1,8 @@
class SessionsController < ApplicationController
+ before_filter :redirect_if_logged_in, :only => [:new]
+
def new
- redirect_to home_url if logged_in?
@session = Session.new
if authentication_errors
@errors = authentication_errors
diff --git a/users/app/controllers/users_controller.rb b/users/app/controllers/users_controller.rb
index 6b32d49..c8e09b6 100644
--- a/users/app/controllers/users_controller.rb
+++ b/users/app/controllers/users_controller.rb
@@ -5,6 +5,7 @@
class UsersController < UsersBaseController
before_filter :require_login, :except => [:new]
+ before_filter :redirect_if_logged_in, :only => [:new]
before_filter :require_admin, :only => [:index, :deactivate, :enable]
before_filter :fetch_user, :only => [:show, :edit, :update, :destroy, :deactivate, :enable]
diff --git a/users/test/functional/users_controller_test.rb b/users/test/functional/users_controller_test.rb
index 57ae94d..0713836 100644
--- a/users/test/functional/users_controller_test.rb
+++ b/users/test/functional/users_controller_test.rb
@@ -4,11 +4,17 @@ class UsersControllerTest < ActionController::TestCase
test "should get new" do
get :new
-
assert_equal User, assigns(:user).class
assert_response :success
end
+ test "new should redirect logged in users" do
+ login
+ get :new
+ assert_response :redirect
+ assert_redirected_to home_path
+ end
+
test "failed show without login" do
user = find_record :user
get :show, :id => user.id