diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index a1a305a3b..11d4125b5 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -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 diff --git a/app/controllers/chapters_controller.rb b/app/controllers/chapters_controller.rb index 83362d9cf..535c64301 100644 --- a/app/controllers/chapters_controller.rb +++ b/app/controllers/chapters_controller.rb @@ -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 @@ -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 diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index 0cb6cab22..2c568e615 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -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 @@ -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 \ No newline at end of file diff --git a/config/locales/es.yml b/config/locales/es.yml index 7856312dd..01fd9db60 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -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 Expectativas? - 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"