Unify domain validation regex to fix custom domain issues
This commit is contained in:
parent
dd83528a3a
commit
c01f566ba9
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
namespace App\Http\Controllers;
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use App\Http\Requests\Workspace\CustomDomainRequest;
|
||||||
use App\Models\Workspace;
|
use App\Models\Workspace;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
|
@ -14,7 +15,7 @@ class CaddyController extends Controller
|
||||||
]);
|
]);
|
||||||
// make sure domain is valid
|
// make sure domain is valid
|
||||||
$domain = $request->input('domain');
|
$domain = $request->input('domain');
|
||||||
if (!preg_match('/^[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}$/', $domain)) {
|
if (!preg_match(CustomDomainRequest::CUSTOM_DOMAINS_REGEX, $domain)) {
|
||||||
return $this->error([
|
return $this->error([
|
||||||
'success' => false,
|
'success' => false,
|
||||||
'message' => 'Invalid domain',
|
'message' => 'Invalid domain',
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
namespace App\Http\Middleware;
|
namespace App\Http\Middleware;
|
||||||
|
|
||||||
|
use App\Http\Requests\Workspace\CustomDomainRequest;
|
||||||
use App\Models\Forms\Form;
|
use App\Models\Forms\Form;
|
||||||
use App\Models\Workspace;
|
use App\Models\Workspace;
|
||||||
use Closure;
|
use Closure;
|
||||||
|
@ -22,7 +23,7 @@ class CustomDomainRestriction
|
||||||
}
|
}
|
||||||
|
|
||||||
$customDomain = $request->header(self::CUSTOM_DOMAIN_HEADER);
|
$customDomain = $request->header(self::CUSTOM_DOMAIN_HEADER);
|
||||||
if (!preg_match('/^[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}$/', $customDomain)) {
|
if (!preg_match(CustomDomainRequest::CUSTOM_DOMAINS_REGEX, $customDomain)) {
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'success' => false,
|
'success' => false,
|
||||||
'message' => 'Invalid domain',
|
'message' => 'Invalid domain',
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
namespace App\Http\Requests;
|
namespace App\Http\Requests;
|
||||||
|
|
||||||
|
|
||||||
|
use App\Http\Requests\Workspace\CustomDomainRequest;
|
||||||
use App\Models\Forms\Form;
|
use App\Models\Forms\Form;
|
||||||
use App\Rules\OneEmailPerLine;
|
use App\Rules\OneEmailPerLine;
|
||||||
use Illuminate\Validation\Rule;
|
use Illuminate\Validation\Rule;
|
||||||
|
@ -126,7 +127,7 @@ abstract class UserFormRequest extends \Illuminate\Foundation\Http\FormRequest
|
||||||
|
|
||||||
// Custom SEO
|
// Custom SEO
|
||||||
'seo_meta' => 'nullable|array',
|
'seo_meta' => 'nullable|array',
|
||||||
'custom_domain' => 'sometimes|nullable|regex:/^[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,20}$/'
|
'custom_domain' => 'sometimes|nullable|regex:'. CustomDomainRequest::CUSTOM_DOMAINS_REGEX,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@ use Illuminate\Http\Request;
|
||||||
|
|
||||||
class CustomDomainRequest extends FormRequest
|
class CustomDomainRequest extends FormRequest
|
||||||
{
|
{
|
||||||
|
const CUSTOM_DOMAINS_REGEX = '/^[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,20}$/';
|
||||||
|
|
||||||
public Workspace $workspace;
|
public Workspace $workspace;
|
||||||
public array $customDomains = [];
|
public array $customDomains = [];
|
||||||
|
@ -32,7 +33,7 @@ class CustomDomainRequest extends FormRequest
|
||||||
$domains = collect($value)->filter(function ($domain) {
|
$domains = collect($value)->filter(function ($domain) {
|
||||||
return !empty( trim($domain) );
|
return !empty( trim($domain) );
|
||||||
})->each(function($domain) use (&$errors) {
|
})->each(function($domain) use (&$errors) {
|
||||||
if (!preg_match('/^[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,20}$/', $domain)) {
|
if (!preg_match(self::CUSTOM_DOMAINS_REGEX, $domain)) {
|
||||||
$errors[] = 'Invalid domain: ' . $domain;
|
$errors[] = 'Invalid domain: ' . $domain;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue