-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAccount.php
More file actions
186 lines (164 loc) · 3.64 KB
/
Copy pathAccount.php
File metadata and controls
186 lines (164 loc) · 3.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
<?php
namespace Apolune\Account;
use Carbon\Carbon;
use Apolune\Core\Traits\Authenticatable;
use Apolune\Core\Database\Eloquent\Model;
use Apolune\Contracts\Account\Account as Contract;
use Apolune\Account\Traits\Relations\Account as AccountRelations;
class Account extends Model implements Contract
{
use Authenticatable, AccountRelations;
/**
* The attributes excluded from the model's JSON form.
*
* @var array
*/
protected $hidden = ['password'];
/**
* Indicates if the model should be timestamped.
*
* @var boolean
*/
public $timestamps = false;
/**
* Retrieve the account id.
*
* @return integer
*/
public function id()
{
return $this->id;
}
/**
* Retrieve the account name.
*
* @return string
*/
public function name()
{
return strtoupper($this->name);
}
/**
* Retrieve the account email.
*
* @return string
*/
public function email()
{
return $this->email;
}
/**
* Retrieve the account type.
*
* @return integer
*/
public function type()
{
return $this->type;
}
/**
* Retrieve the account premium days.
*
* @return integer
*/
public function premiumDays()
{
return $this->premdays;
}
/**
* Retrieve the account last day.
*
* @return integer
*/
public function lastDay()
{
return $this->lastday;
}
/**
* Retrieve the account creation date.
*
* @return \Carbon\Carbon
*/
public function creation()
{
return Carbon::createFromTimestamp($this->creation);
}
/**
* Check if the account has been confirmed.
*
* @return boolean
*/
public function isConfirmed()
{
return $this->properties->emailCode() === null;
}
/**
* Check if the account has been registered.
*
* @return boolean
*/
public function isRegistered()
{
return (boolean) $this->registration;
}
/**
* Check if the account has been deleted.
*
* @return boolean
*/
public function isDeleted()
{
return ! ($this->properties->deletion()->format('Y') < 0);
}
/**
* Check if the account has a pending email address.
*
* @return boolean
*/
public function hasPendingEmail()
{
return $this->properties->email() !== null;
}
/**
* Check if the user can accept the new email address.
*
* @return boolean
*/
public function canAcceptPendingEmail()
{
return $this->hasPendingEmail() and $this->properties->emailDate()->isPast();
}
/**
* Check if the account has a pending registration change.
*
* @return boolean
*/
public function hasPendingRegistration()
{
return $this->isRegistered() and $this->registration->requestFirstname() !== null;
}
/**
* Check if the user can accept the new registration data.
*
* @return boolean
*/
public function canAcceptPendingRegistration()
{
return $this->hasPendingRegistration() and $this->registration->requestDate()->isPast();
}
/**
* Generate a recovery key.
*
* @param boolean $pretend false
* @return string
*/
public function generateRecoveryKey($pretend = false)
{
$key = strtoupper(implode('-', str_split(str_random(20), 5)));
if (! $pretend) {
$this->properties->recovery_key = bcrypt($key);
$this->properties->save();
}
return $key;
}
}