You've already forked Atomcms-edit
Initial commit
This commit is contained in:
Executable
+17
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Rules;
|
||||
|
||||
use App\Models\Miscellaneous\WebsiteBetaCode;
|
||||
use Closure;
|
||||
use Illuminate\Contracts\Validation\InvokableRule;
|
||||
|
||||
class BetaCodeRule implements InvokableRule
|
||||
{
|
||||
public function __invoke(string $attribute, mixed $value, Closure $fail): void
|
||||
{
|
||||
if (setting('requires_beta_code') && WebsiteBetaCode::whereCode($value)->whereNull('user_id')->doesntExist()) {
|
||||
$fail(__('The beta code is invalid.'));
|
||||
}
|
||||
}
|
||||
}
|
||||
Executable
+21
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Rules;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Contracts\Validation\InvokableRule;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
|
||||
class CurrentPasswordRule implements InvokableRule
|
||||
{
|
||||
/**
|
||||
* Run the validation rule.
|
||||
*/
|
||||
public function __invoke(string $attribute, mixed $value, Closure $fail): void
|
||||
{
|
||||
if (! Hash::check($value, Auth::user()->password)) {
|
||||
$fail('It seems like your current password is wrong.');
|
||||
}
|
||||
}
|
||||
}
|
||||
Executable
+42
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace App\Rules;
|
||||
|
||||
use Closure;
|
||||
use GuzzleHttp\Client;
|
||||
use Illuminate\Contracts\Validation\InvokableRule;
|
||||
|
||||
class GoogleRecaptchaRule implements InvokableRule
|
||||
{
|
||||
public function __invoke(string $attribute, mixed $value, Closure $fail): void
|
||||
{
|
||||
// If recaptcha is disabled
|
||||
if ((int) setting('google_recaptcha_enabled') === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
$client = new Client;
|
||||
|
||||
$response = $client->request(
|
||||
'POST', 'https://www.google.com/recaptcha/api/siteverify', [
|
||||
'form_params' => [
|
||||
'secret' => config('habbo.site.recaptcha_secret_key'),
|
||||
'response' => $value,
|
||||
'remoteip' => request()->ip(),
|
||||
],
|
||||
],
|
||||
);
|
||||
|
||||
if ($response->getStatusCode() !== 200) {
|
||||
$fail(__('The Google recaptcha was not successful.'));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$body = json_decode((string) $response->getBody());
|
||||
|
||||
if (! $body->success) {
|
||||
$fail(__('The Google recaptcha was not successful.'));
|
||||
}
|
||||
}
|
||||
}
|
||||
Executable
+180
@@ -0,0 +1,180 @@
|
||||
<?php
|
||||
|
||||
namespace App\Rules;
|
||||
|
||||
use Illuminate\Contracts\Validation\Rule;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class Password implements Rule
|
||||
{
|
||||
/**
|
||||
* The minimum length of the password.
|
||||
*/
|
||||
protected int $length = 6;
|
||||
|
||||
/**
|
||||
* Indicates if the password must contain one uppercase character.
|
||||
*/
|
||||
protected bool $requireUppercase = false;
|
||||
|
||||
/**
|
||||
* Indicates if the password must contain one numeric digit.
|
||||
*/
|
||||
protected bool $requireNumeric = false;
|
||||
|
||||
/**
|
||||
* Indicates if the password must contain one special character.
|
||||
*/
|
||||
protected bool $requireSpecialCharacter = false;
|
||||
|
||||
/**
|
||||
* The message that should be used when validation fails.
|
||||
*/
|
||||
protected ?string $message = null;
|
||||
|
||||
/**
|
||||
* Determine if the validation rule passes.
|
||||
*
|
||||
* @param mixed $value
|
||||
*/
|
||||
public function passes($attribute, $value): bool
|
||||
{
|
||||
$value = is_scalar($value) ? (string) $value : '';
|
||||
|
||||
if ($this->requireUppercase && Str::lower($value) === $value) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($this->requireNumeric && ! preg_match('/\d/', $value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($this->requireSpecialCharacter && ! preg_match('/[\W_]/', $value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return Str::length($value) >= $this->length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation error message.
|
||||
*/
|
||||
public function message(): string
|
||||
{
|
||||
if ($this->message) {
|
||||
return $this->message;
|
||||
}
|
||||
|
||||
return match (true) {
|
||||
$this->requireUppercase
|
||||
&& ! $this->requireNumeric
|
||||
&& ! $this->requireSpecialCharacter => __(
|
||||
'The :attribute must be at least :length characters and contain at least one uppercase character.',
|
||||
[
|
||||
'length' => $this->length,
|
||||
],
|
||||
),
|
||||
$this->requireNumeric
|
||||
&& ! $this->requireUppercase
|
||||
&& ! $this->requireSpecialCharacter => __(
|
||||
'The :attribute must be at least :length characters and contain at least one number.',
|
||||
[
|
||||
'length' => $this->length,
|
||||
],
|
||||
),
|
||||
$this->requireSpecialCharacter
|
||||
&& ! $this->requireUppercase
|
||||
&& ! $this->requireNumeric => __(
|
||||
'The :attribute must be at least :length characters and contain at least one special character.',
|
||||
[
|
||||
'length' => $this->length,
|
||||
],
|
||||
),
|
||||
$this->requireUppercase
|
||||
&& $this->requireNumeric
|
||||
&& ! $this->requireSpecialCharacter => __(
|
||||
'The :attribute must be at least :length characters and contain at least one uppercase character and one number.',
|
||||
[
|
||||
'length' => $this->length,
|
||||
],
|
||||
),
|
||||
$this->requireUppercase
|
||||
&& $this->requireSpecialCharacter
|
||||
&& ! $this->requireNumeric => __(
|
||||
'The :attribute must be at least :length characters and contain at least one uppercase character and one special character.',
|
||||
[
|
||||
'length' => $this->length,
|
||||
],
|
||||
),
|
||||
$this->requireUppercase
|
||||
&& $this->requireNumeric
|
||||
&& $this->requireSpecialCharacter => __(
|
||||
'The :attribute must be at least :length characters and contain at least one uppercase character, one number, and one special character.',
|
||||
[
|
||||
'length' => $this->length,
|
||||
],
|
||||
),
|
||||
$this->requireNumeric
|
||||
&& $this->requireSpecialCharacter
|
||||
&& ! $this->requireUppercase => __(
|
||||
'The :attribute must be at least :length characters and contain at least one special character and one number.',
|
||||
[
|
||||
'length' => $this->length,
|
||||
],
|
||||
),
|
||||
default => __('The :attribute must be at least :length characters.', [
|
||||
'length' => $this->length,
|
||||
]),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the minimum length of the password.
|
||||
*/
|
||||
public function length(int $length)
|
||||
{
|
||||
$this->length = $length;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate that at least one uppercase character is required.
|
||||
*/
|
||||
public function requireUppercase(): static
|
||||
{
|
||||
$this->requireUppercase = true;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate that at least one numeric digit is required.
|
||||
*/
|
||||
public function requireNumeric(): static
|
||||
{
|
||||
$this->requireNumeric = true;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate that at least one special character is required.
|
||||
*/
|
||||
public function requireSpecialCharacter(): static
|
||||
{
|
||||
$this->requireSpecialCharacter = true;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the message that should be used when the rule fails.
|
||||
*/
|
||||
public function withMessage(string $message): static
|
||||
{
|
||||
$this->message = $message;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
Executable
+31
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Rules;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
use RyanChandler\LaravelCloudflareTurnstile\Facades\Turnstile;
|
||||
|
||||
class TurnstileCheck implements ValidationRule
|
||||
{
|
||||
public function validate(string $attribute, mixed $value, Closure $fail): void
|
||||
{
|
||||
if (empty($value)) {
|
||||
$fail(__(config('turnstile.error_messages.turnstile_check_message')));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
$response = Turnstile::siteverify($value);
|
||||
|
||||
$isEnabled = setting('cloudflare_turnstile_enabled', true);
|
||||
|
||||
if (! $response->success && $isEnabled) {
|
||||
$fail(__(config('turnstile.error_messages.turnstile_check_message')));
|
||||
}
|
||||
} catch (\Throwable) {
|
||||
$fail(__(config('turnstile.error_messages.turnstile_check_message')));
|
||||
}
|
||||
}
|
||||
}
|
||||
Executable
+17
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Rules;
|
||||
|
||||
use App\Models\Miscellaneous\WebsiteInstallation;
|
||||
use Closure;
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
|
||||
class ValidateInstallationKeyRule implements ValidationRule
|
||||
{
|
||||
public function validate(string $attribute, mixed $value, Closure $fail): void
|
||||
{
|
||||
if ($value !== WebsiteInstallation::first()->installation_key) {
|
||||
$fail('The :attribute does not match');
|
||||
}
|
||||
}
|
||||
}
|
||||
Executable
+23
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Rules;
|
||||
|
||||
use App\Models\Miscellaneous\WebsiteWordfilter;
|
||||
use Closure;
|
||||
use Illuminate\Contracts\Validation\InvokableRule;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class WebsiteWordfilterRule implements InvokableRule
|
||||
{
|
||||
public function __invoke(string $attribute, mixed $value, Closure $fail): void
|
||||
{
|
||||
$words = WebsiteWordfilter::query()
|
||||
->pluck('word')
|
||||
->filter(fn ($word) => is_string($word))
|
||||
->toArray();
|
||||
|
||||
if (setting('website_wordfilter_enabled') === '1' && (in_array(strtolower((string) $value), $words) || ($words && Str::contains(strtolower((string) $value), implode(' ', $words))))) {
|
||||
$fail(__('You entered something that is not allowed on :hotel', ['hotel' => setting('hotel_name')]));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user