Commit 8da8efb3 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Merge branch 'redirect_on_signin' into 'master'

Redirect on signin

Fixes #1346

See merge request !965
parents f3b0cb77 3b80d68f
......@@ -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
......
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
class UsersSessionsController < Devise::SessionsController
def create
@return_to = params[:return_to]
super
end
end
......@@ -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"
......@@ -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)
......@@ -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
......
......@@ -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
......@@ -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
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment