В приложении My Rails при первом входе пользователя в приложение после подтверждения по электронной почте оно перенаправляется на
"/ users / translation"
evenпосле успешной аутентификации и входа в систему
Журналы
После регистрации нового пользователя -
Started GET "/users/sign_up" for 49.206.141.123 at 2018-10-16 15:29:10 +0200
Cannot render console from 49.206.141.123! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255
Processing by Devise::RegistrationsController#new as HTML
Rendering devise/registrations/new.html.erb within layouts/application
Rendered devise/shared/_links.html.erb (1.4ms)
Rendered devise/registrations/new.html.erb within layouts/application (51.1ms)
Rendered shared/_navbar.html.erb (3.4ms)
Rendered shared/_footer.html.erb (3.0ms)
Completed 200 OK in 117ms (Views: 114.9ms | ActiveRecord: 0.0ms)
Started POST "/users" for 49.206.141.123 at 2018-10-16 15:30:47 +0200
Cannot render console from 49.206.141.123! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255
Processing by Devise::RegistrationsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"zrMOtrXS1dl3hVyaDjQM/TousIdlc7iqFWpBsLUU02bx/GS1HFUEHCfSiGv7N/kSaZLUCFVzQi27Vz7QJf9fvQ==", "user"=>{"first_name"=>"user", "last_name"=>"first", "company"=>"testing", "country"=>"FR", "phone"=>"8765447854", "email"=>"usertesting@yopmail.com", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]"}, "commit"=>"Sign up"}
(0.4ms) BEGIN
User Exists (1.0ms) SELECT 1 AS one FROM `users` WHERE `users`.`email` = BINARY 'usertesting@yopmail.com' LIMIT 1
User Create (1.7ms) INSERT INTO `users` (`email`, `encrypted_password`, `created_at`, `updated_at`, `confirmation_token`, `confirmation_sent_at`, `company`, `first_name`, `last_name`, `country`, `phone`) VALUES ('usertesting@yopmail.com', '$2a$11$N3HFy8Ec7fdpoM4XgWjGS.WHv.UkQYy10pPFUD7Mz3g/.tjp48yTi', '2018-10-16 13:30:48', '2018-10-16 13:30:48', '75nwy8zh9bs_xxzqQ-JJ', '2018-10-16 13:30:48', 'testing', 'user', 'first', 'FR', '8765447854')
Rendering contact_mailer/send_new_user_message.html.erb within layouts/mailer
Rendered contact_mailer/send_new_user_message.html.erb within layouts/mailer (2.1ms)
ContactMailer#send_new_user_message: processed outbound mail in 23.1ms
User.rb
class User < ApplicationRecord
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable, :confirmable
end
Подтверждение электронной почты -
Started GET "/users/confirmation?confirmation_token=75nwy8zh9bs_xxzqQ-JJ" for 49.206.141.123 at 2018-10-16 15:37:12 +0200
Cannot render console from 49.206.141.123! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255
Processing by Devise::ConfirmationsController#show as HTML
Parameters: {"confirmation_token"=>"75nwy8zh9bs_xxzqQ-JJ"}
User Load (1.2ms) SELECT `users`.* FROM `users` WHERE `users`.`confirmation_token` = '75nwy8zh9bs_xxzqQ-JJ' ORDER BY `users`.`id` ASC LIMIT 1
(0.2ms) BEGIN
User Update (0.8ms) UPDATE `users` SET `confirmed_at` = '2018-10-16 13:37:12', `updated_at` = '2018-10-16 13:37:12' WHERE `users`.`id` = 26
(2.1ms) COMMIT
Redirected to http://173.212.237.245:3010/users/sign_in
Completed 302 Found in 18ms (ActiveRecord: 4.3ms)
Started GET "/users/sign_in" for 49.206.141.123 at 2018-10-16 15:37:12 +0200
Cannot render console from 49.206.141.123! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255
Processing by Devise::SessionsController#new as HTML
Rendering devise/sessions/new.html.erb within layouts/application
Rendered devise/shared/_links.html.erb (3.1ms)
Rendered devise/sessions/new.html.erb within layouts/application (12.6ms)
Rendered shared/_navbar.html.erb (6.6ms)
Rendered shared/_footer.html.erb (8.0ms)
Completed 200 OK in 169ms (Views: 164.3ms | ActiveRecord: 0.0ms)
Самый первый пользователь, входящий в приложение
Started POST "/users/sign_in" for 49.206.141.123 at 2018-10-16 15:42:24 +0200
Cannot render console from 49.206.141.123! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255
Processing by Devise::SessionsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"zLqBZuAIj2tSPS62q6dR6fe56mGWKdALO79kvQ6Rc2zz9etlSY9ergJq+kdepKQGpAWO7qYpKoyVghvdnnr/tw==", "user"=>{"email"=>"usertesting@yopmail.com", "password"=>"[FILTERED]", "remember_me"=>"0"}, "commit"=>"Log in"}
User Load (0.6ms) SELECT `users`.* FROM `users` WHERE `users`.`email` = 'usertesting@yopmail.com' ORDER BY `users`.`id` ASC LIMIT 1
(0.3ms) BEGIN
User Update (0.6ms) UPDATE `users` SET `current_sign_in_at` = '2018-10-16 13:42:24', `last_sign_in_at` = '2018-10-16 13:42:24', `current_sign_in_ip` = '49.206.141.123', `last_sign_in_ip` = '49.206.141.123', `sign_in_count` = 1, `updated_at` = '2018-10-16 13:42:24' WHERE `users`.`id` = 26
(1.9ms) COMMIT
Redirected to http://173.212.237.245:3010/users/confirmation
Completed 302 Found in 187ms (ActiveRecord: 3.5ms)
Started GET "/users/confirmation" for 49.206.141.123 at 2018-10-16 15:42:25 +0200
Cannot render console from 49.206.141.123! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255
Processing by Devise::ConfirmationsController#show as HTML
User Load (0.6ms) SELECT `users`.* FROM `users` WHERE `users`.`confirmation_token` = '' ORDER BY `users`.`id` ASC LIMIT 1
Rendering devise/confirmations/new.html.erb within layouts/application
Rendered devise/shared/_links.html.erb (3.5ms)
Rendered devise/confirmations/new.html.erb within layouts/application (11.0ms)
User Load (0.5ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 26 ORDER BY `users`.`id` ASC LIMIT 1
Rendered shared/_navbar.html.erb (7.3ms)
Rendered shared/_footer.html.erb (4.6ms)
Completed 200 OK in 154ms (Views: 146.9ms | ActiveRecord: 1.2ms)
application_controller.rb
class ApplicationController < ActionController::Base
before_action :persist_last_visited_path
private
def persist_last_visited_path
unless Rails.configuration.ignored_paths.include?(request.path) || request.xhr?
session[:last_visited_path] = request.path
end
end
def after_sign_in_path_for(resource)
if session[:last_visited_path].present?
session[:last_visited_path]
else
root_path
end
end
end
Чтобы перенаправить на последний просмотренный путь пользователя после входа в систему, я добавил вышеуказанный фрагмент кода.
config / application.rb
require_relative 'boot'
require 'rails/all'
Bundler.require(*Rails.groups)
module Test
class Application < Rails::Application
config.load_defaults 5.2
config.ignored_paths = %W(/users/sign_in /users/sign_up /users/password /users/sign_out /users/confirm_password users/confirmation)
end
end
Перенаправление на «/ users / подтверждение» происходит только при первом успешном входе пользователя в систему
Если тот же пользователь успешно выполнит вход в следующий раз, это не вызывает никаких проблем.
Любая помощь высоко ценится. Заранее спасибо.