From c40777be2bcffefb380d3e667cde209108be0dd7 Mon Sep 17 00:00:00 2001 From: Jasder <2053003901@@qq.com> Date: Sun, 16 Aug 2020 00:54:22 +0800 Subject: [PATCH] FIX debug token --- app/controllers/concerns/login_helper.rb | 1 + app/controllers/oauth/educoder_controller.rb | 8 ++++---- app/models/token.rb | 4 ++++ 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/app/controllers/concerns/login_helper.rb b/app/controllers/concerns/login_helper.rb index 1752e4f6c..45d08a02b 100644 --- a/app/controllers/concerns/login_helper.rb +++ b/app/controllers/concerns/login_helper.rb @@ -11,6 +11,7 @@ module LoginHelper def set_autologin_cookie(user) token = Token.get_or_create_permanent_login_token(user, "autologin") + Rails.logger.info "###### def set_autologin_cookie and get_or_create_permanent_login_token result: #{token&.value}" cookie_options = { :value => token.value, :expires => 1.month.from_now, diff --git a/app/controllers/oauth/educoder_controller.rb b/app/controllers/oauth/educoder_controller.rb index bc1a0cb6d..87d8c8f8a 100644 --- a/app/controllers/oauth/educoder_controller.rb +++ b/app/controllers/oauth/educoder_controller.rb @@ -10,12 +10,12 @@ class Oauth::EducoderController < Oauth::BaseController open_user= OpenUsers::Educoder.find_by(uid: login) if open_user.present? && open_user.user.present? && open_user.user.email_binded? - if current_user != open_user.user - logout_user - successful_authentication(open_user.user) - end + Rails.logger.info "######## open_user exist and open_user.user exsit and email is binded ok" + successful_authentication(open_user.user) + redirect_to callback_url else + Rails.logger.info "######## open user not exits" if current_user.blank? || !current_user.logged? user = User.find_by(login: login) if user diff --git a/app/models/token.rb b/app/models/token.rb index cd61090be..d40388440 100644 --- a/app/models/token.rb +++ b/app/models/token.rb @@ -27,8 +27,10 @@ class Token < ActiveRecord::Base def self.get_or_create_permanent_login_token(user, type) token = Token.get_token_from_user(user, type) + Rails.logger.info "###### Token.get_token_from_user result: #{token&.value}" unless token token = Token.create(:user => user, :action => type) + Rails.logger.info "###### Token.get_token_from_user is nul and agine create token: #{token&.value}" else token.update_attribute(:created_on, Time.now) end @@ -37,8 +39,10 @@ class Token < ActiveRecord::Base def self.get_token_from_user(user, action) token = Token.where(:action => action, :user_id => user).first + Rails.logger.info "###### self.get_token_from_user query result: #{token&.value}" unless token token = Token.create!(user_id: user.id, action: action) + Rails.logger.info "###### self.get_token_from_user query is nil and create result: #{token&.value}" end token end