|
|
|
@ -25,14 +25,11 @@ 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
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 企业开通
|
|
|
|
|
# applyno 申请单号,唯一
|
|
|
|
|
# ecordercode 唯一标志一个企业的订购关系
|
|
|
|
@ -117,6 +114,8 @@ class EcloudController < ApplicationController
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def ecloud_login_callback
|
|
|
|
|
|
|
|
|
|
unless params["test"] == 'true'
|
|
|
|
|
#获取code
|
|
|
|
|
logger.info "oauth2 login_callback: #{params}"
|
|
|
|
|
|
|
|
|
@ -127,29 +126,41 @@ class EcloudController < ApplicationController
|
|
|
|
|
|
|
|
|
|
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}
|
|
|
|
|
|
|
|
|
|
body = decode(res)
|
|
|
|
|
#{"access_token":"21a80f20ff736b54aecd002b60210943","token_type":"bearer","expires_in":86400,"refresh_token":"be92e2c137a8c6dd22f0d8c4a622b3aeceb054087a95d293130f04ec60fd3e3f","scope":"user_info","created_at":1542684088}
|
|
|
|
|
|
|
|
|
|
raise '登录失败' unless body["access_token"]
|
|
|
|
|
|
|
|
|
|
#获取此用户信息
|
|
|
|
|
|
|
|
|
|
# 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}"
|
|
|
|
|
# {"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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 同步用户
|
|
|
|
|
# info = decode(res)
|
|
|
|
|
#
|
|
|
|
|
# user = User.find_by_oschina_user_id(info["id"])
|
|
|
|
|
# unless user
|
|
|
|
|
# user = User.create_with_oschina!(info)
|
|
|
|
|
# end
|
|
|
|
|
#
|
|
|
|
|
# @current_user = user
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
render :index
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|