修改bug

This commit is contained in:
sylor_huang@126.com 2020-03-16 21:54:31 +08:00
parent d5069c9254
commit af62da7ae6
5 changed files with 32 additions and 61 deletions

View File

@ -5,11 +5,12 @@ class Gitea::UserForm
include ActiveModel::Model
attr_accessor :username, :email, :password
# validates :username, presence: true
validates :username, presence: true
# validates :email, presence: true, format: { with: EMAIL_REGEX, multiline: true }
#
# validates :password, presence: true
#
validates :email, presence: true
validates :password, presence: true
# validate :check_username, :check_email
attr_reader :record
@ -17,7 +18,7 @@ class Gitea::UserForm
def persist
@record = id ? User.find(id) : User.new
if true #valid?
if valid?
@record.attributes = attributes.except(:password_confirmation, :id)
@record.save!
true

View File

@ -26,6 +26,10 @@ module Gitea
render_result(response)
rescue Exception => exception
Rails.logger.info "Exception ===========> #{exception.message}"
failed_dic = "public/sync_failed_users.dic"
File.open(failed_dic,"a") do |file|
file.puts "user_info---#{params},errors--#{exception.message}"
end
fail!(exception.message)
end

View File

@ -43,11 +43,6 @@ class SyncForgeJob < ApplicationJob
end
end
else
failed_dic = "public/sync_failed_users.dic"
File.open(failed_dic,"a") do |file|
file.puts "id---#{user_params["id"]},login--#{user_params["login"]}"
end
Rails.logger.info("############___________________########{user_params["login"]}创建失败")
end
end
@ -71,36 +66,39 @@ class SyncForgeJob < ApplicationJob
if owner_params.present?
if User.exists?(login: owner_params["login"])
new_user = User.find_by(login: owner_params["login"])
elsif User.exists?(mail: owner_params["mail"])
new_user = User.find_by(mail: owner_params["mail"])
else
new_user = User.new(owner_params.merge(platform: platform))
new_user.save(:validate => false)
interactor = Gitea::RegisterInteractor.call({username: owner_params["login"], email: owner_params["mail"], password: user_password})
if interactor.success?
gitea_user = interactor.result
new_user.gitea_uid = gitea_user['id']
gitea_uid = gitea_user['id']
# new_user.gitea_uid = gitea_user['id']
else
response = Gitea::User::GetTokenService.new("#{owner_params["login"]}").call
if response.status == 200
user_id = JSON.parse(response.body)["id"]
new_user.gitea_uid = user_id
gitea_uid = JSON.parse(response.body)["id"]
# new_user.gitea_uid = user_id
else
new_user.gitea_uid = ""
gitea_uid = ""
end
end
if new_user.gitea_uid.present?
result = Gitea::User::GenerateTokenService.new(owner_params["login"], user_password).call
if result != 401
new_user.gitea_token = result.result['sha1']
else
new_user.gitea_token = ""
end
result = Gitea::User::GenerateTokenService.new(owner_params["login"], user_password).call
if result != 401
gitea_token = result.result['sha1']
# new_user.gitea_token = result.result['sha1']
else
gitea_token = ""
end
new_user.update_attributes(gitea_uid: gitea_uid, gitea_token: gitea_token)
if new_user.save(:validate => false)
if owner_extension_params.present?
owner_extension_params = owner_extension_params["user_extensions"] if old_version_source.include?(platform) #trustie上需要
owner_extension_params = owner_extension_params&.except!(*keys_other_delete).merge(user_id: new_user.id)
UserExtension.create!(owner_extension_params)
end
if owner_extension_params.present?
owner_extension_params = owner_extension_params["user_extensions"] if old_version_source.include?(platform) #trustie上需要
owner_extension_params = owner_extension_params&.except!(*keys_other_delete).merge(user_id: new_user.id)
UserExtension.create!(owner_extension_params)
end
end
Rails.logger.info("#######______sync_user_end__########")
@ -110,7 +108,7 @@ class SyncForgeJob < ApplicationJob
end
def random_password
[*('a'..'z'),*(0..9),*('A'..'Z')].shuffle[0..12].join
[*('a'..'z'),*(0..9),*('A'..'Z')].shuffle[0..8].join
end
#同步项目
@ -139,10 +137,6 @@ class SyncForgeJob < ApplicationJob
project_identifier = repo_params["identifier"]
end
# project_exists = false
# if project_identifier.present?
# project_exists = Project.exists?(user_id: new_user.id, identifier:project_identifier)
# end
new_project = Project.new(project&.except!(*keys_to_delete).merge(user_id: new_user.id))
if new_project.save!(:validate => false)
if project_identifier.present?
@ -152,15 +146,6 @@ class SyncForgeJob < ApplicationJob
identifier: project_identifier
}
Repositories::CreateService.new(new_user, new_project, repository_params).call
# unless Repository.exists?(project_id: new_project.id, user_id: new_user.id, identifier: project_identifier)
# repository_params = {
# hidden: project["is_public"],
# user_id: new_user.id,
# identifier: project_identifier
# }
# Repositories::CreateService.new(new_user, new_project, repository_params).call
# # SyncRepositoryJob.perform_later(new_user.login, project["identifier"]) #暂时不迁移版本库
# end
end
if project_score.present?

View File

@ -1,20 +0,0 @@
class SyncRepositoryJob < ApplicationJob
queue_as :default
def perform(login,identifier)
Rails.logger.info("#######__________begin_sync_repository_________####")
gitea_test_ssh = "sshpass -p '@pd:lk4+407' ssh -o StrictHostKeyChecking=no -p 30122 root@123.59.135.93"
gitea_jump_ssh = "sshpass -p '#pd:lk3+407' ssh -o StrictHostKeyChecking=no -p 30122 root@10.9.69.134"
gitea_user_repo = "/home/git/gitea-repositories/#{login}"
git_clone_bare = "git clone --bare http://git.trustie.net/#{login}/#{identifier}.git"
gitea_repos = system("#{gitea_test_ssh} && #{gitea_jump_ssh} && cd #{gitea_user_repo} && rm -rf #{identifier}.git && #{git_clone_bare}")
if gitea_repos
Rails.logger.info("########________gitea_clone_success__________##############")
else
Rails.logger.info("########________gitea_clone_failed_____user_loigin:_#{login}_identifier:__#{identifier}")
end
end
end

View File

@ -125,6 +125,7 @@ class Gitea::ClientService < ApplicationService
{status: 200}
end
when 401
""
raise Error, mark + "401"
when 422
result = JSON.parse(response&.body)