FIX generate token bug for regitster api
This commit is contained in:
parent
32a52a5c7a
commit
50021a278b
|
@ -12,7 +12,7 @@ module RegisterHelper
|
|||
interactor = Gitea::RegisterInteractor.call({username: username, email: email, password: password})
|
||||
if interactor.success?
|
||||
gitea_user = interactor.result
|
||||
result = Gitea::User::GenerateTokenService.new(username, password).call
|
||||
result = Gitea::User::GenerateTokenService.call(username, password)
|
||||
user.gitea_token = result['sha1']
|
||||
user.gitea_uid = gitea_user['id']
|
||||
if user.save!
|
||||
|
|
|
@ -9,14 +9,18 @@ class Gitea::User::GenerateTokenService < Gitea::ClientService
|
|||
|
||||
|
||||
def call
|
||||
params = {}
|
||||
url = "/users/#{username}/tokens".freeze
|
||||
params = params.merge(token: token_params, data: request_params)
|
||||
post(url, params)
|
||||
params = Hash.new.merge(token: token_params, data: request_params)
|
||||
response = post(url, params)
|
||||
|
||||
render_200_response(response)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def url
|
||||
"/users/#{@username}/tokens".freeze
|
||||
end
|
||||
|
||||
def token_params
|
||||
{
|
||||
username: username,
|
||||
|
@ -25,6 +29,10 @@ class Gitea::User::GenerateTokenService < Gitea::ClientService
|
|||
end
|
||||
|
||||
def request_params
|
||||
{ name: username }
|
||||
{ name: "#{@username}-#{token_name}" }
|
||||
end
|
||||
|
||||
def token_name
|
||||
SecureRandom.hex(6)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue