Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F117750395
VerificationCodeObserver.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
1 KB
Referenced Files
None
Subscribers
None
VerificationCodeObserver.php
View Options
<?php
namespace
App\Observers
;
use
App\VerificationCode
;
use
Carbon\Carbon
;
use
Illuminate\Support\Str
;
class
VerificationCodeObserver
{
/**
* Handle the "creating" event.
*
* Ensure that the code entry is created with a random code/short_code.
*
* @param \App\VerificationCode $code The code being created.
*
* @return void
*/
public
function
creating
(
VerificationCode
$code
):
void
{
$code_length
=
VerificationCode
::
CODE_LENGTH
;
$exp_hours
=
env
(
'VERIFICATION_CODE_EXPIRY'
,
VerificationCode
::
CODE_EXP_HOURS
);
if
(
empty
(
$code
->
code
))
{
$code
->
short_code
=
VerificationCode
::
generateShortCode
();
// FIXME: Replace this with something race-condition free
while
(
true
)
{
$code
->
code
=
Str
::
random
(
$code_length
);
if
(!
VerificationCode
::
find
(
$code
->
code
))
{
break
;
}
}
}
$code
->
expires_at
=
Carbon
::
now
()->
addHours
(
$exp_hours
);
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sat, Apr 4, 2:19 AM (1 w, 2 d ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
89/7d/5b9a289189b3b8225baeef8af397
Default Alt Text
VerificationCodeObserver.php (1 KB)
Attached To
Mode
rK kolab
Attached
Detach File
Event Timeline