diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index ad65bd13935..d58890fa33b 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,7 +1,6 @@ require 'gon' class ApplicationController < ActionController::Base - before_filter :store_location before_filter :authenticate_user! before_filter :reject_blocked! before_filter :check_password_expiration @@ -49,18 +48,7 @@ class ApplicationController < ActionController::Base flash[:alert] = "Your account is blocked. Retry when an admin has unblocked it." new_user_session_path else - session[:previous_url] || root_path - end - end - - def store_location - # store last url - this is needed for post-login redirect to whatever the user last visited. - if (request.fullpath != "/users/sign_in" && - request.fullpath != "/users/sign_up" && - request.fullpath != "/users/password" && - request.fullpath != "/users/sign_out" && - !request.xhr?) # don't store ajax calls - session[:previous_url] = request.fullpath + @return_to || root_path end end diff --git a/app/controllers/users_sessions_controller.rb b/app/controllers/users_sessions_controller.rb new file mode 100644 index 00000000000..656c92376fd --- /dev/null +++ b/app/controllers/users_sessions_controller.rb @@ -0,0 +1,6 @@ +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 a2f85fa3fe2..989fcb4a63f 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-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 63992a22f32..25984df0444 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), class: 'btn btn-sign-in btn-new' + = link_to "Sign in", new_session_path(:user, return_to: request.fullpath), 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) + = link_to "Sign in", new_session_path(:user, return_to: request.fullpath) diff --git a/config/routes.rb b/config/routes.rb index 746e532a0ec..779cbad709c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -157,7 +157,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} + devise_for :users, controllers: { omniauth_callbacks: :omniauth_callbacks, registrations: :registrations , passwords: :passwords, sessions: :users_sessions } # # Project Area diff --git a/features/project/redirects.feature b/features/project/redirects.feature index 1f85bab71f1..10e5fbf55c7 100644 --- a/features/project/redirects.feature +++ b/features/project/redirects.feature @@ -28,5 +28,5 @@ Feature: Project Redirects Scenario: I visit a public project without signing in When I visit project "Community" page And I should see project "Community" home page - And I sign in as a user + And I click on "Sign In" Then I should be redirected to "Community" page diff --git a/features/steps/project/redirects.rb b/features/steps/project/redirects.rb index 16c32a4d56a..2ce0e836119 100644 --- a/features/steps/project/redirects.rb +++ b/features/steps/project/redirects.rb @@ -32,6 +32,10 @@ class Spinach::Features::ProjectRedirects < Spinach::FeatureSteps visit project_path(project) + 'DoesNotExist' end + step 'I click on "Sign In"' do + click_link "Sign in" + end + step 'I should be redirected to "Community" page' do project = Project.find_by(name: 'Community') page.current_path.should == "/#{project.path_with_namespace}"