|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace hiam\mrdp\models; |
|
4
|
|
|
|
|
5
|
|
|
use Yii; |
|
6
|
|
|
use yii\base\Model; |
|
7
|
|
|
use yii\httpclient\Client; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Class EmailConfirm is legacy code from old.ahnemes provided email confirmation. |
|
11
|
|
|
*/ |
|
12
|
|
|
class EmailConfirm extends Model |
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* @var string |
|
16
|
|
|
*/ |
|
17
|
|
|
public $email; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @var string |
|
21
|
|
|
*/ |
|
22
|
|
|
public $client; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @var integer |
|
26
|
|
|
*/ |
|
27
|
|
|
public $id; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @var string The API module name and the method name (in API call names manner) to which the request should be sent. |
|
31
|
|
|
* For example: `clientConfirmEmail` or `contactConfirmEmail` |
|
32
|
|
|
*/ |
|
33
|
|
|
public $what; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @var string |
|
37
|
|
|
*/ |
|
38
|
|
|
public $salt; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @var string |
|
42
|
|
|
*/ |
|
43
|
|
|
public $hash; |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* {@inheritdoc} |
|
47
|
|
|
* @return array |
|
48
|
|
|
*/ |
|
49
|
|
|
public function rules() |
|
50
|
|
|
{ |
|
51
|
|
|
return [ |
|
52
|
|
|
[['id', 'client', 'email', 'what', 'salt', 'hash'], 'required'], |
|
53
|
|
|
[['email'], 'email'], |
|
54
|
|
|
[['client', 'what', 'salt', 'hash'], 'string'], |
|
55
|
|
|
['what', 'in', 'range' => ['clientConfirmEmail', 'contactConfirmEmail']], |
|
56
|
|
|
]; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Send http request to API |
|
61
|
|
|
* @return string|bool |
|
62
|
|
|
*/ |
|
63
|
|
|
public function confirm() |
|
64
|
|
|
{ |
|
65
|
|
|
$error = null; |
|
|
|
|
|
|
66
|
|
|
if (!$this->validate()) { |
|
67
|
|
|
return implode("\n", $this->getFirstErrors()); |
|
68
|
|
|
} |
|
69
|
|
|
$client = new Client(['baseUrl' => Yii::$app->params['hiapi.url']]); |
|
70
|
|
|
$response = $client->createRequest() |
|
71
|
|
|
->setUrl($this->what) |
|
72
|
|
|
->setData(['confirm_data' => $this->attributes]) |
|
73
|
|
|
->send(); |
|
74
|
|
|
$responseData = $response->getData(); |
|
75
|
|
|
if (array_key_exists('_error', $responseData)) { |
|
76
|
|
|
return $responseData['_error']; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
return true; |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.