forked from Gitlink/forgeplus
更改:导入用户规则
This commit is contained in:
parent
f22ffcb7c4
commit
4ed846a68b
|
@ -1,13 +1,14 @@
|
|||
module Register
|
||||
class RemoteForm < Register::BaseForm
|
||||
# login 登陆方式,支持邮箱、登陆、手机号等
|
||||
attr_accessor :username, :email, :password, :platform
|
||||
attr_accessor :username, :phone, :email, :password, :platform
|
||||
|
||||
validates :username, :email, :password, presence: true
|
||||
validates :username, :phone, :email, :password, presence: true
|
||||
validate :check!
|
||||
|
||||
def check!
|
||||
Rails.logger.info "Register::RemoteForm params: username: #{username}; email: #{email}; password: #{password}; platform: #{platform}"
|
||||
Rails.logger.info "Register::RemoteForm params: username: #{username}, phone: #{phone}; email: #{email}; password: #{password}; platform: #{platform}"
|
||||
check_phone(phone)
|
||||
check_login(username)
|
||||
check_mail(email)
|
||||
check_password(password)
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
class Admins::NewImportUserFromExcel < BaseImportXlsx
|
||||
UserData = Struct.new(:login, :email, :password, :nickname)
|
||||
UserData = Struct.new(:login, :phone, :password, :nickname)
|
||||
|
||||
def read_each(&block)
|
||||
sheet.each_row_streaming(pad_cells: true, offset: 1) do |row|
|
||||
|
|
|
@ -41,12 +41,13 @@ class Admins::ImportUserFromExcelService < ApplicationService
|
|||
def create_user(data)
|
||||
ActiveRecord::Base.transaction do
|
||||
username = data.login&.gsub(/\s+/, "")
|
||||
email = data.email&.gsub(/\s+/, "")
|
||||
phone = data.phone&.gsub(/\s+/, "")
|
||||
password = data.password
|
||||
nickname = data.nickname&.gsub(/\s+/, "")
|
||||
email = "#{username}@example.org"
|
||||
raise Error, "无法使用以下关键词:#{username},请重新命名" if ReversedKeyword.check_exists?(data.login)
|
||||
Register::RemoteForm.new({username: username, email: email, password: password, platform: 'forge'}).validate!
|
||||
user = User.new(admin: false, login: username, mail: email, nickname: nickname, platform: 'forge' , type: "User")
|
||||
Register::RemoteForm.new({username: username, phone: phone, email: email, password: password, platform: 'forge'}).validate!
|
||||
user = User.new(admin: false, login: username, phone: phone, mail: email, nickname: nickname, platform: 'forge' , type: "User")
|
||||
user.password = password
|
||||
user.activate
|
||||
raise Error, user.errors.full_messages.join(",") unless user.valid?
|
||||
|
|
Binary file not shown.
Loading…
Reference in New Issue