This commit is contained in:
rulingcom 2023-02-14 13:11:59 +08:00
parent f38a3aebcb
commit c50ed3c675
2 changed files with 36 additions and 4 deletions

View File

@ -3,7 +3,7 @@ class SsoLoginBoxController < SessionsController
OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
def oauth2_auth_page
session[:referer_url] = params[:referer_url]
redirect_to "https://portal.ncu.edu.tw/oauth2/authorization?response_type=#{ENV['RESPONSE_TYPE']}&client_id=#{ENV['APP_ID']}&redirect_uri=#{ENV['REDIRECT_URI']}&scope=identifier"
redirect_to "https://portal.ncu.edu.tw/oauth2/authorization?response_type=#{ENV['RESPONSE_TYPE']}&client_id=#{ENV['APP_ID']}&redirect_uri=#{ENV['REDIRECT_URI']}&scope=identifier chinese-name english-name gender birthday faculty-records email mobile-phone alternated-id"
end
def oauth2_sign_in
# receive code from ncu
@ -29,9 +29,41 @@ class SsoLoginBoxController < SessionsController
request.headers['Accept'] = 'application/json'
request.headers['Authorization'] = "#{token_response_json['token_type']} " + token
end
user_name = JSON.parse(account_response.body)['identifier']
data = JSON.parse(account_response.body) rescue {}
puts ["data", data]
user_name = data['identifier']
user = User.find_by(user_name: user_name) rescue nil
if !user.nil?
member = user.member_profile
if member
first_name_translations = member.first_name_translations
last_name_translations = member.last_name_translations
email = member.email
update_flag = false
if data["chineseName"].present?
if data["chineseName"].length == 3
last_name_translations["zh_tw"] = data["chineseName"][0]
first_name_translations["zh_tw"] = data["chineseName"][1..-1]
else
last_name_translations["zh_tw"] = ""
first_name_translations["zh_tw"] = data["chineseName"]
end
update_flag = true
end
# if data["englishName"].present?
# first_name_translations["en"] = ''
# last_name_translations["en"] = data["englishName"]
# update_flag = true
# end
if data['email'].present?
email = data['email']
update_flag = true
end
if update_flag
member.update_attributes(:first_name_translations=>first_name_translations, :last_name_translations=>last_name_translations, :email=>email)
end
end
# gender birthday faculty-records mobile-phone alternated-id
session[:user_id] = user.id
session[:login_referer] = nil
if session[:referer_url].present?

View File

@ -6,7 +6,7 @@ module SsoLoginBox::LoginTag
}
</style>
<div class=\"pull-right\">
<a class=\"sso_login_button btn\" href=\"/ncu_sso?referer_url=#{(URI.encode(OrbitHelper.request.original_url.gsub('?','&')) rescue "")}\" style=\"border: 0.1em solid black;\">
<a class=\"sso_login_button btn\" href=\"/ncu_sso?referer_url=#{(URI.encode(OrbitHelper.request.original_url) rescue "")}\" style=\"border: 0.1em solid black;\">
NCU SSO Login
</a>
</div>"