app/controllers/reception_controller.rb in tkh_authentication-0.9.8 vs app/controllers/reception_controller.rb in tkh_authentication-0.9.9

- old
+ new

@@ -1,9 +1,7 @@ class ReceptionController < ApplicationController - # FIXME - debugging mode now. The ajax call has messed conditions where I want HTML to be rendered. - # TODO change email address - may be a profile feature in tkh_mailing_list # TODO change password - "" # TODO localize the whole process before_action :set_target_page, only: [ :email_input, :parse_email, :email_validation, :create_your_password, :enter_your_password, :disconnect ] @@ -126,11 +124,12 @@ @user = User.find(params[:id]) if @user if @user.email_validated? if @user.authenticate(params[:user][:password]) login_the_user - redirect_to (session[:target_page] || root_url), notice: t('authentication.login_confirmation') + flash[:notice] = t('authentication.login_confirmation') + redirect_user_upon_successful_login destroy_target_page else # most likely wrong password flash.now.alert = t('authentication.warning.email_or_password_invalid') render "enter_your_password" end @@ -246,9 +245,22 @@ def login_the_user if params[:user][:remember_me].to_i == 1 cookies.permanent[:auth_token] = @user.auth_token else cookies[:auth_token] = @user.auth_token + end + end + + def redirect_user_upon_successful_login + if session[:target_page].present? + # add case when target pages is login page. + unless Rails.application.routes.recognize_path(session[:target_page])[:controller] == 'reception' + redirect_to session[:target_page] + else # the target page is the login or reception page + redirect_to root_url + end + else # no target page is set + redirect_to root_url end end end