Commit cf9140ee2264b6cc90caf69b60a4404ff4cda7a2
Committed by
Antonio Terceiro
1 parent
44c42816
Exists in
master
and in
23 other branches
Redirecting logged users if tries to signup/login
(ActionItem1354)
Showing
7 changed files
with
28 additions
and
1 deletions
Show diff stats
app/controllers/public/account_controller.rb
| @@ -5,6 +5,7 @@ class AccountController < ApplicationController | @@ -5,6 +5,7 @@ class AccountController < ApplicationController | ||
| 5 | require_ssl :except => [ :login_popup, :logout_popup, :wizard, :profile_details ] | 5 | require_ssl :except => [ :login_popup, :logout_popup, :wizard, :profile_details ] |
| 6 | 6 | ||
| 7 | before_filter :login_required, :only => [:activation_question, :accept_terms, :activate_enterprise] | 7 | before_filter :login_required, :only => [:activation_question, :accept_terms, :activate_enterprise] |
| 8 | + before_filter :redirect_if_logged_in, :only => [:login, :signup] | ||
| 8 | 9 | ||
| 9 | # say something nice, you goof! something sweet. | 10 | # say something nice, you goof! something sweet. |
| 10 | def index | 11 | def index |
| @@ -291,4 +292,10 @@ class AccountController < ApplicationController | @@ -291,4 +292,10 @@ class AccountController < ApplicationController | ||
| 291 | end | 292 | end |
| 292 | end | 293 | end |
| 293 | 294 | ||
| 295 | + def redirect_if_logged_in | ||
| 296 | + if logged_in? | ||
| 297 | + go_to_initial_page | ||
| 298 | + end | ||
| 299 | + end | ||
| 300 | + | ||
| 294 | end | 301 | end |
features/login.feature
| @@ -39,3 +39,8 @@ Feature: login | @@ -39,3 +39,8 @@ Feature: login | ||
| 39 | | Password | 123456 | | 39 | | Password | 123456 | |
| 40 | When I press "Log in" | 40 | When I press "Log in" |
| 41 | Then I should be on Joao Silva's control panel | 41 | Then I should be on Joao Silva's control panel |
| 42 | + | ||
| 43 | + Scenario: be redirected if user goes to login page and is logged | ||
| 44 | + Given I am logged in as "joaosilva" | ||
| 45 | + And I go to login page | ||
| 46 | + Then I should be on Joao Silva's control panel |
features/publish_article.feature
| @@ -40,6 +40,7 @@ Feature: publish article | @@ -40,6 +40,7 @@ Feature: publish article | ||
| 40 | And I follow "Spread" | 40 | And I follow "Spread" |
| 41 | And I check "Sample Community" | 41 | And I check "Sample Community" |
| 42 | And I press "Publish" | 42 | And I press "Publish" |
| 43 | + And I am not logged in | ||
| 43 | And I am logged in as "mariasilva" | 44 | And I am logged in as "mariasilva" |
| 44 | And "Maria Silva" is a member of "Sample Community" | 45 | And "Maria Silva" is a member of "Sample Community" |
| 45 | And I am on Maria Silva's control panel | 46 | And I am on Maria Silva's control panel |
features/signup.feature
| @@ -15,3 +15,10 @@ Feature: signup | @@ -15,3 +15,10 @@ Feature: signup | ||
| 15 | And I press "Sign up" | 15 | And I press "Sign up" |
| 16 | Then I should see "Thanks for signing up!" | 16 | Then I should see "Thanks for signing up!" |
| 17 | 17 | ||
| 18 | + Scenario: be redirected if user goes to signup page and is logged | ||
| 19 | + Given the following users | ||
| 20 | + | login | name | | ||
| 21 | + | joaosilva | Joao Silva | | ||
| 22 | + Given I am logged in as "joaosilva" | ||
| 23 | + And I go to signup page | ||
| 24 | + Then I should be on Joao Silva's control panel |
features/support/paths.rb
| @@ -29,6 +29,9 @@ module NavigationHelpers | @@ -29,6 +29,9 @@ module NavigationHelpers | ||
| 29 | when /^login page$/ | 29 | when /^login page$/ |
| 30 | '/account/login' | 30 | '/account/login' |
| 31 | 31 | ||
| 32 | + when /^signup page$/ | ||
| 33 | + '/account/signup' | ||
| 34 | + | ||
| 32 | when /^(.*)'s control panel$/ | 35 | when /^(.*)'s control panel$/ |
| 33 | '/myprofile/%s' % Profile.find_by_name($1).identifier | 36 | '/myprofile/%s' % Profile.find_by_name($1).identifier |
| 34 | 37 |
test/functional/account_controller_test.rb
| @@ -36,6 +36,7 @@ class AccountControllerTest < Test::Unit::TestCase | @@ -36,6 +36,7 @@ class AccountControllerTest < Test::Unit::TestCase | ||
| 36 | should 'redirect to where user was on login' do | 36 | should 'redirect to where user was on login' do |
| 37 | @request.env["HTTP_REFERER"] = '/bli' | 37 | @request.env["HTTP_REFERER"] = '/bli' |
| 38 | u = new_user | 38 | u = new_user |
| 39 | + @controller.stubs(:logged_in?).returns(false) | ||
| 39 | post :login, :user => {:login => 'quire', :password => 'quire'} | 40 | post :login, :user => {:login => 'quire', :password => 'quire'} |
| 40 | 41 | ||
| 41 | assert_redirected_to '/bli' | 42 | assert_redirected_to '/bli' |
| @@ -283,6 +284,7 @@ class AccountControllerTest < Test::Unit::TestCase | @@ -283,6 +284,7 @@ class AccountControllerTest < Test::Unit::TestCase | ||
| 283 | assert_difference User, :count do | 284 | assert_difference User, :count do |
| 284 | new_user(:login => 'user1', :email => 'user@example.com') | 285 | new_user(:login => 'user1', :email => 'user@example.com') |
| 285 | assert assigns(:user).valid? | 286 | assert assigns(:user).valid? |
| 287 | + @controller.stubs(:logged_in?).returns(false) | ||
| 286 | new_user(:login => 'user2', :email => 'user@example.com') | 288 | new_user(:login => 'user2', :email => 'user@example.com') |
| 287 | assert assigns(:user).errors.on(:email) | 289 | assert assigns(:user).errors.on(:email) |
| 288 | end | 290 | end |
test/integration/enterprise_registration_test.rb
| @@ -44,10 +44,12 @@ class EnterpriseRegistrationTest < ActionController::IntegrationTest | @@ -44,10 +44,12 @@ class EnterpriseRegistrationTest < ActionController::IntegrationTest | ||
| 44 | 44 | ||
| 45 | code = CreateEnterprise.find(:first, :order => 'id desc').code | 45 | code = CreateEnterprise.find(:first, :order => 'id desc').code |
| 46 | 46 | ||
| 47 | + post '/account/logout' | ||
| 48 | + | ||
| 47 | # steps done by the validator | 49 | # steps done by the validator |
| 48 | validator = create_user_with_permission('validator', 'validate_enterprise', org) | 50 | validator = create_user_with_permission('validator', 'validate_enterprise', org) |
| 49 | login 'validator', 'validator' | 51 | login 'validator', 'validator' |
| 50 | - | 52 | + |
| 51 | get "/myprofile/myorg/enterprise_validation" | 53 | get "/myprofile/myorg/enterprise_validation" |
| 52 | assert_response :success | 54 | assert_response :success |
| 53 | assert_tag :tag => 'a', :attributes => { :href => "/myprofile/myorg/enterprise_validation/details/#{code}" } | 55 | assert_tag :tag => 'a', :attributes => { :href => "/myprofile/myorg/enterprise_validation/details/#{code}" } |