同步bot信息,回调地址和名称

This commit is contained in:
xxq250 2023-03-29 17:29:42 +08:00
parent 7045fb3960
commit 3d61b920ac
1 changed files with 8 additions and 2 deletions

View File

@ -38,10 +38,16 @@ class InstallationsController < ApplicationController
render_ok
end
# 同步bot信息回调地址和名称
def update_callback_url
bot = Bot.find params[:id]
application = Doorkeeper::Application.find_by(uid: bot.client_id, secret: bot.client_secret)
# application.redirect_uri = bot.callback_url
application.redirect_uri = bot.oauth_callback_url
application.name = bot.name
if bot.uid.present?
bot_user = User.find_by(id: bot.uid)
bot_user.update_column(:nickname, bot.name) if bot_user.present?
end
application.save
render_ok
end
@ -66,7 +72,7 @@ class InstallationsController < ApplicationController
@bot.owner_id = current_user.id
ActiveRecord::Base.transaction do
# 注册bot对应oauth应用
Doorkeeper::Application.create!(name: @bot.name, uid: @bot.client_id, secret: @bot.client_secret, redirect_uri: "https://gitlink.org.cn")
Doorkeeper::Application.create!(name: @bot.name, uid: @bot.client_id, secret: @bot.client_secret, redirect_uri: @bot.oauth_callback_url)
# 注册bot对应用户
result = autologin_register(User.generate_user_login('b'), nil, "#{SecureRandom.hex(6)}", 'bot', nil, @bot.name)
tip_exception(-1, result[:message]) if result[:message].present?