fixed注册gitea

This commit is contained in:
xiaoxiaoqiong 2022-02-22 13:48:37 +08:00
parent 58ca8e2651
commit c1ea0232bb
2 changed files with 46 additions and 4 deletions

View File

@ -13,15 +13,15 @@ module RegisterHelper
user.platform = platform
user.phone = phone if phone.present?
user.activate
return unless user.valid?
interactor = Gitea::RegisterInteractor.call({username: username, email: email, password: password})
if interactor.success?
gitea_user = interactor.result
if interactor.success? || interactor.error.to_s.include?("已被注册")
gitea_user = interactor.error.to_s.include?("已被注册") ? Gitea::User::GetService.call(username, password) : interactor.result
result = Gitea::User::GenerateTokenService.call(username, password)
user.gitea_token = result['sha1']
user.gitea_uid = gitea_user[:body]['id']
user.gitea_uid = gitea_user[:body]['id'] if gitea_user[:body].present?
if user.save!
UserExtension.create!(user_id: user.id) if user.user_extension.blank?
result[:user] = {id: user.id, token: user.gitea_token}

View File

@ -0,0 +1,42 @@
class Gitea::User::GetService < Gitea::ClientService
attr_reader :username, :password
# params:
# username* string # required
def initialize(username, password = "")
@username = username
@password = password
end
def call
params = Hash.new.merge(token: token_params, data: params)
response = get(url, params)
status, message, body = render_response(response)
json_format(status, message, body)
end
private
def url
"/users/#{username}"
end
def token_params
{
username: username,
password: password
}
end
def params
{username: username}
end
def json_format(status, message, body)
case status
when 200 then success(body)
else
error(message, status)
end
end
end