fixed 增加自动登录

This commit is contained in:
xiaoxiaoqiong 2022-05-24 10:25:58 +08:00
parent 0ae3544235
commit 2959414d56
2 changed files with 47 additions and 44 deletions

View File

@ -8,7 +8,7 @@ class UsersController < ApplicationController
before_action :connect_to_ci_db, only: [:get_user_info]
before_action :convert_image!, only: [:update, :update_image]
skip_before_action :check_sign, only: [:attachment_show]
# before_action :sso_login, only: [:get_user_info]
before_action :sso_login, only: [:get_user_info]
def connect_to_ci_db(options={})
if !(current_user && !current_user.is_a?(AnonymousUser) && current_user.devops_certification?)
@ -331,26 +331,29 @@ class UsersController < ApplicationController
end
def sso_login
if params[:ticket].present? && !current_user.logged? && params[:websiteName].nil?
info = Base64.decode64(params[:ticket]) || Base64.decode64(params[:info].gsub(" ", "+")).force_encoding("utf-8")
# login 邮箱 手机号 姓名 学校/单位
user_info = info.split("&&")
# Rails.logger.info("user_info====== #{info}")
login = user_info[0]
email = user_info[1]
phone = user_info[2]
real_name = user_info[3]
department_name = user_info[4]
if params[:login].present? && !current_user.logged? && params[:websiteName].nil?
params = { "login" => "#{params[:login]}", "private_token" => "hriEn3UwXfJs3PmyXnSH" }
api_url= "https://pre-data.educoder.net"
client = Faraday.new(url: api_url)
response = client.public_send("get", "/api/sources/get_user_info_by_login", params)
result = JSON.parse(response.body)
# 没有登录时,新建用户并登录
if current_user.logged?
user = current_user
else
user = User.where("login = ? or phone = ? or mail = ? ", "edu_#{login}", phone, email).first
if result["status"].to_s == "0"
# login 邮箱 手机号 姓名 学校/单位
user_info = result["data"]
Rails.logger.info("user_info====== #{user_info}")
login = user_info["login"]
email = user_info["mail"]
phone = user_info["phone"]
real_name = user_info["username"]
department_name = user_info["school"]
# 没有用户时,新建用户并登录
user = User.where("login = ? or phone = ? or mail = ? ", "#{login}", phone, email).first
unless user
ActiveRecord::Base.transaction do
phone_rand = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9].sample(4).join
user_params = { status: 1, type: 'User', login: "e_#{login}", lastname: "#{real_name}", mail: "#{email}",
user_params = { status: 1, type: 'User', login: "#{login}", lastname: "#{real_name}", mail: "#{email}",
nickname: "#{real_name}", professional_certification: 0, certification: 0, grade: 0,
password: "12345678", phone: "#{phone_rand}", profile_completed: 1 }
user = User.create!(user_params)

View File

@ -1,28 +1,28 @@
json.username @user.full_name
json.real_name @user.real_name
json.nickname @user.nickname
json.gender @user.gender
json.login @user.login
json.user_id @user.id
json.image_url url_to_avatar(@user)
json.admin @user.admin?
json.is_teacher @user.user_extension&.teacher?
json.user_identity @user.identity
json.tidding_count 0
json.user_phone_binded @user.phone.present?
json.need_edit_info @user.need_edit_info?
# json.phone @user.phone
# json.email @user.mail
json.profile_completed @user.profile_is_completed?
json.professional_certification @user.professional_certification
json.devops_step @user.devops_step
json.ci_certification @user.ci_certification?
json.email @user.mail
json.province @user.province
json.city @user.city
json.custom_department @user.custom_department
json.description @user.description
json.super_description @user.super_description
json.(@user, :show_email, :show_department, :show_location, :show_super_description)
json.message_unread_total @message_unread_total
json.username @user.full_name
json.real_name @user.real_name
json.nickname @user.nickname
json.gender @user.gender
json.login @user.login
json.user_id @user.id
json.image_url url_to_avatar(@user)
json.admin @user.admin?
json.is_teacher @user.user_extension&.teacher?
json.user_identity @user.identity
json.tidding_count 0
json.user_phone_binded @user.phone.present?
json.need_edit_info @user.need_edit_info?
json.phone @user.phone
# json.email @user.mail
json.profile_completed @user.profile_is_completed?
json.professional_certification @user.professional_certification
json.devops_step @user.devops_step
json.ci_certification @user.ci_certification?
json.email @user.mail
json.province @user.province
json.city @user.city
json.custom_department @user.custom_department
json.description @user.description
json.super_description @user.super_description
json.(@user, :show_email, :show_department, :show_location, :show_super_description)
json.message_unread_total @message_unread_total
json.has_trace_user @user.trace_user.present?