Test Setup Failed
Push — master ( ef125c...60f940 )
by he
08:55
created

User::getEmail()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
c 0
b 0
f 0
nc 2
nop 0
dl 0
loc 7
rs 10
1
<?php
2
3
namespace App\Entities;
4
5
use Carbon\Carbon;
6
use Illuminate\Auth\MustVerifyEmail;
7
use Illuminate\Contracts\Auth\MustVerifyEmail as MustVerifyEmailContract;
8
use Illuminate\Foundation\Auth\User as Authenticatable;
9
use Illuminate\Notifications\Notifiable;
10
use Laratrust\Traits\LaratrustUserTrait;
11
12
/**
13
 * Class User.
14
 *
15
 * @property int $id
16
 * @property string $username
17
 * @property string $email
18
 * @property string $nick
19
 * @property string $school
20
 * @property string $locale
21
 * @property int $language
22
 * @property string $password
23
 * @property string $remember_token
24
 * @property int $submit
25
 * @property int $email_level
26
 * @property int $solved
27
 * @property int $status
28
 * @property Carbon $email_verified_at
29
 * @property Carbon $created_at
30
 * @property Carbon $updated_at
31
 */
32
class User extends Authenticatable implements MustVerifyEmailContract
33
{
34
    use Notifiable, LaratrustUserTrait, MustVerifyEmail;
0 ignored issues
show
introduced by
The trait Laratrust\Traits\LaratrustUserTrait requires some properties which are not provided by App\Entities\User: $forceDeleting, $permissions
Loading history...
35
36
    const ST_ACTIVE = 0;
37
    const ST_INACTIVE = 1;
38
39
    /**
40
     * The attributes that are mass assignable.
41
     *
42
     * @var array
43
     */
44
    protected $fillable = [
45
        'username',
46
        'email',
47
        'school',
48
        'nick',
49
        'email_level',
50
        'confirmed',
51
        'language',
52
        'submit',
53
        'solved',
54
        'locale',
55
        'language',
56
        'status',
57
    ];
58
59
    /**
60
     * The attributes that should be hidden for arrays.
61
     *
62
     * @var array
63
     */
64
    protected $hidden = [
65
        'password',
66
        'remember_token',
67
    ];
68
69
    public function lastAccess()
70
    {
71
        return $this->logs()->orderBy('created_at', 'desc')->limit(1);
72
    }
73
74
    public function showEmail()
75
    {
76
        return $this->email_level != 0;
77
    }
78
79
    public function getEmail()
80
    {
81
        if ($this->email_level == 2) {
82
            return base64_encode($this->email);
83
        }
84
85
        return $this->email;
86
    }
87
88
    public function logs()
89
    {
90
        return $this->hasMany(LoginLog::class, 'user_id');
91
    }
92
93
    public function contests()
94
    {
95
        return $this->belongsToMany(Contest::class, 'contest_user', 'user_id');
96
    }
97
98
    public function isActive()
99
    {
100
        return $this->status === self::ST_ACTIVE;
101
    }
102
}
103