forgeplus/lib/tasks/user.rake

73 lines
2.8 KiB
Ruby
Raw Normal View History

2020-03-09 00:40:16 +08:00
# add test user
namespace :sync do
task :add_user => :environment do
DCODES = %W(2 3 4 5 6 7 8 9 a b c f e f g h i j k l m n o p q r s t u v w x y z)
user_count = ENV['args'].split(",")[0].to_i # 用户数
rand_chart = ENV['args'].split(",")[1] # 手机号或者邮箱等前面的随机数
puts rand_chart
puts user_count
(1..user_count).each do |i|
puts i
no = sprintf("%04d", i)
phone = "#{rand_chart}160731#{no}"
mail = "#{rand_chart}#{no}@educoder.net"
code = generate_identifier User, 8
login = "m" + code
l = "赵,钱,孙,李,周,吴,郑,王,冯,陈,褚,卫,蒋,沈,韩,杨,朱,秦,尤,许,何,吕,施,张,孔,曹,严,华,金,魏,陶,姜,黄".split(",")
f = "爱童,安妮,若婷,安煜,博,雷,梅,静,士红,大龙,冰波,慧娟,梅,婧婧,军,淋,真,维,涛,程程,
,,,,,,,,,,,,,,,,访,,,绿,,
,,访,,,,,,,,,,,,访,,,,,,,
,,,,,,,,,,,,,,,,,,绿,,,
,,,,,,,,,,访,,绿,,,,,,,,,
,,绿,,,,,,,,,,,,,,,,,,,
,绿,,,,,,,,,,绿,,,,,,,,,,
,,,,,,,,,,,,,,,,,".split(",")
lastname = l[rand(l.length)].strip + f[rand(f.length)].strip
edit_params = {
login: login,
admin: false,
type: User,
phone: phone,
lastname: lastname,
mail: mail,
authentication: 1,
professional_certification: 1,
profile_completed: true,
is_test: true
}
user = User.create!(edit_params)
user.password = "edu12345678"
user.save!
UserExtension.create!(user_id: user.id, school_id: 117)
puts i
end
end
task :password => :environment do
end
# 随机生成字符
def generate_identifier(container, num)
code = DCODES.sample(num).join
if container == User
while container.exists?(login: code) do
code = DCODES.sample(num).join
end
else
while container.exists?(identifier: code) do
code = DCODES.sample(num).join
end
end
code
end
end