From 1d9df770b516d9804476c441b94d473bc17ac413 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Thu, 16 Feb 2023 09:41:39 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4Bot=E6=8E=88=E6=9D=83?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/installations_controller.rb | 31 +++++++++++---------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/app/controllers/installations_controller.rb b/app/controllers/installations_controller.rb index 5d6a26836..40efa3c90 100644 --- a/app/controllers/installations_controller.rb +++ b/app/controllers/installations_controller.rb @@ -7,21 +7,22 @@ class InstallationsController < ApplicationController end def auth_active - @bot = Bot.find params[:id] - @bot.client_id = Doorkeeper::OAuth::Helpers::UniqueToken.generate if params[:client_id].blank? - @bot.client_secret = Doorkeeper::OAuth::Helpers::UniqueToken.generate if params[:client_secret].blank? - @bot.private_key = OpenSSL::PKey::RSA::generate(2048).to_s - @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") - # 注册bot对应用户 - result = autologin_register(User.generate_user_login('b'), nil, "b58333123413", 'bot', nickname: @bot.name) - tip_exception(-1, result[:message]) if result[:message].present? - @bot.uid = result[:user][:id] - @bot.save - render_ok - end + begin + @bot = Bot.find params[:id] + @bot.client_id = Doorkeeper::OAuth::Helpers::UniqueToken.generate if params[:client_id].blank? + @bot.client_secret = Doorkeeper::OAuth::Helpers::UniqueToken.generate if params[:client_secret].blank? + @bot.private_key = OpenSSL::PKey::RSA::generate(2048).to_s + @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") + # 注册bot对应用户 + result = autologin_register(User.generate_user_login('b'), nil, "b58333123413", 'bot', nickname: @bot.name) + tip_exception(-1, result[:message]) if result[:message].present? + @bot.uid = result[:user][:id] + @bot.save + render_ok + end rescue Exception => e tip_exception(-1, e.message) end