Test Setup Failed
Push — master ( 9340e9...95bd49 )
by he
05:10
created

User::logs()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
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 $access_at
30
 * @property Carbon $created_at
31
 * @property Carbon $updated_at
32
 */
33
class User extends Authenticatable implements MustVerifyEmailContract
34
{
35
    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...
36
37
    const ST_ACTIVE = 0;
38
    const ST_INACTIVE = 1;
39
40
    /**
41
     * The attributes that are mass assignable.
42
     *
43
     * @var array
44
     */
45
    protected $fillable = [
46
        'username',
47
        'email',
48
        'school',
49
        'nick',
50
        'email_level',
51
        'confirmed',
52
        'language',
53
        'submit',
54
        'solved',
55
        'locale',
56
        'language',
57
        'status',
58
    ];
59
60
    public $dates = [
61
        'email_verified_at',
62
        'access_at'
63
    ];
64
65
    /**
66
     * The attributes that should be hidden for arrays.
67
     *
68
     * @var array
69
     */
70
    protected $hidden = [
71
        'password',
72
        'remember_token',
73
    ];
74
75
    public function showEmail()
76
    {
77
        return $this->email_level != 0;
78
    }
79
80
    public function getEmail()
81
    {
82
        if ($this->email_level == 2) {
83
            return base64_encode($this->email);
84
        }
85
86
        return $this->email;
87
    }
88
89
    public function logs()
90
    {
91
        return $this->hasMany(LoginLog::class, 'user_id')->orderBy('created_at', 'desc');
92
    }
93
94
    public function contests()
95
    {
96
        return $this->belongsToMany(Contest::class, 'contest_user', 'user_id');
97
    }
98
99
    public function isActive()
100
    {
101
        return $this->status === self::ST_ACTIVE;
102
    }
103
}
104