修改bug

This commit is contained in:
sylor_huang@126.com 2020-03-16 22:51:00 +08:00
parent af62da7ae6
commit 17ad972b38
3 changed files with 59 additions and 51 deletions

View File

@ -1,17 +1,16 @@
class Gitea::UserForm class Gitea::UserForm
include ActiveModel::Model include ActiveModel::Model
EMAIL_REGEX = /^[a-zA-Z0-9_-]+@[a-zA-Z0-9_\-.]+(\.[a-zA-Z0-9_-]+)+$/ EMAIL_REGEX = /^[a-zA-Z0-9_\-.]+@[a-zA-Z0-9_\-.]+(\.[a-zA-Z0-9_-]+)+$/
include ActiveModel::Model include ActiveModel::Model
attr_accessor :username, :email, :password attr_accessor :username, :email, :password
validates :username, presence: true validates :username, presence: true
# validates :email, presence: true, format: { with: EMAIL_REGEX, multiline: true } validates :email, presence: true, format: { with: EMAIL_REGEX, multiline: true }
validates :email, presence: true
validates :password, presence: true validates :password, presence: true
# validate :check_username, :check_email validate :check_username, :check_email
attr_reader :record attr_reader :record

View File

@ -26,10 +26,6 @@ module Gitea
render_result(response) render_result(response)
rescue Exception => exception rescue Exception => exception
Rails.logger.info "Exception ===========> #{exception.message}" 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) fail!(exception.message)
end end

View File

@ -17,6 +17,7 @@ class SyncForgeJob < ApplicationJob
if new_user.present? if new_user.present?
ActiveRecord::Base.transaction do ActiveRecord::Base.transaction do
begin begin
user_params = user_params["user"] if old_version_source.include?(platform)
Watcher&.where(user_id: user_params["id"]).update_all(user_id: new_user.id) Watcher&.where(user_id: user_params["id"]).update_all(user_id: new_user.id)
ProjectTrend&.where(user_id: user_params["id"]).update_all(user_id: new_user.id) ProjectTrend&.where(user_id: user_params["id"]).update_all(user_id: new_user.id)
sync_roles(roles_params, platform) sync_roles(roles_params, platform)
@ -55,6 +56,8 @@ class SyncForgeJob < ApplicationJob
private private
def sync_user(owner_params,owner_extension_params,platform) def sync_user(owner_params,owner_extension_params,platform)
ActiveRecord::Base.transaction do
begin
Rails.logger.info("#######______sync_user_start__########") Rails.logger.info("#######______sync_user_start__########")
keys_other_delete = %w(id created_at updated_at user_id) keys_other_delete = %w(id created_at updated_at user_id)
keys_to_delete = %w(id created_on updated_on platform) keys_to_delete = %w(id created_on updated_on platform)
@ -73,6 +76,7 @@ class SyncForgeJob < ApplicationJob
new_user.save(:validate => false) new_user.save(:validate => false)
interactor = Gitea::RegisterInteractor.call({username: owner_params["login"], email: owner_params["mail"], password: user_password}) interactor = Gitea::RegisterInteractor.call({username: owner_params["login"], email: owner_params["mail"], password: user_password})
if interactor.success? if interactor.success?
gitea_user = interactor.result gitea_user = interactor.result
gitea_uid = gitea_user['id'] gitea_uid = gitea_user['id']
@ -105,6 +109,15 @@ class SyncForgeJob < ApplicationJob
end end
new_user new_user
rescue Exception => e
failed_dic = "public/sync_failed_users.dic"
File.open(failed_dic,"a") do |file|
file.puts "user_info---#{owner_params},errors--#{e}"
end
end
end
end end
def random_password def random_password