Completed
Pull Request — master (#15)
by ARCANEDEV
04:13
created

User::isImpersonating()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
ccs 0
cts 0
cp 0
cc 1
eloc 2
nc 1
nop 0
crap 2
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
0 ignored issues
show
Bug introduced by
There is at least one abstract method in this class. Maybe declare it as abstract, or implement the remaining methods: can, getAuthIdentifier, getAuthIdentifierName, getAuthPassword, getEmailForPasswordReset, getRememberToken, getRememberTokenName, sendPasswordResetNotification, setAttribute, setRememberToken
Loading history...
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