1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Services\Auth\Back; |
4
|
|
|
|
5
|
|
|
use App\Services\Auth\Back\Enums\UserRole; |
6
|
|
|
use App\Services\Auth\Back\Enums\UserStatus; |
7
|
|
|
use App\Services\Auth\Back\Exceptions\UserIsAlreadyActivated; |
8
|
|
|
use App\Services\Auth\Back\Mail\ResetPassword; |
9
|
|
|
use App\Services\Auth\User as BaseUser; |
10
|
|
|
use Mail; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* @property \App\Services\Auth\Back\Enums\UserRole $role |
14
|
|
|
* @property \App\Services\Auth\Back\Enums\UserStatus $status |
15
|
|
|
*/ |
16
|
|
|
class User extends BaseUser |
17
|
|
|
{ |
18
|
|
|
protected $table = 'users_back'; |
19
|
|
|
|
20
|
|
|
public function guardDriver(): string |
21
|
|
|
{ |
22
|
|
|
return 'back'; |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
public function getHomeUrl(): string |
26
|
|
|
{ |
27
|
|
|
return url('blender'); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function getProfileUrl(): string |
31
|
|
|
{ |
32
|
|
|
return action('Back\AdministratorsController@edit', $this->id); |
|
|
|
|
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function getStatusAttribute(): UserStatus |
36
|
|
|
{ |
37
|
|
|
return new UserStatus($this->attributes['status']); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function setStatusAttribute(UserStatus $status) |
41
|
|
|
{ |
42
|
|
|
$this->attributes['status'] = $status->getValue(); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function hasStatus(UserStatus $status): bool |
46
|
|
|
{ |
47
|
|
|
return $this->status->equals($status); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function isActive(): bool |
51
|
|
|
{ |
52
|
|
|
return $this->hasStatus(UserStatus::ACTIVE()); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function activate(): User |
56
|
|
|
{ |
57
|
|
|
if ($this->status->doesntEqual(UserStatus::WAITING_FOR_APPROVAL())) { |
58
|
|
|
throw new UserIsAlreadyActivated(); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
$this->status = UserStatus::ACTIVE(); |
62
|
|
|
|
63
|
|
|
return $this; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function getRoleAttribute(): UserRole |
67
|
|
|
{ |
68
|
|
|
return new UserRole($this->attributes['role']); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
public function setRoleAttribute(UserRole $role) |
72
|
|
|
{ |
73
|
|
|
$this->attributes['role'] = $role->getValue(); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
public function hasRole(UserRole $role): bool |
77
|
|
|
{ |
78
|
|
|
return $this->role->equals($role); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Send the password reset notification. |
83
|
|
|
* |
84
|
|
|
* @param string $token |
85
|
|
|
*/ |
86
|
|
|
public function sendPasswordResetNotification($token) |
87
|
|
|
{ |
88
|
|
|
Mail::to($this->email)->send(new ResetPassword($this, $token)); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
public function delete() |
92
|
|
|
{ |
93
|
|
|
if (current_back_user() && current_back_user()->id === $this->id) { |
94
|
|
|
abort(406); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
return parent::delete(); |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: