Completed
Push — master ( 5021ae...be2f55 )
by he
08:00
created

User::showEmail()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
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
        return $this->email;
85
    }
86
87
    public function logs()
88
    {
89
        return $this->hasMany(LoginLog::class, 'user_id');
90
    }
91
92
    public function contests()
93
    {
94
        return $this->belongsToMany(Contest::class, 'contest_user', 'user_id');
95
    }
96
97
    public function isActive()
98
    {
99
        return $this->status === self::ST_ACTIVE;
100
    }
101
}
102