-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUser.php
More file actions
106 lines (86 loc) · 2.22 KB
/
User.php
File metadata and controls
106 lines (86 loc) · 2.22 KB
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
<?php
namespace App;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Tymon\JWTAuth\Contracts\JWTSubject;
use Hash;
use App\Notifications\VerifyEmail;
class User extends Authenticatable implements JWTSubject
{
use Notifiable;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'first_name', 'last_name', 'email', 'password', 'type',
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password', 'remember_token',
];
/**
* The attributes that should be cast to native types.
*
* @var array
*/
protected $casts = [
'email_verified_at' => 'datetime',
];
public function getJWTIdentifier()
{
return $this->getKey();
}
/**
* Return a key value array, containing any custom claims to be added to the JWT.
*
* @return array
*/
public function getJWTCustomClaims()
{
return [];
}
public static function register($newUser)
{
return static::create([
'email' => $newUser['email'],
'first_name' => $newUser['first_name'],
'last_name' => $newUser['last_name'],
'password' => Hash::make($newUser['password'])
]);
}
private static function makeServiceAccountPassword()
{
return bin2hex(openssl_random_pseudo_bytes(32));
}
public static function registerServiceAccount($username)
{
$password = self::makeServiceAccountPassword();
static::create([
'email' => $username,
'password' => Hash::make($password),
'type' => 'service',
]);
return $password;
}
public function rotateServiceAccountPassword()
{
$password = self::makeServiceAccountPassword();
$this->password = Hash::make($password);
$this->save();
return $password;
}
public function sendEmailVerificationNotification()
{
$this->notify(new VerifyEmail);
}
public function alerts()
{
return $this->hasMany('App\Alert');
}
}