Commit 2cd8dbb3ae34255808165d9bfa3131a981c5e7b8
Committed by
Antonio Terceiro
1 parent
1f072e5a
Exists in
staging
and in
42 other branches
Redirect to correct page after login
ActionItem1305
Showing
6 changed files
with
114 additions
and
12 deletions
Show diff stats
app/controllers/public/account_controller.rb
@@ -17,7 +17,7 @@ class AccountController < ApplicationController | @@ -17,7 +17,7 @@ class AccountController < ApplicationController | ||
17 | def login | 17 | def login |
18 | @user = User.new | 18 | @user = User.new |
19 | @person = @user.build_person | 19 | @person = @user.build_person |
20 | - store_location(request.referer) | 20 | + store_location(request.referer) unless session[:return_to] |
21 | return unless request.post? | 21 | return unless request.post? |
22 | self.current_user = User.authenticate(params[:user][:login], params[:user][:password]) if params[:user] | 22 | self.current_user = User.authenticate(params[:user][:login], params[:user][:password]) if params[:user] |
23 | if logged_in? | 23 | if logged_in? |
@@ -290,4 +290,5 @@ class AccountController < ApplicationController | @@ -290,4 +290,5 @@ class AccountController < ApplicationController | ||
290 | redirect_back_or_default(:controller => 'home') | 290 | redirect_back_or_default(:controller => 'home') |
291 | end | 291 | end |
292 | end | 292 | end |
293 | + | ||
293 | end | 294 | end |
app/controllers/public/profile_controller.rb
@@ -55,6 +55,7 @@ class ProfileController < PublicController | @@ -55,6 +55,7 @@ class ProfileController < PublicController | ||
55 | end | 55 | end |
56 | 56 | ||
57 | def join | 57 | def join |
58 | + store_location(request.referer) | ||
58 | @wizard = params[:wizard] | 59 | @wizard = params[:wizard] |
59 | if request.post? && params[:confirmation] | 60 | if request.post? && params[:confirmation] |
60 | profile.add_member(current_user.person) | 61 | profile.add_member(current_user.person) |
@@ -65,7 +66,6 @@ class ProfileController < PublicController | @@ -65,7 +66,6 @@ class ProfileController < PublicController | ||
65 | redirect_to_before_join | 66 | redirect_to_before_join |
66 | end | 67 | end |
67 | else | 68 | else |
68 | - store_location(request.referer) | ||
69 | if request.xhr? | 69 | if request.xhr? |
70 | render :layout => false | 70 | render :layout => false |
71 | end | 71 | end |
app/views/shared/join_community_popup.rhtml
1 | <div id='join-community-popup'> | 1 | <div id='join-community-popup'> |
2 | <h3> <%= __('Do you want to join this community?') %> </h3> | 2 | <h3> <%= __('Do you want to join this community?') %> </h3> |
3 | 3 | ||
4 | - <% button_bar do %> | ||
5 | - <% if logged_in? %> | ||
6 | - <%= button(:ok, _('Yes'), profile.join_url.merge(:confirmation => '1'), :method => :post) %> | ||
7 | - <% else %> | ||
8 | - <%= button(:ok, _('Yes'), profile.join_url) %> | 4 | + <% form_tag(profile.join_url) do %> |
5 | + <%= hidden_field(:confirmation, 1) if logged_in? %> | ||
6 | + <% button_bar do %> | ||
7 | + <%= submit_button(:ok,"Yes") %> | ||
8 | + <%= button_to_remote(:cancel, _('Not now'), :url => profile.join_url.merge({:controller => 'profile', :action => 'refuse_for_now', :profile => profile.identifier}), :loaded => '$("join-community-popup").hide()') %> | ||
9 | + <%= button(:cancel, _('No and don\'t ask again'), :controller => 'profile', :action => 'refuse_join', :profile => profile.identifier) if logged_in? %> | ||
9 | <% end %> | 10 | <% end %> |
10 | - <%= button_to_remote(:cancel, _('Not now'), :url => profile.join_url.merge({:controller => 'profile', :action => 'refuse_for_now', :profile => profile.identifier}), :loaded => '$("join-community-popup").hide()') %> | ||
11 | - <%= button(:cancel, _('No and don\'t ask again'), :controller => 'profile', :action => 'refuse_join', :profile => profile.identifier) if logged_in? %> | ||
12 | <% end %> | 11 | <% end %> |
13 | </div> | 12 | </div> |
14 | <%= draggable_element('join-community-popup') %> | 13 | <%= draggable_element('join-community-popup') %> |
@@ -0,0 +1,61 @@ | @@ -0,0 +1,61 @@ | ||
1 | +Feature: join a community | ||
2 | + As a user | ||
3 | + I want to join a community | ||
4 | + In order to interact with other people | ||
5 | + | ||
6 | + Background: | ||
7 | + Given the following users | ||
8 | + | login | name | | ||
9 | + | joaosilva | Joao Silva | | ||
10 | + Given the following communities | ||
11 | + | identifier | name | | ||
12 | + | sample-community | Sample Community | | ||
13 | + | ||
14 | + Scenario: a logged user asks to join a community with "join_community_popup" | ||
15 | + Given feature "join_community_popup" is enabled on environment | ||
16 | + And I am logged in as "joaosilva" | ||
17 | + And I go to Sample Community's homepage | ||
18 | + And I press "Yes" | ||
19 | + Then I should be on Sample Community's homepage | ||
20 | + And "Joao Silva" should be a member of "Sample Community" | ||
21 | + | ||
22 | + Scenario: a logged user asks to join a community without "join_community_popup" | ||
23 | + Given feature "join_community_popup" is disabled on environment | ||
24 | + And I am logged in as "joaosilva" | ||
25 | + And I am on Sample Community's homepage | ||
26 | + And I follow "Join" | ||
27 | + And I should see "Are you sure you want to join Sample Community?" | ||
28 | + When I press "Yes, I want to join." | ||
29 | + Then "Joao Silva" should be a member of "Sample Community" | ||
30 | + | ||
31 | + Scenario: a not logged user asks join a community | ||
32 | + Given feature "join_community_popup" is enabled on environment | ||
33 | + And I am not logged in | ||
34 | + And I go to Sample Community's homepage | ||
35 | + And I press "Yes" | ||
36 | + And I fill in the following: | ||
37 | + | Username | joaosilva | | ||
38 | + | Password | 123456 | | ||
39 | + And I press "Log in" | ||
40 | + And I should see "Are you sure you want to join Sample Community?" | ||
41 | + When I press "Yes, I want to join" | ||
42 | + Then I should be on Sample Community's homepage | ||
43 | + And "Joao Silva" should be a member of "Sample Community" | ||
44 | + | ||
45 | + Scenario: a non-user ask to join a community | ||
46 | + Given feature "join_community_popup" is enabled on environment | ||
47 | + And I am not logged in | ||
48 | + And I go to Sample Community's homepage | ||
49 | + And I press "Yes" | ||
50 | + And I follow "I want to participate" | ||
51 | + And I fill in the following: | ||
52 | + | e-mail | jose@domain.br | | ||
53 | + | Username | joseoliveira | | ||
54 | + | Password | 123456 | | ||
55 | + | Password confirmation | 123456 | | ||
56 | + | Full name | Jose Oliveira | | ||
57 | + And I press "Sign up" | ||
58 | + And I should see "Are you sure you want to join Sample Community?" | ||
59 | + When I press "Yes, I want to join" | ||
60 | + Then I should be on Sample Community's homepage | ||
61 | + And "Jose Oliveira" should be a member of "Sample Community" |
@@ -0,0 +1,41 @@ | @@ -0,0 +1,41 @@ | ||
1 | +Feature: login | ||
2 | + As a user | ||
3 | + I want to login | ||
4 | + In order to view pages logged in | ||
5 | + | ||
6 | + Background: | ||
7 | + Given the following users | ||
8 | + | login | name | | ||
9 | + | joaosilva | Joao Silva | | ||
10 | + | ||
11 | + Scenario: login from portal homepage | ||
12 | + Given I am not logged in | ||
13 | + And I go to the homepage | ||
14 | + And I fill in the following: | ||
15 | + | Username | joaosilva | | ||
16 | + | Password | 123456 | | ||
17 | + When I press "Log in" | ||
18 | + Then I should be on the homepage | ||
19 | + | ||
20 | + Scenario: login from some profile page | ||
21 | + Given I am not logged in | ||
22 | + And the following users | ||
23 | + | login | name | | ||
24 | + | mariasilva | Maria Silva | | ||
25 | + And I go to Maria Silva's homepage | ||
26 | + And I follow "Login" | ||
27 | + And I fill in the following: | ||
28 | + | Username | joaosilva | | ||
29 | + | Password | 123456 | | ||
30 | + When I press "Log in" | ||
31 | + Then I should be on Maria Silva's homepage | ||
32 | + | ||
33 | + Scenario: view my control panel | ||
34 | + Given I am not logged in | ||
35 | + And I go to Joao Silva's control panel | ||
36 | + And I should be on login page | ||
37 | + And I fill in the following: | ||
38 | + | Username | joaosilva | | ||
39 | + | Password | 123456 | | ||
40 | + When I press "Log in" | ||
41 | + Then I should be on Joao Silva's control panel |
test/functional/profile_controller_test.rb
@@ -616,7 +616,7 @@ class ProfileControllerTest < Test::Unit::TestCase | @@ -616,7 +616,7 @@ class ProfileControllerTest < Test::Unit::TestCase | ||
616 | login_as(profile.identifier) | 616 | login_as(profile.identifier) |
617 | 617 | ||
618 | assert_nil @request.session[:return_to] | 618 | assert_nil @request.session[:return_to] |
619 | - @request.expects(:referer).returns("/profile/redirect_to") | 619 | + @request.expects(:referer).returns("/profile/redirect_to").at_least_once |
620 | 620 | ||
621 | get :join, :profile => community.identifier | 621 | get :join, :profile => community.identifier |
622 | 622 | ||
@@ -626,7 +626,7 @@ class ProfileControllerTest < Test::Unit::TestCase | @@ -626,7 +626,7 @@ class ProfileControllerTest < Test::Unit::TestCase | ||
626 | should 'redirect to stored location after join community' do | 626 | should 'redirect to stored location after join community' do |
627 | community = Community.create!(:name => 'my test community') | 627 | community = Community.create!(:name => 'my test community') |
628 | 628 | ||
629 | - @request.session[:return_to] = "/profile/#{community.identifier}/to_go" | 629 | + @request.expects(:referer).returns("/profile/#{community.identifier}/to_go") |
630 | login_as(profile.identifier) | 630 | login_as(profile.identifier) |
631 | 631 | ||
632 | post :join, :profile => community.identifier, :confirmation => '1' | 632 | post :join, :profile => community.identifier, :confirmation => '1' |
@@ -647,7 +647,7 @@ class ProfileControllerTest < Test::Unit::TestCase | @@ -647,7 +647,7 @@ class ProfileControllerTest < Test::Unit::TestCase | ||
647 | should 'redirect to location before login after join community' do | 647 | should 'redirect to location before login after join community' do |
648 | community = Community.create!(:name => 'my test community') | 648 | community = Community.create!(:name => 'my test community') |
649 | 649 | ||
650 | - @request.session[:before_join] = "/profile/#{community.identifier}/to_go" | 650 | + @request.expects(:referer).returns("/profile/#{community.identifier}/to_go") |
651 | login_as(profile.identifier) | 651 | login_as(profile.identifier) |
652 | 652 | ||
653 | post :join, :profile => community.identifier, :confirmation => '1' | 653 | post :join, :profile => community.identifier, :confirmation => '1' |