Browse Source

新增:acge 第三方登录回调地址

pull/347/head
yystopf 2 years ago
parent
commit
e891d52c32
3 changed files with 60 additions and 0 deletions
  1. +32
    -0
      app/controllers/oauth/acge_controller.rb
  2. +27
    -0
      app/models/open_users/acge.rb
  3. +1
    -0
      config/routes.rb

+ 32
- 0
app/controllers/oauth/acge_controller.rb View File

@@ -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

+ 27
- 0
app/models/open_users/acge.rb View File

@@ -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

+ 1
- 0
config/routes.rb View File

@@ -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'


Loading…
Cancel
Save