|
|
|
@ -38,8 +38,6 @@ class EcloudController < ApplicationController
|
|
|
|
|
ROOT_URl = 'http://localhost:3000'
|
|
|
|
|
SERVER_URL = "https://221.176.54.92:9081/restful/services/"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## 签名
|
|
|
|
|
def sign(timestamp)
|
|
|
|
|
Digest::MD5.hexdigest("client_id=#{CLIENT_ID}client_key=#{CLIENT_SECRET}timestamp=#{timestamp}").upcase
|
|
|
|
@ -174,39 +172,53 @@ class EcloudController < ApplicationController
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def ecloud_login_callback
|
|
|
|
|
#获取code
|
|
|
|
|
logger.info "oauth2 login_callback: #{params}"
|
|
|
|
|
|
|
|
|
|
raise "没有code" unless params[:code]
|
|
|
|
|
unless params["test"] == 'true'
|
|
|
|
|
#获取code
|
|
|
|
|
logger.info "oauth2 login_callback: #{params}"
|
|
|
|
|
|
|
|
|
|
url = "#{SERVER_URL}/oauth2/authorization?grant_type=authorization_code" +
|
|
|
|
|
"&client_id=#{CLIENT_ID}&scope=&redirect_uri=&code=#{params[:code]}"
|
|
|
|
|
raise "没有code" unless params[:code]
|
|
|
|
|
|
|
|
|
|
res = post(url)
|
|
|
|
|
logger.info "oauth2 authorization resp: #{res}"
|
|
|
|
|
url = "#{SERVER_URL}/oauth2/authorization?grant_type=authorization_code" +
|
|
|
|
|
"&client_id=#{CLIENT_ID}&scope=&redirect_uri=&code=#{params[:code]}"
|
|
|
|
|
|
|
|
|
|
body = decode(res)
|
|
|
|
|
#{"access_token":"21a80f20ff736b54aecd002b60210943","token_type":"bearer","expires_in":86400,"refresh_token":"be92e2c137a8c6dd22f0d8c4a622b3aeceb054087a95d293130f04ec60fd3e3f","scope":"user_info","created_at":1542684088}
|
|
|
|
|
res = post(url)
|
|
|
|
|
logger.info "oauth2 authorization resp: #{res}"
|
|
|
|
|
# {"access_token":"ae673b2d-88b4-46cc-aa74-0b031f24b76f","expires":6,"refresh_token":"7380cc67-a59c-4c21-9000-70e12a58d175","username":"15111030087@QW_er","uid":2147}
|
|
|
|
|
|
|
|
|
|
raise '登录失败' unless body["access_token"]
|
|
|
|
|
body = decode(res)
|
|
|
|
|
|
|
|
|
|
#获取此用户信息
|
|
|
|
|
raise '登录失败' unless body["access_token"]
|
|
|
|
|
|
|
|
|
|
#获取此用户信息
|
|
|
|
|
res = get("#{SERVER_URL}/user/info?access_token=#{body['access_token']}&userid=#{body['uid']}")
|
|
|
|
|
logger.info "oauth2 get user info: #{res}"
|
|
|
|
|
# {"userid":2147,"custid":2104,"custcode":"E0002018042810010054","custtype":2,"status":2,"username":"15111030087@QW_er","useralias":"15111030087","isadmin":true,"entprise":"04**004","departments":"","departmentnames":"","mobile":"15365386520","email":"15111030087@139.com"}
|
|
|
|
|
else
|
|
|
|
|
res = '{"userid":2147,"custid":2104,"custcode":"E0002018042810010054","custtype":2,"status":2,"username":"15111030087@QW_er","useralias":"15111030087","isadmin":true,"entprise":"04**004","departments":"","departmentnames":"","mobile":"15365386520","email":"15111030087@139.com"}'
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# res = get("https://gitee.com/api/v5/user?access_token=#{body["access_token"]}")
|
|
|
|
|
res = get("#{SERVER_URL}/user/info?access_token=#{body['access_token']}&userid=#{body['uid']}")
|
|
|
|
|
logger.info "oauth2 get user info: #{res}"
|
|
|
|
|
|
|
|
|
|
# 同步用户
|
|
|
|
|
# info = decode(res)
|
|
|
|
|
#
|
|
|
|
|
# user = User.find_by_oschina_user_id(info["id"])
|
|
|
|
|
# unless user
|
|
|
|
|
# user = User.create_with_oschina!(info)
|
|
|
|
|
# end
|
|
|
|
|
#
|
|
|
|
|
# @current_user = user
|
|
|
|
|
|
|
|
|
|
render :index
|
|
|
|
|
info = decode(res)
|
|
|
|
|
|
|
|
|
|
user = User.find_by_ecoder_user_id(info["userid"])
|
|
|
|
|
unless user
|
|
|
|
|
#新建用户
|
|
|
|
|
user = User.create_with_ecoder!(info)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
self.logged_user = user
|
|
|
|
|
|
|
|
|
|
user = UserExtensions.where(:user_id => User.current.id).first
|
|
|
|
|
if user.gender.nil? || user.school_id.nil? || User.current.lastname.nil?
|
|
|
|
|
redirect_to my_account_path
|
|
|
|
|
elsif user.identity == 3 && user.school_id.nil?
|
|
|
|
|
redirect_to my_account_path
|
|
|
|
|
else
|
|
|
|
|
redirect_to User.current
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|