|
1
|
|
|
<?php namespace Arcanesoft\Auth\Models; |
|
2
|
|
|
|
|
3
|
|
|
use Arcanedev\LaravelAuth\Models\User as BaseUserModel; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* Class User |
|
7
|
|
|
* |
|
8
|
|
|
* @package Arcanesoft\Auth\Models |
|
9
|
|
|
* @author ARCANEDEV <[email protected]> |
|
10
|
|
|
* |
|
11
|
|
|
* @property \Arcanesoft\Auth\Models\PasswordReset passwordReset |
|
12
|
|
|
*/ |
|
13
|
|
|
class User extends BaseUserModel |
|
|
|
|
|
|
14
|
|
|
{ |
|
15
|
|
|
/* ------------------------------------------------------------------------------------------------ |
|
16
|
|
|
| Traits |
|
17
|
|
|
| ------------------------------------------------------------------------------------------------ |
|
18
|
|
|
*/ |
|
19
|
|
|
use Presenters\UserPresenter; |
|
20
|
|
|
|
|
21
|
|
|
/* ------------------------------------------------------------------------------------------------ |
|
22
|
|
|
| Relationships |
|
23
|
|
|
| ------------------------------------------------------------------------------------------------ |
|
24
|
|
|
*/ |
|
25
|
|
|
/** |
|
26
|
|
|
* Password reset relationship. |
|
27
|
|
|
* |
|
28
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\HasOne |
|
29
|
|
|
*/ |
|
30
|
|
|
public function passwordReset() |
|
31
|
|
|
{ |
|
32
|
|
|
return $this->hasOne(PasswordReset::class, 'email', 'email'); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/* ------------------------------------------------------------------------------------------------ |
|
36
|
|
|
| Main Function |
|
37
|
|
|
| ------------------------------------------------------------------------------------------------ |
|
38
|
|
|
*/ |
|
39
|
|
|
/** |
|
40
|
|
|
* Get a user from a hashed id or fail if not found. |
|
41
|
|
|
* |
|
42
|
|
|
* @param string $hashedId |
|
43
|
|
|
* |
|
44
|
|
|
* @return self |
|
45
|
|
|
* |
|
46
|
|
|
* @throws \Illuminate\Database\Eloquent\ModelNotFoundException |
|
47
|
|
|
*/ |
|
48
|
|
|
public static function firstHashedOrFail($hashedId) |
|
49
|
|
|
{ |
|
50
|
|
|
return self::withTrashed()->withHashedId($hashedId)->firstOrFail(); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/* ------------------------------------------------------------------------------------------------ |
|
54
|
|
|
| Check Functions |
|
55
|
|
|
| ------------------------------------------------------------------------------------------------ |
|
56
|
|
|
*/ |
|
57
|
|
|
/** |
|
58
|
|
|
* Check if user is an administrator. |
|
59
|
|
|
* |
|
60
|
|
|
* @return bool |
|
61
|
|
|
*/ |
|
62
|
|
|
public function isAdmin() |
|
63
|
|
|
{ |
|
64
|
|
|
return parent::isAdmin() || $this->hasRoleSlug(Role::ADMINISTRATOR); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* Check if user is a moderator. |
|
69
|
|
|
* |
|
70
|
|
|
* @return bool |
|
71
|
|
|
*/ |
|
72
|
|
|
public function isModerator() |
|
73
|
|
|
{ |
|
74
|
|
|
return $this->hasRoleSlug(Role::MODERATOR); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* Check if user is a member. |
|
79
|
|
|
* |
|
80
|
|
|
* @return bool |
|
81
|
|
|
*/ |
|
82
|
|
|
public function isMember() |
|
83
|
|
|
{ |
|
84
|
|
|
return $this->hasRoleSlug(Role::MEMBER); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* Check if user has a password reset. |
|
89
|
|
|
* |
|
90
|
|
|
* @return bool |
|
91
|
|
|
*/ |
|
92
|
|
|
public function hasPasswordReset() |
|
93
|
|
|
{ |
|
94
|
|
|
return ! is_null($this->passwordReset); |
|
95
|
|
|
} |
|
96
|
|
|
} |
|
97
|
|
|
|