diff --git a/src/.env.example b/src/.env.example --- a/src/.env.example +++ b/src/.env.example @@ -16,6 +16,9 @@ APP_WITH_RESELLER=1 APP_WITH_SERVICES=1 +SIGNUP_LIMIT_EMAIL=0 +SIGNUP_LIMIT_IP=0 + ASSET_URL=http://127.0.0.1:8000 WEBMAIL_URL=/apps diff --git a/src/app/Rules/ExternalEmail.php b/src/app/Rules/ExternalEmail.php --- a/src/app/Rules/ExternalEmail.php +++ b/src/app/Rules/ExternalEmail.php @@ -37,6 +37,28 @@ return false; } + // don't allow multiple open registrations against the same email address + if (env('SIGNUP_LIMIT_EMAIL', 0) > 0) { + $signups = \App\SignupCode::where('email', $email) + ->whereDate('expires_at', '>', \Carbon\Carbon::now()); + + if ($signups->count() >= env('SIGNUP_LIMIT_EMAIL')) { + $this->message = \trans('validation.emailinvalid'); + return false; + } + } + + // don't allow multiple open registrations against the same source ip address + if (env('SIGNUP_LIMIT_IP', 0) > 0) { + $signups = \App\SignupCode::where("ip_address", request()->ip()) + ->whereDate('expires_at', '>', \Carbon\Carbon::now()); + + if ($signups->count() >= env('SIGNUP_LIMIT_IP')) { + $this->message = \trans('validation.emailinvalid'); + return false; + } + } + return true; } diff --git a/src/app/SignupCode.php b/src/app/SignupCode.php --- a/src/app/SignupCode.php +++ b/src/app/SignupCode.php @@ -99,8 +99,18 @@ */ public static function generateShortCode(): string { - $code_length = env('SIGNUP_CODE_LENGTH', self::SHORTCODE_LENGTH); + $codeLength = env('SIGNUP_CODE_LENGTH', self::SHORTCODE_LENGTH); - return \App\Utils::randStr($code_length); + $allegedlyUnique = \App\Utils::randStr($codeLength); + + while ($code = $this->where('short_code', $allegedlyUnique)->first()) { + if ($code->isExpired()) { + break; + } + + $allegedlyUnique = \App\Utils::randStr($codeLength); + } + + return $allegedlyUnique; } }