mirror of
https://github.com/mastodon/mastodon.git
synced 2024-08-20 21:08:15 -07:00
Merge 4000d1aeca
into a50c8e951f
This commit is contained in:
commit
14dfd8cd94
1 changed files with 6 additions and 2 deletions
|
@ -20,6 +20,10 @@ class Invite < ApplicationRecord
|
||||||
include Expireable
|
include Expireable
|
||||||
|
|
||||||
COMMENT_SIZE_LIMIT = 420
|
COMMENT_SIZE_LIMIT = 420
|
||||||
|
VALID_CODE_CHARACTERS = (
|
||||||
|
# Lowercase chars & Uppercase chars & numbers with homoglyphs removed
|
||||||
|
[*('a'..'z'), *('A'..'Z'), *('0'..'9')] - %w(0 1 I l O)
|
||||||
|
).freeze
|
||||||
|
|
||||||
belongs_to :user, inverse_of: :invites
|
belongs_to :user, inverse_of: :invites
|
||||||
has_many :users, inverse_of: :invite, dependent: nil
|
has_many :users, inverse_of: :invite, dependent: nil
|
||||||
|
@ -38,8 +42,8 @@ class Invite < ApplicationRecord
|
||||||
|
|
||||||
def set_code
|
def set_code
|
||||||
loop do
|
loop do
|
||||||
self.code = ([*('a'..'z'), *('A'..'Z'), *('0'..'9')] - %w(0 1 I l O)).sample(8).join
|
self.code = VALID_CODE_CHARACTERS.sample(8).join
|
||||||
break if Invite.find_by(code: code).nil?
|
break unless self.class.exists?(code: code)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue