user fresh gitea token method

This commit is contained in:
chenjing 2023-03-20 14:47:48 +08:00
parent ac49edc8e8
commit 0a7c41d97c
1 changed files with 13 additions and 0 deletions

View File

@ -449,6 +449,19 @@ class User < Owner
self.status = STATUS_EDIT_INFO
end
def fresh_gitea_token
result = $gitea_client.get_users_tokens_by_username(self.login, {query: {sudo: self.login}})
if result[:data].present?
result[:data].map{ |e|
$gitea_client.delete_users_tokens_by_username_token(self.login, e["name"], {query: {sudo: self.login} })
}
end
new_result = $gitea_client.post_users_tokens_by_username(self.login, { query: {sudo: self.login}, body:{ name: self.login} })
if new_result["sha1"].present?
update(gitea_token: new_result["sha1"])
end
end
def activate!
update_attribute(:status, STATUS_ACTIVE)
prohibit_gitea_user_login!(false)