1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Spinen\Formio\Concerns; |
4
|
|
|
|
5
|
|
|
use Illuminate\Container\Container; |
6
|
|
|
use Illuminate\Contracts\Encryption\Encrypter; |
7
|
|
|
use Illuminate\Support\Facades\Crypt; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Trait HasForms |
11
|
|
|
* |
12
|
|
|
* @package Spinen\Formio |
13
|
|
|
* |
14
|
|
|
* @property string $formio_password |
15
|
|
|
*/ |
16
|
|
|
trait HasForms |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* Accessor for FormioPassword. |
20
|
|
|
* |
21
|
|
|
* @return string |
22
|
|
|
*/ |
23
|
2 |
|
public function getFormioPasswordAttribute() |
24
|
|
|
{ |
25
|
2 |
|
return is_null($this->attributes['formio_password'] ?? null) |
26
|
1 |
|
? null |
27
|
1 |
|
: $this->resolveEncrypter() |
28
|
2 |
|
->decrypt($this->attributes['formio_password']); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Build the array to login to Formio |
33
|
|
|
* |
34
|
|
|
* @return array |
35
|
|
|
*/ |
36
|
1 |
|
public function getLoginData() |
37
|
|
|
{ |
38
|
|
|
return [ |
39
|
1 |
|
'email' => $this->email, |
40
|
1 |
|
'password' => $this->formio_password, |
41
|
|
|
]; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Build the array to register a user to Formio |
46
|
|
|
* |
47
|
|
|
* @return array |
48
|
|
|
*/ |
49
|
1 |
|
public function getRegistrationData() |
50
|
|
|
{ |
51
|
|
|
return [ |
52
|
1 |
|
'email' => $this->email, |
53
|
1 |
|
'firstName' => $this->first_name, |
54
|
1 |
|
'lastName' => $this->last_name, |
55
|
1 |
|
'password' => $this->formio_password, |
56
|
|
|
]; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Make sure that the formio_password is fillable & protected |
61
|
|
|
*/ |
62
|
1 |
|
public function initializeHasFormsTrait() |
63
|
|
|
{ |
64
|
1 |
|
$this->fillable[] = 'formio_password'; |
|
|
|
|
65
|
1 |
|
$this->hidden[] = 'formio_password'; |
|
|
|
|
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Resolve the encrypter from the IoC |
70
|
|
|
* |
71
|
|
|
* We are staying away from the Crypt facade, so that we can support PHP 7.4 with Laravel 5.x |
72
|
|
|
* |
73
|
|
|
* TODO: Remove this when dropping support of Laravel 5.5 |
74
|
|
|
* |
75
|
|
|
* @return Encrypter |
76
|
|
|
*/ |
77
|
2 |
|
protected function resolveEncrypter() |
78
|
|
|
{ |
79
|
2 |
|
return Container::getInstance() |
80
|
|
|
->make(Encrypter::class); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Mutator for FormioPassword. |
85
|
|
|
* |
86
|
|
|
* @param string $formio_password |
87
|
|
|
*/ |
88
|
2 |
|
public function setFormioPasswordAttribute($formio_password) |
89
|
|
|
{ |
90
|
2 |
|
$this->attributes['formio_password'] = is_null($formio_password) |
|
|
|
|
91
|
1 |
|
? null |
92
|
1 |
|
: $this->resolveEncrypter() |
93
|
|
|
->encrypt($formio_password); |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
|