Skip to content

Commit

Permalink
Added error handle for whois
Browse files Browse the repository at this point in the history
  • Loading branch information
tafid committed Nov 11, 2016
1 parent bc3159b commit 0118c91
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 7 deletions.
15 changes: 12 additions & 3 deletions src/controllers/WhoisController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,25 @@
use hipanel\helpers\ArrayHelper;
use hipanel\modules\domain\repositories\DomainTariffRepository;
use hipanel\modules\domain\models\Whois;
use yii\base\Exception;
use yii\web\UnprocessableEntityHttpException;
use Yii;

class WhoisController extends \hipanel\base\CrudController
{
private function getWhoisModel($domain)
{
$whois = Yii::$app->hiart->createCommand()->perform('domainGetWhois', ['domain' => $domain]);

$whois = ['domain' => $domain];
try {
$whois = Yii::$app->hiart->createCommand()->perform('domainGetWhois', ['domain' => $domain]);
} catch (Exception $e) {
$message = $e->getMessage();
switch ($message) {
case 'domain available':
$whois['available'] = true;
break;
}
}
$model = reset(Whois::find()->populate([$whois]));

return $model;
Expand Down Expand Up @@ -41,7 +51,6 @@ public function actionLookup()
$request = Yii::$app->request;
$model = $this->getWhoisModel($request->post('domain'));
if ($request->isAjax) {

return $this->renderAjax('_view', [
'model' => $model,
]);
Expand Down
1 change: 1 addition & 0 deletions src/messages/ru/domain.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,4 +197,5 @@

'Set IPs' => 'Сменить IP',
'What is a NS-server and how it works' => 'Что такое NS-сервер и как он работает',
'This domain is available for registration' => 'Этот домен доступен для регистрации',
];
1 change: 1 addition & 0 deletions src/models/Whois.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public function attributes()
return [
'domain', 'registrar', 'nss', 'created', 'updated',
'expires', 'rawdata', 'ip', 'country_name', 'city',
'available',
];
}

Expand Down
32 changes: 28 additions & 4 deletions src/views/whois/_view.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
/** @var string $sShotSrc */
/** @var \hipanel\modules\domain\models\Domain $model */

use hipanel\modules\dashboard\widgets\SmallBox;
use hipanel\modules\domain\widgets\WhoisData;
use hipanel\widgets\ArraySpoiler;
use toriphes\lazyload\LazyLoad;
use yii\helpers\Html;
use yii\widgets\DetailView;

$this->registerCss("
Expand Down Expand Up @@ -85,8 +87,30 @@
<div class="well well-sm"><?= WhoisData::widget(['data' => $model->rawdata]) ?></div>
</div>
</div>
<?php else: ?>
<div class="bg-danger text-center">
<?= Yii::t('hipanel/domain', 'You have entered wrong domain name or domain name with unsupported zone.') ?>
</div>
<?php elseif ($model->available === true) : ?>
<table class="table">
<thead>
<tr class="success">
<td style="vertical-align: middle;">
<?= Yii::t('hipanel/domain', 'This domain is available for registration') ?>
</td>
<td>
<?= Html::a('<i class="fa fa-fw fa-cart-plus"></i> ' . Yii::t('hipanel/domain', 'Buy domain'),
['@domain/add-to-cart-registration', 'name' => $model->domain],
['class' => 'btn btn-flat btn-sm ' . SmallBox::COLOR_OLIVE]
) ?>
</td>
</tr>
</thead>
</table>
<?php else : ?>
<table class="table">
<thead>
<tr class="danger">
<td class="text-center">
<?= Yii::t('hipanel/domain', 'You have entered wrong domain name or domain name with unsupported zone.') ?>
</td>
</tr>
</thead>
</table>
<?php endif ?>

0 comments on commit 0118c91

Please sign in to comment.