Merge branch 'dev_change_route' into dev_devops

This commit is contained in:
Jasder 2020-08-14 23:25:10 +08:00
commit dac91f9a0c
3 changed files with 30 additions and 12 deletions

View File

@ -10,18 +10,22 @@ class Oauth::EducoderController < Oauth::BaseController
open_user= OpenUsers::Educoder.find_by(uid: login)
if open_user.present? && open_user.user.present? && open_user.user.email_binded?
# 存在说明绑定了,验证信息是否齐全,
if current_user != open_user.user
logout_user
successful_authentication(open_user.user)
end
redirect_to callback_url
else
# 未存在需要进行绑定
if current_user.blank? || !current_user.logged?
# forge平台未登录
redirect_to oauth_register_path(login: login, callback_url: callback_url)
user = User.find_by(login: login)
if user
successful_authentication(user)
OpenUsers::Educoder.create!(user: user, uid: user.login)
redirect_to callback_url
else
redirect_to oauth_register_path(login: login, callback_url: callback_url)
end
else
# forge平台已登录
OpenUsers::Educoder.create!(user: current_user, uid: login)

View File

@ -55,22 +55,27 @@ class OauthController < ApplicationController
end
def register
logger.info "=====auto_register=======login: #{params[:login]}"
logger.info "=====auto_register=======callback_url: #{params[:callback_url]}"
# redirect_to params[:callback_url]
end
def auto_register
login = params[:login]
email = params[:mail]
password = params[:password]
callback_url = params[:callback_url]
platform = params[:plathform] || 'forge'
result = autologin_register(login, email, password, platform)
logger.info "[Oauth educoer] =====#{result}"
if result[:message].blank?
redirect_to params[:callback_url]
logger.info "[Oauth educoer] ====auto_register success"
user = User.find result[:user][:id]
successful_authentication(user)
OpenUsers::Educoder.create!(user: user, uid: user.login)
render_ok({callback_url: callback_url})
# redirect_to callback_url
else
logger.info "[Oauth educoer] ====auto_register failed."
render :action => "auto_register"
end
end

View File

@ -52,7 +52,16 @@
$.ajax({
url: "<%= oauth_auto_register_path %>",
data: $("#oauth_form").serialize(),
type: 'post'
})
type: 'post',
dataType: "json",
success: function(data) {
console.log(data)
if (data) {
// data.redirect contains the string URL to redirect to
// window.location.href = "<%#= params[:callback_url] %>";
window.location.href = data.callback_url;
}
}
});
}
</script>