mirror of
https://gitlink.org.cn/Gitlink/forgeplus.git
synced 2026-05-22 12:45:46 +08:00
add: invite code
This commit is contained in:
13
app/models/concerns/dcodes.rb
Normal file
13
app/models/concerns/dcodes.rb
Normal file
@@ -0,0 +1,13 @@
|
||||
module Dcodes
|
||||
DCODES = %W(1 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)
|
||||
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
def generate_dcode(field, num, pre='')
|
||||
code = DCODES.sample(num).join
|
||||
while self.class.exists?("#{field}": pre+code) do
|
||||
code = DCODES.sample(num).join
|
||||
end
|
||||
code
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user