|
|
|
@ -154,9 +154,9 @@ class OauthController < ApplicationController
|
|
|
|
|
####--Start-- 获取Openi的授权码,access_token,以及用户信息。为在openi登录的用户创建相关的educoder用户 ####
|
|
|
|
|
IDENTITY_SITE = Redmine::Configuration['openi_domain']
|
|
|
|
|
ROOT_URL = Redmine::Configuration['educoder_domain']
|
|
|
|
|
DEFAULT_PASSWORD = "a12345678"
|
|
|
|
|
TOKEN_CALL_BACK = "/oauth/get_token_callback"
|
|
|
|
|
USER_INFO = "/oauth/userinfo"
|
|
|
|
|
DEFAULT_PASSWORD = 'a12345678'.freeze
|
|
|
|
|
TOKEN_CALL_BACK = '/oauth/get_token_callback'.freeze
|
|
|
|
|
USER_INFO = '/oauth/userinfo'.freeze
|
|
|
|
|
|
|
|
|
|
def get_code
|
|
|
|
|
# 从OpenI发过来的回调中获取授权码
|
|
|
|
@ -183,6 +183,10 @@ class OauthController < ApplicationController
|
|
|
|
|
openi = Openi.find_by_login(login)
|
|
|
|
|
unless openi
|
|
|
|
|
ActiveRecord::Base.transaction do
|
|
|
|
|
# 如果Educoder中已存在与该OpenI用户的邮箱相同的用户,则会直接跳转到登录educoder的登录页面
|
|
|
|
|
existing_user = User.find_by_mail(email)
|
|
|
|
|
break if existing_user.present?
|
|
|
|
|
|
|
|
|
|
user = User.new(lastname: name, mail: email, mail_notification: email)
|
|
|
|
|
user.login = custom_openi_login(login)
|
|
|
|
|
user.password = DEFAULT_PASSWORD
|
|
|
|
@ -196,7 +200,7 @@ class OauthController < ApplicationController
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
self.logged_user = openi.user
|
|
|
|
|
self.logged_user = openi.user if openi.present? && openi.user.present?
|
|
|
|
|
original_url = params[:original_url]
|
|
|
|
|
redirect_to original_url
|
|
|
|
|
end
|
|
|
|
@ -208,7 +212,7 @@ class OauthController < ApplicationController
|
|
|
|
|
private
|
|
|
|
|
# 为了保证新创建的用户用户名不与系统中已存在的用户冲突,加上 _openi 后缀
|
|
|
|
|
def custom_openi_login(login)
|
|
|
|
|
login + "_openi"
|
|
|
|
|
login + '_openi'
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def require_login
|
|
|
|
|