From bdbfedfb230009b30ed2c07acd1c0cc47910a3ce Mon Sep 17 00:00:00 2001 From: joshua stein Date: Fri, 8 Aug 2014 10:31:06 -0500 Subject: [PATCH] for normal requests to /login, save the referrer and redir back there properly closes #164 --- app/controllers/login_controller.rb | 15 +++++++++++++-- app/views/login/index.html.erb | 4 ++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/app/controllers/login_controller.rb b/app/controllers/login_controller.rb index 536c447..6d5c955 100644 --- a/app/controllers/login_controller.rb +++ b/app/controllers/login_controller.rb @@ -11,6 +11,7 @@ class LoginController < ApplicationController def index @title = "Login" + @referer ||= request.referer render :action => "index" end @@ -28,12 +29,22 @@ class LoginController < ApplicationController if (rd = session[:redirect_to]).present? session.delete(:redirect_to) return redirect_to rd - else - return redirect_to "/" + elsif params[:referer].present? + begin + ru = URI.parse(params[:referer]) + if ru.host == Rails.application.domain + return redirect_to ru.to_s + end + rescue => e + Rails.logger.error "error parsing referer: #{e}" + end end + + return redirect_to "/" end flash.now[:error] = "Invalid e-mail address and/or password." + @referer = params[:referer] index end diff --git a/app/views/login/index.html.erb b/app/views/login/index.html.erb index 7cd7a18..90e58b3 100644 --- a/app/views/login/index.html.erb +++ b/app/views/login/index.html.erb @@ -29,5 +29,9 @@ ask them for an invitation or request one publicly.

+ + <% if @referer.present? %> + <%= hidden_field_tag :referer, @referer %> + <% end %> <% end %>