|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* HIAM module for MRDP database compatibility |
|
4
|
|
|
* |
|
5
|
|
|
* @link https://github.com/hiqdev/hiam-mrdp |
|
6
|
|
|
* @package hiam-mrdp |
|
7
|
|
|
* @license BSD-3-Clause |
|
8
|
|
|
* @copyright Copyright (c) 2016, HiQDev (http://hiqdev.com/) |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace hiam\mrdp\controllers; |
|
12
|
|
|
|
|
13
|
|
|
use hiam\mrdp\exceptions\BadConfirmException; |
|
14
|
|
|
use Yii; |
|
15
|
|
|
use yii\helpers\Json; |
|
16
|
|
|
use yii\web\ForbiddenHttpException; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* MRDP controller. |
|
20
|
|
|
*/ |
|
21
|
|
|
class MrdpController extends \yii\web\Controller |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* Implements login from MRDP panel. |
|
25
|
|
|
* @param $confirm_data confirmation data |
|
26
|
|
|
* @param $goto url to go to on success |
|
27
|
|
|
* @throws ForbiddenHttpException when login confirmation is broken |
|
28
|
|
|
*/ |
|
29
|
|
|
public function actionLogin(array $confirm_data, $goto) |
|
30
|
|
|
{ |
|
31
|
|
|
$url = 'http://hiapi.ahnames.com/verifyConfirmation?' . http_build_query([ |
|
32
|
|
|
'auth_ip' => Yii::$app->request->getUserIp(), |
|
33
|
|
|
'what' => 'redirect_hipanel', |
|
34
|
|
|
'confirm_data' => $confirm_data, |
|
35
|
|
|
]); |
|
36
|
|
|
$res = Json::decode(file_get_contents($url)); |
|
37
|
|
|
if (!empty($res['login']) && empty($res['_error'])) { |
|
38
|
|
|
$user = $this->user->findIdentity($res['login']); |
|
39
|
|
|
} else { |
|
40
|
|
|
throw new ForbiddenHttpException('Bad confirmation', 0, new BadConfirmException($res)); |
|
41
|
|
|
} |
|
42
|
|
|
if (!$user) { |
|
43
|
|
|
Yii::$app->session->setFlash('error', Yii::t('hiam', 'Failed login.')); |
|
44
|
|
|
return $this->goHome(); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
$this->user->login($user); |
|
48
|
|
|
|
|
49
|
|
|
return $this->redirect($goto); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
public function getUser() |
|
53
|
|
|
{ |
|
54
|
|
|
return Yii::$app->user; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
public function actionTestReferralParams() |
|
58
|
|
|
{ |
|
59
|
|
|
return $this->render('test-referral-params', ['params' => $_GET]); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
} |
|
63
|
|
|
|