Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F2397556
UserEmailLocal.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
UserEmailLocal.php
View Options
<?php
namespace
App\Rules
;
use
Illuminate\Contracts\Validation\Rule
;
use
Illuminate\Support\Facades\Validator
;
class
UserEmailLocal
implements
Rule
{
private
$message
;
private
$external
;
/**
* Class constructor.
*
* @param bool $external The user in an external domain, or not
*/
public
function
__construct
(
bool
$external
)
{
$this
->
external
=
$external
;
}
/**
* Determine if the validation rule passes.
*
* Validation of local part of an email address that's
* going to be user's login.
*
* @param string $attribute Attribute name
* @param mixed $login Local part of email address
*
* @return bool
*/
public
function
passes
(
$attribute
,
$login
):
bool
{
// Strict validation
if
(!
preg_match
(
'/^[A-Za-z0-9_.-]+$/'
,
$login
))
{
$this
->
message
=
\trans
(
'validation.entryinvalid'
,
[
'attribute'
=>
$attribute
]);
return
false
;
}
// Standard email address validation
$v
=
Validator
::
make
([
$attribute
=>
$login
.
'@test.com'
],
[
$attribute
=>
'required|email'
]);
if
(
$v
->
fails
())
{
$this
->
message
=
\trans
(
'validation.entryinvalid'
,
[
'attribute'
=>
$attribute
]);
return
false
;
}
// Check if the local part is not one of exceptions
// (when signing up for an account in public domain
if
(!
$this
->
external
)
{
$exceptions
=
'/^(admin|administrator|sales|root)$/i'
;
if
(
preg_match
(
$exceptions
,
$login
))
{
$this
->
message
=
\trans
(
'validation.entryexists'
,
[
'attribute'
=>
$attribute
]);
return
false
;
}
}
return
true
;
}
/**
* Get the validation error message.
*
* @return string
*/
public
function
message
():
?
string
{
return
$this
->
message
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Mon, Nov 3, 2:09 PM (9 h, 35 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
358082
Default Alt Text
UserEmailLocal.php (1 KB)
Attached To
Mode
R2 kolab
Attached
Detach File
Event Timeline
Log In to Comment