|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Models; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Database\Eloquent\Collection; |
|
6
|
|
|
use Illuminate\Support\Facades\Config; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* Class ChocolateyId. |
|
10
|
|
|
* |
|
11
|
|
|
* @property bool mail_verified |
|
12
|
|
|
* @property int last_logged_id |
|
13
|
|
|
*/ |
|
14
|
|
|
class ChocolateyId extends ChocolateyModel |
|
15
|
|
|
{ |
|
16
|
|
|
/** |
|
17
|
|
|
* Disable Timestamps. |
|
18
|
|
|
* |
|
19
|
|
|
* @var bool |
|
20
|
|
|
*/ |
|
21
|
|
|
public $timestamps = false; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* The table associated with the model. |
|
25
|
|
|
* |
|
26
|
|
|
* @var string |
|
27
|
|
|
*/ |
|
28
|
|
|
protected $table = 'chocolatey_users_id'; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Primary Key of the Table. |
|
32
|
|
|
* |
|
33
|
|
|
* @var string |
|
34
|
|
|
*/ |
|
35
|
|
|
protected $primaryKey = 'mail'; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* The Appender(s) of the Model. |
|
39
|
|
|
* |
|
40
|
|
|
* @var array |
|
41
|
|
|
*/ |
|
42
|
|
|
protected $appends = ['relatedAccounts']; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* The attributes that are mass assignable. |
|
46
|
|
|
* |
|
47
|
|
|
* @var array |
|
48
|
|
|
*/ |
|
49
|
|
|
protected $fillable = ['mail', 'password', 'last_logged_id', 'mail_verified']; |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Store a new Azure Id Account. |
|
53
|
|
|
* |
|
54
|
|
|
* @param string $userMail |
|
55
|
|
|
* @param string $userPassword |
|
56
|
|
|
* |
|
57
|
|
|
* @return ChocolateyId |
|
58
|
|
|
*/ |
|
59
|
|
|
public function store(string $userMail, string $userPassword): ChocolateyId |
|
60
|
|
|
{ |
|
61
|
|
|
$this->attributes['password'] = hash(Config::get('chocolatey.security.hash'), $userPassword); |
|
62
|
|
|
$this->attributes['mail'] = $userMail; |
|
63
|
|
|
$this->timestamps = false; |
|
64
|
|
|
|
|
65
|
|
|
$this->save(); |
|
66
|
|
|
|
|
67
|
|
|
return $this; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* Get All Accounts related with this E-mail. |
|
72
|
|
|
* |
|
73
|
|
|
* @return Collection|static[] |
|
74
|
|
|
*/ |
|
75
|
|
|
public function getRelatedAccountsAttribute() |
|
76
|
|
|
{ |
|
77
|
|
|
return User::where('mail', $this->attributes['mail'])->get(); |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
|