Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F117748097
SignupCode.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
2 KB
Referenced Files
None
Subscribers
None
SignupCode.php
View Options
<?php
namespace
App
;
use
Carbon\Carbon
;
use
Illuminate\Database\Eloquent\Model
;
/**
* The eloquent definition of a SignupCode.
*/
class
SignupCode
extends
Model
{
// Note: Removed '0', 'O', '1', 'I' as problematic with some fonts
public
const
SHORTCODE_CHARS
=
'23456789ABCDEFGHJKLMNPQRSTUVWXYZ'
;
public
const
SHORTCODE_LENGTH
=
5
;
public
const
CODE_LENGTH
=
32
;
// Code expires after so many hours
public
const
CODE_EXP_HOURS
=
24
;
/**
* The primary key associated with the table.
*
* @var string
*/
protected
$primaryKey
=
'code'
;
/**
* Indicates if the IDs are auto-incrementing.
*
* @var bool
*/
public
$incrementing
=
false
;
/**
* The "type" of the auto-incrementing ID.
*
* @var string
*/
protected
$keyType
=
'string'
;
/**
* Indicates if the model should be timestamped.
*
* @var bool
*/
public
$timestamps
=
false
;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected
$fillable
=
[
'code'
,
'short_code'
,
'data'
,
'expires_at'
];
/**
* The attributes that should be cast to native types.
*
* @var array
*/
protected
$casts
=
[
'data'
=>
'array'
];
/**
* The attributes that should be mutated to dates.
*
* @var array
*/
protected
$dates
=
[
'expires_at'
];
/**
* Check if code is expired.
*
* @return bool True if code is expired, False otherwise
*/
public
function
isExpired
()
{
return
$this
->
expires_at
?
Carbon
::
now
()->
gte
(
$this
->
expires_at
)
:
false
;
}
/**
* Generate a short code (for human).
*
* @return string
*/
public
static
function
generateShortCode
():
string
{
$code_length
=
env
(
'SIGNUP_CODE_LENGTH'
,
self
::
SHORTCODE_LENGTH
);
$code_chars
=
env
(
'SIGNUP_CODE_CHARS'
,
self
::
SHORTCODE_CHARS
);
$random
=
[];
for
(
$i
=
1
;
$i
<=
$code_length
;
$i
++)
{
$random
[]
=
$code_chars
[
rand
(
0
,
strlen
(
$code_chars
)
-
1
)];
}
shuffle
(
$random
);
return
implode
(
''
,
$random
);
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sat, Apr 4, 12:47 AM (3 w, 4 d ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
57/75/35db541d71dda27a35be98c0c28c
Default Alt Text
SignupCode.php (2 KB)
Attached To
Mode
rK kolab
Attached
Detach File
Event Timeline