forked from REBELinBLUE/deployer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUser.php
114 lines (100 loc) · 2.53 KB
/
User.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<?php
namespace REBELinBLUE\Deployer;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use McCool\LaravelAutoPresenter\HasPresenter;
use REBELinBLUE\Deployer\Notifications\System\ResetPassword;
use REBELinBLUE\Deployer\Traits\BroadcastChanges;
use REBELinBLUE\Deployer\View\Presenters\UserPresenter;
/**
* User model.
*/
class User extends Authenticatable implements HasPresenter
{
use SoftDeletes, BroadcastChanges, Notifiable;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = ['name', 'email', 'password', 'skin', 'language', 'scheme', 'is_admin'];
/**
* The attributes excluded from the model's JSON form.
*
* @var array
*/
protected $hidden = ['deleted_at', 'updated_at', 'password', 'remember_token', 'google2fa_secret'];
/**
* Additional attributes to include in the JSON representation.
*
* @var array
*/
protected $appends = ['has_two_factor_authentication'];
/**
* The attributes that should be casted to native types.
*
* @var array
*/
protected $casts = [
'id' => 'integer',
'is_admin' => 'boolean',
];
/**
* Generate a change email token.
*
* @return string
*/
public function requestEmailToken()
{
$this->email_token = token(40);
$this->save();
return $this->email_token;
}
/**
* Gets the view presenter.
*
* @return string
*/
public function getPresenterClass()
{
return UserPresenter::class;
}
/**
* Determines whether the user has Google 2FA enabled.
*
* @return bool
*/
public function getHasTwoFactorAuthenticationAttribute()
{
return !empty($this->google2fa_secret);
}
/**
* Send the password reset notification.
*
* @param string $token
*/
public function sendPasswordResetNotification($token)
{
// FIXME: Clean this up?
$this->notify(new ResetPassword($token, app('translator')));
}
/**
* Has many relationship for projects.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
public function projects()
{
return $this->belongsToMany(Project::class);
}
/**
* Is this user a super administrator.
*
* @return bool
*/
public function isAdmin()
{
return $this->is_admin;
}
}