mirror of
https://github.com/discourse/discourse.git
synced 2025-03-23 01:35:42 +08:00
FEATURE: Reduce invite key length (#12692)
We used to generate invite keys that were 32-characters long which were not very friendly and lead to very long links. This commit changes the generation method to use almost all alphanumeric characters to produce a 10-character long invite key. This commit also introduces a rate limit for redeeming invites because the probability of guessing an invite key has increased.
This commit is contained in:
parent
21d1ee1065
commit
8c24a848e0
app
@ -17,6 +17,8 @@ class InvitesController < ApplicationController
|
|||||||
def show
|
def show
|
||||||
expires_now
|
expires_now
|
||||||
|
|
||||||
|
RateLimiter.new(nil, "invites-show-#{request.remote_ip}", 100, 1.minute).performed!
|
||||||
|
|
||||||
invite = Invite.find_by(invite_key: params[:id])
|
invite = Invite.find_by(invite_key: params[:id])
|
||||||
if invite.present? && invite.redeemable?
|
if invite.present? && invite.redeemable?
|
||||||
email = Email.obfuscate(invite.email)
|
email = Email.obfuscate(invite.email)
|
||||||
@ -63,6 +65,9 @@ class InvitesController < ApplicationController
|
|||||||
|
|
||||||
render layout: 'no_ember'
|
render layout: 'no_ember'
|
||||||
end
|
end
|
||||||
|
rescue RateLimiter::LimitExceeded => e
|
||||||
|
flash.now[:error] = e.description
|
||||||
|
render layout: 'no_ember'
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
|
@ -35,7 +35,7 @@ class Invite < ActiveRecord::Base
|
|||||||
validate :user_doesnt_already_exist
|
validate :user_doesnt_already_exist
|
||||||
|
|
||||||
before_create do
|
before_create do
|
||||||
self.invite_key ||= SecureRandom.hex
|
self.invite_key ||= SecureRandom.base58(10)
|
||||||
self.expires_at ||= SiteSetting.invite_expiry_days.days.from_now
|
self.expires_at ||= SiteSetting.invite_expiry_days.days.from_now
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user