Updated.
This commit is contained in:
parent
f38a3aebcb
commit
c50ed3c675
|
@ -3,7 +3,7 @@ class SsoLoginBoxController < SessionsController
|
||||||
OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
|
OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
|
||||||
def oauth2_auth_page
|
def oauth2_auth_page
|
||||||
session[:referer_url] = params[:referer_url]
|
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
|
end
|
||||||
def oauth2_sign_in
|
def oauth2_sign_in
|
||||||
# receive code from ncu
|
# receive code from ncu
|
||||||
|
@ -29,9 +29,41 @@ class SsoLoginBoxController < SessionsController
|
||||||
request.headers['Accept'] = 'application/json'
|
request.headers['Accept'] = 'application/json'
|
||||||
request.headers['Authorization'] = "#{token_response_json['token_type']} " + token
|
request.headers['Authorization'] = "#{token_response_json['token_type']} " + token
|
||||||
end
|
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
|
user = User.find_by(user_name: user_name) rescue nil
|
||||||
if !user.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[:user_id] = user.id
|
||||||
session[:login_referer] = nil
|
session[:login_referer] = nil
|
||||||
if session[:referer_url].present?
|
if session[:referer_url].present?
|
||||||
|
@ -45,4 +77,4 @@ class SsoLoginBoxController < SessionsController
|
||||||
render "new"
|
render "new"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -6,7 +6,7 @@ module SsoLoginBox::LoginTag
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
<div class=\"pull-right\">
|
<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
|
NCU SSO Login
|
||||||
</a>
|
</a>
|
||||||
</div>"
|
</div>"
|
||||||
|
|
Loading…
Reference in New Issue