diff --git a/app/controllers/sso_login_box_controller.rb b/app/controllers/sso_login_box_controller.rb index a7b04fc..4c4e091 100644 --- a/app/controllers/sso_login_box_controller.rb +++ b/app/controllers/sso_login_box_controller.rb @@ -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? @@ -45,4 +77,4 @@ class SsoLoginBoxController < SessionsController render "new" end end -end \ No newline at end of file +end diff --git a/lib/sso_login_box/login_tag.rb b/lib/sso_login_box/login_tag.rb index 7e05136..fc9f882 100644 --- a/lib/sso_login_box/login_tag.rb +++ b/lib/sso_login_box/login_tag.rb @@ -6,7 +6,7 @@ module SsoLoginBox::LoginTag }
- + NCU SSO Login
"