Skip to content

Commit

Permalink
Merge pull request #422 from mumuki/feature-redirect-is-back
Browse files Browse the repository at this point in the history
Redirect is back
  • Loading branch information
fedescarpa committed Jan 22, 2016
2 parents f1efce9 + e234d89 commit a5657ac
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 6 deletions.
18 changes: 17 additions & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,23 @@ def set_locale

private

def subject
def subject #TODO may be used to remove breadcrumbs duplication
nil
end

def visitor_recurrent?
current_user? && current_user.last_guide.present?
end

def visitor_comes_from_internet?
!request_host_include? %w(mumuki localmumuki)
end

def request_host_include?(hosts)
hosts.any? { |host| Addressable::URI.parse(request.referer).host.include? host } rescue false
end

def redirect_to_last_guide
redirect_to current_user.last_guide, notice: t(:welcome_back_after_redirection)
end
end
15 changes: 15 additions & 0 deletions app/controllers/chapters_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
require 'addressable/uri'

class ChaptersController < ApplicationController
before_action :redirect_to_last_guide_if_possible, only: :index

def show
@chapter = Chapter.find(params[:id])
end
Expand All @@ -10,4 +14,15 @@ def index
def subject
@chapter
end

private

def redirect_to_last_guide_if_possible
redirect_to_last_guide if should_redirect?
end

def should_redirect?
visitor_recurrent? && visitor_comes_from_internet?
end

end
13 changes: 9 additions & 4 deletions app/controllers/sessions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ def callback
user = User.omniauth(env['omniauth.auth'])
remember_me_token.value = user.remember_me_token

redirect_to redirect_after_login_path
redirect_after_login
end

def failure
Expand All @@ -16,9 +16,14 @@ def destroy
end


def redirect_after_login_path
redirect_after_login = session[:redirect_after_login] || :back
def redirect_after_login
path = session[:redirect_after_login] || :back
session[:redirect_after_login] = nil
redirect_after_login

if visitor_recurrent? && path == root_path
redirect_to_last_guide
else
redirect_to path
end
end
end
2 changes: 1 addition & 1 deletion config/locales/es.yml
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ es:
you_must_sign_in_before_submitting: Tenés que iniciar sesión antes de empezar a enviar tus soluciones
you_must_sign_in_to_see_stats: Necesitás iniciar sesión para ver más estadísticas sobre tu progreso
what_exactly_are_expectations_html: ¿Qué son concretamente las <a href="http://www.mumuki.org/expectativas/plataform/2015/06/16/el-lenguaje-de-expectativas/">Expectativas</a>?
welcome_back_after_redirection: "¡Qué bueno verte de nuevo! Aquí es donde estuviste la última vez"
welcome_back_after_redirection: "¡Qué bueno verte de nuevo! Acá es donde estuviste la última vez"
need_a_hint: "¿Necesitás ayuda?"
about: "Detalles"
sending_solution: "Enviando solución"
Expand Down

0 comments on commit a5657ac

Please sign in to comment.