add github token for mirror
This commit is contained in:
parent
677f9c2f4e
commit
e90c79486a
|
@ -293,7 +293,7 @@ class ProjectsController < ApplicationController
|
|||
end
|
||||
|
||||
def mirror_params
|
||||
params.permit(:user_id, :name, :description, :repository_name, :is_mirror, :auth_username,
|
||||
params.permit(:user_id, :name, :description, :repository_name, :is_mirror, :auth_username, :auth_token,
|
||||
:auth_password, :project_category_id, :project_language_id, :clone_addr, :private)
|
||||
end
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
class Projects::MigrateForm < BaseForm
|
||||
attr_accessor :user_id, :name, :repository_name, :project_category_id, :description,
|
||||
attr_accessor :user_id, :name, :repository_name, :project_category_id, :description, :auth_token,
|
||||
:project_language_id, :clone_addr, :private, :is_mirror, :auth_username, :auth_password, :owner
|
||||
|
||||
validates :user_id, :name, :repository_name, :clone_addr, presence: true
|
||||
|
|
|
@ -43,6 +43,7 @@ class Repository < ApplicationRecord
|
|||
validates :identifier, presence: true
|
||||
|
||||
delegate :default_branch, to: :project, allow_nil: true
|
||||
attr_accessor :auth_token
|
||||
|
||||
def to_param
|
||||
self.identifier.parameterize
|
||||
|
|
|
@ -39,15 +39,14 @@
|
|||
# business :boolean default("0")
|
||||
# profile_completed :boolean default("0")
|
||||
# laboratory_id :integer
|
||||
# is_shixun_marker :boolean default("0")
|
||||
# admin_visitable :boolean default("0")
|
||||
# collaborator :boolean default("0")
|
||||
# platform :string(255) default("0")
|
||||
# gitea_token :string(255)
|
||||
# gitea_uid :integer
|
||||
# is_shixun_marker :boolean default("0")
|
||||
# is_sync_pwd :boolean default("1")
|
||||
# watchers_count :integer default("0")
|
||||
# devops_step :integer default("0")
|
||||
# gitea_token :string(255)
|
||||
# platform :string(255)
|
||||
# sign_cla :boolean default("0")
|
||||
#
|
||||
# Indexes
|
||||
#
|
||||
|
@ -56,8 +55,7 @@
|
|||
# index_users_on_homepage_teacher (homepage_teacher)
|
||||
# index_users_on_laboratory_id (laboratory_id)
|
||||
# index_users_on_login (login) UNIQUE
|
||||
# index_users_on_mail (mail) UNIQUE
|
||||
# index_users_on_phone (phone) UNIQUE
|
||||
# index_users_on_mail (mail)
|
||||
# index_users_on_type (type)
|
||||
#
|
||||
|
||||
|
@ -463,6 +461,23 @@ class User < Owner
|
|||
end
|
||||
end
|
||||
|
||||
|
||||
def register_gitea
|
||||
psd = "12345678"
|
||||
interactor = Gitea::RegisterInteractor.call({username: self.login, email: self.mail, password: psd})
|
||||
if interactor.success?
|
||||
gitea_user = interactor.result
|
||||
result = Gitea::User::GenerateTokenService.call(self.login, psd)
|
||||
self.gitea_token = result['sha1']
|
||||
self.gitea_uid = gitea_user[:body]['id']
|
||||
self.password = psd
|
||||
self.password_confirmation = psd
|
||||
if self.save!
|
||||
UserExtension.create!(user_id: self.id)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def activate!
|
||||
update_attribute(:status, STATUS_ACTIVE)
|
||||
prohibit_gitea_user_login!(false)
|
||||
|
|
|
@ -9,7 +9,6 @@ class Projects::MigrateService < ApplicationService
|
|||
|
||||
def call
|
||||
raise Error, "user_id不正确." unless authroize_user_id_success
|
||||
|
||||
@project = Project.new(project_params)
|
||||
if @project.save!
|
||||
ProjectUnit.init_types(@project.id, project.project_type)
|
||||
|
@ -55,6 +54,7 @@ class Projects::MigrateService < ApplicationService
|
|||
user_id: params[:user_id],
|
||||
login: params[:auth_username],
|
||||
password: params[:auth_password],
|
||||
auth_token: params[:auth_token],
|
||||
is_mirror: params[:is_mirror],
|
||||
source_clone_url: params[:source_clone_url]
|
||||
}
|
||||
|
|
|
@ -32,7 +32,8 @@ class Repositories::MigrateService < ApplicationService
|
|||
private: params[:hidden],
|
||||
mirror: wrapper_mirror || false,
|
||||
auth_username: params[:login],
|
||||
auth_password: Base64.decode64(params[:password] || "")
|
||||
auth_password: Base64.decode64(params[:password] || ""),
|
||||
auth_token: params[:auth_token]
|
||||
}
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue