调整Bot授权接口
This commit is contained in:
parent
c0fcf3445a
commit
1d9df770b5
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue