summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2014-07-11 19:27:04 +0000
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2014-07-11 19:27:04 +0000
commit8da8efb387cc62dd85fcb4abcb5a6197521303a5 (patch)
tree1beb202aff0a939c7f7feb4dc46ecc6e676fcabd
parentf3b0cb77fcb379107cdd4f770fdb16381cda1baf (diff)
parent3b80d68f9d9d074ca24ca7cbc2f123360670a29a (diff)
downloadgitlab-ce-8da8efb387cc62dd85fcb4abcb5a6197521303a5.tar.gz
Merge branch 'redirect_on_signin' into 'master'
Redirect on signin Fixes #1346 See merge request !965
-rw-r--r--app/controllers/application_controller.rb2
-rw-r--r--app/controllers/sessions_controller.rb14
-rw-r--r--app/controllers/users_sessions_controller.rb6
-rw-r--r--app/views/devise/sessions/_new_base.html.haml6
-rw-r--r--app/views/layouts/_public_head_panel.html.haml4
-rw-r--r--config/routes.rb2
-rw-r--r--features/project/redirects.feature5
-rw-r--r--features/steps/project/redirects.rb17
8 files changed, 41 insertions, 15 deletions
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index 1feeb601d36..d0546a441e1 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -68,7 +68,7 @@ class ApplicationController < ActionController::Base
flash[:alert] = "Your account is blocked. Retry when an admin has unblocked it."
new_user_session_path
else
- @return_to || root_path
+ stored_location_for(:redirect) || stored_location_for(resource) || root_path
end
end
diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb
new file mode 100644
index 00000000000..9b7bd94c3a2
--- /dev/null
+++ b/app/controllers/sessions_controller.rb
@@ -0,0 +1,14 @@
+class SessionsController < Devise::SessionsController
+
+ def new
+ if request.referer.present?
+ store_location_for(:redirect, URI(request.referer).path)
+ end
+
+ super
+ end
+
+ def create
+ super
+ end
+end
diff --git a/app/controllers/users_sessions_controller.rb b/app/controllers/users_sessions_controller.rb
deleted file mode 100644
index 656c92376fd..00000000000
--- a/app/controllers/users_sessions_controller.rb
+++ /dev/null
@@ -1,6 +0,0 @@
-class UsersSessionsController < Devise::SessionsController
- def create
- @return_to = params[:return_to]
- super
- end
-end
diff --git a/app/views/devise/sessions/_new_base.html.haml b/app/views/devise/sessions/_new_base.html.haml
index d26c0c92cb8..a2f85fa3fe2 100644
--- a/app/views/devise/sessions/_new_base.html.haml
+++ b/app/views/devise/sessions/_new_base.html.haml
@@ -7,8 +7,8 @@
= f.check_box :remember_me
%span Remember me
%div
- = hidden_field_tag 'return_to', params[:return_to]
- = f.submit "Sign in", class: "btn-save btn"
-
+ = f.submit "Sign in", class: "btn-create btn"
.pull-right
= link_to "Forgot your password?", new_password_path(resource_name), class: "btn"
+
+
diff --git a/app/views/layouts/_public_head_panel.html.haml b/app/views/layouts/_public_head_panel.html.haml
index 25984df0444..63992a22f32 100644
--- a/app/views/layouts/_public_head_panel.html.haml
+++ b/app/views/layouts/_public_head_panel.html.haml
@@ -13,10 +13,10 @@
%i.icon-reorder
.pull-right.hidden-xs
- = link_to "Sign in", new_session_path(:user, return_to: request.fullpath), class: 'btn btn-sign-in btn-new'
+ = link_to "Sign in", new_session_path(:user), class: 'btn btn-sign-in btn-new'
.navbar-collapse.collapse
%ul.nav.navbar-nav
%li.visible-xs
- = link_to "Sign in", new_session_path(:user, return_to: request.fullpath)
+ = link_to "Sign in", new_session_path(:user)
diff --git a/config/routes.rb b/config/routes.rb
index 244cb339898..f73fd7a87fa 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -160,7 +160,7 @@ Gitlab::Application.routes.draw do
resources :projects, constraints: { id: /[^\/]+/ }, only: [:new, :create]
- devise_for :users, controllers: { omniauth_callbacks: :omniauth_callbacks, registrations: :registrations , passwords: :passwords, sessions: :users_sessions }
+ devise_for :users, controllers: { omniauth_callbacks: :omniauth_callbacks, registrations: :registrations , passwords: :passwords, sessions: :sessions }
devise_scope :user do
get "/users/auth/:provider/omniauth_error" => "omniauth_callbacks#omniauth_error", as: :omniauth_error
diff --git a/features/project/redirects.feature b/features/project/redirects.feature
index 776ab83a876..a2e77e7bf30 100644
--- a/features/project/redirects.feature
+++ b/features/project/redirects.feature
@@ -31,3 +31,8 @@ Feature: Project Redirects
And I click on "Sign In"
And Authenticate
Then I should be redirected to "Community" page
+
+ Scenario: I visit private project page without signing in
+ When I visit project "Enterprise" page
+ And I get redirected to signin page where I sign in
+ Then I should be redirected to "Enterprise" page
diff --git a/features/steps/project/redirects.rb b/features/steps/project/redirects.rb
index 5a4342dba30..25d37fd7888 100644
--- a/features/steps/project/redirects.rb
+++ b/features/steps/project/redirects.rb
@@ -41,7 +41,6 @@ class Spinach::Features::ProjectRedirects < Spinach::FeatureSteps
step 'Authenticate' do
admin = create(:admin)
project = Project.find_by(name: 'Community')
- find(:xpath, "//input[@id='return_to']").set "/#{project.path_with_namespace}"
fill_in "user_login", with: admin.email
fill_in "user_password", with: admin.password
click_button "Sign in"
@@ -53,5 +52,19 @@ class Spinach::Features::ProjectRedirects < Spinach::FeatureSteps
page.current_path.should == "/#{project.path_with_namespace}"
page.status_code.should == 200
end
-end
+ step 'I get redirected to signin page where I sign in' do
+ admin = create(:admin)
+ project = Project.find_by(name: 'Enterprise')
+ fill_in "user_login", with: admin.email
+ fill_in "user_password", with: admin.password
+ click_button "Sign in"
+ Thread.current[:current_user] = admin
+ end
+
+ step 'I should be redirected to "Enterprise" page' do
+ project = Project.find_by(name: 'Enterprise')
+ page.current_path.should == "/#{project.path_with_namespace}"
+ page.status_code.should == 200
+ end
+end