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