From 24ac425c21d524caefcfc9f0403cd0868bf797f3 Mon Sep 17 00:00:00 2001 From: xxqfamous Date: Mon, 22 May 2023 11:21:46 +0800 Subject: [PATCH] =?UTF-8?q?fixed=20=E4=BF=AE=E6=94=B9user=20login=E5=94=AF?= =?UTF-8?q?=E4=B8=80=E7=B4=A2=E5=BC=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/repair_gitea_user.rake.rb | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 lib/tasks/repair_gitea_user.rake.rb diff --git a/lib/tasks/repair_gitea_user.rake.rb b/lib/tasks/repair_gitea_user.rake.rb new file mode 100644 index 000000000..7f14325be --- /dev/null +++ b/lib/tasks/repair_gitea_user.rake.rb @@ -0,0 +1,25 @@ +namespace :repair_gitea_user do + desc "If forge users gitea_uid is null repair gitea user" + task done: :environment do + users = User.find_by_sql("SELECT * FROM `users` WHERE id !=2 AND type='User' AND NOT EXISTS (SELECT * FROM forgegitea.`user` WHERE forgegitea.`user`.id=users.gitea_uid)") + puts "total users count:#{users.count}" + success_count = 0 + users.each do |user| + begin + interactor = Gitea::RegisterInteractor.call({ username: user.login, email: user.mail, password: "abc12345678" }) + if interactor.success? + gitea_user = interactor.result + result = Gitea::User::GenerateTokenService.call(user.login, password) + user.gitea_token = result['sha1'] + user.gitea_uid = gitea_user[:body]['id'] + user.is_sync_pwd = false + user.save! + success_count = success_count + 1 + end + rescue Exception => e + puts "repair gitea user: #{user.id}:#{user.login}:, error:#{e}" + end + end + puts "repair gitea user success total: #{success_count}" + end +end \ No newline at end of file