Blame view

app/User/User.php 5.02 KB
e77200db5   nologostudio.ru   Initial commit
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
  <?php
  
  namespace FootyRoom\User;
  
  use FootyRoom\Core\EventGenerator;
  use Illuminate\Auth\Authenticatable;
  use FootyRoom\Core\User\UserRegistered;
  use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableInterface;
  
  class User implements AuthenticatableInterface
  {
      use EventGenerator;
  
      // use Accessors;
      use Authenticatable;
  
      /**
       * Number of days the user has to stay in the newborn status.
       */
      protected static $birthPeriod = 10;
  
      /**
       * @var int
       */
      protected $user_id;
  
      public function getUserId()
      {
          return $this->user_id;
      }
  
      public function getAuthIdentifier()
      {
          return $this->getUserId();
      }
  
      /**
       * @var string
       */
      protected $username;
  
      public function getUsername()
      {
          return $this->username;
      }
  
      /**
       * @var string
       */
      protected $fullname;
  
      public function getFullname()
      {
          return $this->fullname;
      }
  
      public function setFullname($fullname)
      {
          $this->fullname = $fullname;
      }
  
      /**
       * Hashed representation of password.
       *
       * @var string
       */
      protected $password;
  
      /**
       * Password getter.
       *
       * @return string
       */
      public function getPassword()
      {
          return $this->getAuthPassword();
      }
  
      protected $email;
  
      public function getEmail()
      {
          return $this->email;
      }
  
      protected $gender;
  
      public function getGender()
      {
          return $this->gender;
      }
  
      protected $dob;
  
      public function getDob()
      {
          return $this->dob;
      }
  
      protected $user_role;
  
      public function getRole()
      {
          return $this->user_role;
      }
  
      protected $status;
  
      public function getStatus()
      {
          return $this->status;
      }
  
      protected $date_registered;
  
      public function getDateRegistered()
      {
          return $this->date_registered;
      }
  
      protected $national_team;
  
      public function getNationalTeam()
      {
          return $this->national_team;
      }
  
      protected $national_team_id;
  
      protected $club_team;
  
      public function getClubTeam()
      {
          return $this->club_team;
      }
  
      protected $club_team_id;
  
      protected $location;
  
      public function getLocation()
      {
          return $this->location;
      }
  
      public function getTimezone()
      {
          return $this->tz;
      }
  
      protected $noSpoilers;
  
      public function isNoSpoilers()
      {
          return $this->noSpoilers;
      }
  
      protected $tz;
  
      protected $activation_key;
  
      /**
       * Constructor.
       *
       * @param array|object
       */
      public function __construct($options)
      {
          $options = (object) $options;
  
          foreach ($options as $key => $value) {
              if (property_exists($this, $key)) {
                  $this->{$key} = $value;
              }
          }
      }
  
      /**
       * Register this user under specified user id.
       *
       * @param int $userId
       */
      public function register($userId)
      {
          $this->user_id = $userId;
  
          $this->raise(new UserRegistered($this));
      }
  
      public function birth()
      {
          $this->status = '';
      }
  
      public function readyForBirth()
      {
          return date_diff(
              new \DateTime($this->date_registered),
              new \DateTime()
          )->format('%r%a') > self::$birthPeriod;
      }
  
      public function isNewborn()
      {
          return $this->status === 'newborn';
      }
  
      public function isBanned()
      {
          return $this->status === 'banned';
      }
  
      /**
       * Decides whether user's account is open.
       *
       * @return bool
       */
      public function accountOpen()
      {
          if ($this->status === 'banned' || $this->status === 'activation') {
              return false;
          }
  
          return true;
      }
  
      public function canCreateBans()
      {
          if ($this->user_role > 20) {
              return true;
          }
  
          return false;
      }
  
      public function canGiveBettingTips(): bool
      {
          if ($this->user_role === 11 || $this->user_role >= 26) {
              return true;
          }
  
          return false;
      }
  
      /**
       * Decides whether user is a moderator.
       *
       * @return bool
       */
      public function isModerator()
      {
          return $this->user_role >= 20;
      }
  
      public function isAdmin(): bool
      {
          return $this->user_role >= 30;
      }
  
      /**
       * Returns `true` if given password matches stored password.
       *
       * @param  string $plain
       *
       * @return bool
       */
      public function comparePassword($plain)
      {
          return $this->password === md5($plain);
      }
  
      /**
       * Set the token value for the "remember me" session. We don't do anything
       * here since our remember token is a users hashed password.
       *
       * @param  string  $value
       * @return void
       */
      public function setRememberToken($value)
      {
      }
  
      /**
       * Get the column name for the "remember me" token.
       *
       * @return string
       */
      public function getRememberTokenName()
      {
          return 'password';
      }
  }