diff --git a/app/controllers/oauth/acge_controller.rb b/app/controllers/oauth/acge_controller.rb new file mode 100644 index 000000000..5afc57c6b --- /dev/null +++ b/app/controllers/oauth/acge_controller.rb @@ -0,0 +1,32 @@ +class Oauth::AcgeController < Oauth::BaseController + include RegisterHelper + + def create + begin + code = params['code'].to_s.strip + tip_exception("code不能为空") if code.blank? + uid = params['uid'].to_s.strip + tip_exception("uid不能为空") if uid.blank? + redirect_uri = params['redirect_uri'].to_s.strip + tip_exception("redirect_uri不能为空") if redirect_uri.blank? + + open_user = OpenUsers::Acge.find_by(uid: uid) + if open_user.present? && open_user.user.present? + successful_authentication(open_user.user) + redirect_to redirect_uri + return + else + if current_user.blank? || !current_user.logged? + session[:unionid] = uid + else + OpenUsers::Acge.create!(user: current_user, uid: uid) + end + end + + Rails.logger.info("[OAuth2] session[:unionid] -> #{session[:unionid]}") + redirect_to "/bindlogin/acge?redirect_uri=#{redirect_uri}" + rescue Exception => ex + render_error(ex.message) + end + end +end \ No newline at end of file diff --git a/app/models/open_users/acge.rb b/app/models/open_users/acge.rb new file mode 100644 index 000000000..59963b91f --- /dev/null +++ b/app/models/open_users/acge.rb @@ -0,0 +1,27 @@ +# == Schema Information +# +# Table name: open_users +# +# id :integer not null, primary key +# user_id :integer +# type :string(255) +# uid :string(255) +# created_at :datetime not null +# updated_at :datetime not null +# extra :text(65535) +# +# Indexes +# +# index_open_users_on_type_and_uid (type,uid) UNIQUE +# index_open_users_on_user_id (user_id) +# + +class OpenUsers::Acge < OpenUser + def nickname + extra&.[]('nickname') + end + + def en_type + 'acge' + end +end diff --git a/config/routes.rb b/config/routes.rb index a165a3d1e..b5f5c75ca 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -24,6 +24,7 @@ Rails.application.routes.draw do # get 'auth/qq/callback', to: 'oauth/qq#create' get 'auth/failure', to: 'oauth/base#auth_failure' get 'auth/cas/callback', to: 'oauth/cas#create' + get 'auth/acge/callback', to: "oauth/acge#create" get 'auth/:provider/callback', to: 'oauth/callbacks#create' get 'oauth/bind', to: 'oauth/educoder#bind'