2016-01-03 05:48:37 +05:30
|
|
|
<?php
|
2016-01-15 14:51:27 +05:30
|
|
|
namespace api\controllers;
|
2016-01-03 05:48:37 +05:30
|
|
|
|
2016-05-14 05:17:17 +05:30
|
|
|
use api\models\authentication\ConfirmEmailForm;
|
|
|
|
use api\models\authentication\RegistrationForm;
|
2018-04-18 02:17:25 +05:30
|
|
|
use api\models\authentication\RepeatAccountActivationForm;
|
2016-06-17 02:02:23 +05:30
|
|
|
use common\helpers\Error as E;
|
2016-01-03 05:48:37 +05:30
|
|
|
use Yii;
|
|
|
|
use yii\filters\AccessControl;
|
2016-02-24 03:45:04 +05:30
|
|
|
use yii\helpers\ArrayHelper;
|
2016-01-03 05:48:37 +05:30
|
|
|
|
2016-01-15 14:51:27 +05:30
|
|
|
class SignupController extends Controller {
|
2016-01-03 05:48:37 +05:30
|
|
|
|
2017-09-19 22:36:16 +05:30
|
|
|
public function behaviors(): array {
|
2016-02-24 03:45:04 +05:30
|
|
|
return ArrayHelper::merge(parent::behaviors(), [
|
|
|
|
'authenticator' => [
|
2016-03-13 23:54:49 +05:30
|
|
|
'except' => ['index', 'repeat-message', 'confirm'],
|
2016-02-24 03:45:04 +05:30
|
|
|
],
|
2016-01-03 05:48:37 +05:30
|
|
|
'access' => [
|
2016-01-21 02:44:29 +05:30
|
|
|
'class' => AccessControl::class,
|
2016-01-03 05:48:37 +05:30
|
|
|
'rules' => [
|
|
|
|
[
|
2016-03-13 23:54:49 +05:30
|
|
|
'actions' => ['index', 'repeat-message', 'confirm'],
|
2016-01-03 05:48:37 +05:30
|
|
|
'allow' => true,
|
|
|
|
'roles' => ['?'],
|
|
|
|
],
|
|
|
|
],
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2016-01-21 02:44:29 +05:30
|
|
|
public function verbs() {
|
|
|
|
return [
|
|
|
|
'register' => ['POST'],
|
|
|
|
'confirm' => ['POST'],
|
2016-03-13 04:49:00 +05:30
|
|
|
'new-message' => ['POST'],
|
2016-01-21 02:44:29 +05:30
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2024-12-02 15:40:55 +05:30
|
|
|
public function actionIndex(): array {
|
2016-01-15 14:51:27 +05:30
|
|
|
$model = new RegistrationForm();
|
2016-01-03 05:48:37 +05:30
|
|
|
$model->load(Yii::$app->request->post());
|
2016-01-15 14:51:27 +05:30
|
|
|
if (!$model->signup()) {
|
2016-01-03 05:48:37 +05:30
|
|
|
return [
|
|
|
|
'success' => false,
|
2016-11-30 23:27:30 +05:30
|
|
|
'errors' => $model->getFirstErrors(),
|
2016-01-03 05:48:37 +05:30
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
return [
|
|
|
|
'success' => true,
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2024-12-02 15:40:55 +05:30
|
|
|
public function actionRepeatMessage(): array {
|
2016-03-13 23:54:49 +05:30
|
|
|
$model = new RepeatAccountActivationForm();
|
2016-03-13 04:49:00 +05:30
|
|
|
$model->load(Yii::$app->request->post());
|
2016-03-13 23:54:49 +05:30
|
|
|
if (!$model->sendRepeatMessage()) {
|
2016-03-13 04:49:00 +05:30
|
|
|
$response = [
|
|
|
|
'success' => false,
|
2016-11-30 23:27:30 +05:30
|
|
|
'errors' => $model->getFirstErrors(),
|
2016-03-13 04:49:00 +05:30
|
|
|
];
|
|
|
|
|
2016-08-03 18:27:41 +05:30
|
|
|
if (ArrayHelper::getValue($response['errors'], 'email') === E::RECENTLY_SENT_MESSAGE) {
|
2019-12-21 03:53:58 +05:30
|
|
|
/** @var \common\models\confirmations\RegistrationConfirmation $activation */
|
2016-05-11 01:10:06 +05:30
|
|
|
$activation = $model->getActivation();
|
2016-03-13 04:49:00 +05:30
|
|
|
$response['data'] = [
|
2019-12-21 03:53:58 +05:30
|
|
|
'canRepeatIn' => $activation->canResendAt(),
|
2016-03-13 04:49:00 +05:30
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
return $response;
|
|
|
|
}
|
|
|
|
|
|
|
|
return [
|
|
|
|
'success' => true,
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2024-12-02 15:40:55 +05:30
|
|
|
public function actionConfirm(): array {
|
2016-01-21 02:44:29 +05:30
|
|
|
$model = new ConfirmEmailForm();
|
|
|
|
$model->load(Yii::$app->request->post());
|
2016-05-30 05:14:17 +05:30
|
|
|
if (!($result = $model->confirm())) {
|
2016-01-21 02:44:29 +05:30
|
|
|
return [
|
|
|
|
'success' => false,
|
2016-11-30 23:27:30 +05:30
|
|
|
'errors' => $model->getFirstErrors(),
|
2016-01-21 02:44:29 +05:30
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2016-05-30 05:14:17 +05:30
|
|
|
return array_merge([
|
2016-01-21 02:44:29 +05:30
|
|
|
'success' => true,
|
2019-08-01 14:47:12 +05:30
|
|
|
], $result->formatAsOAuth2Response());
|
2016-01-21 02:44:29 +05:30
|
|
|
}
|
|
|
|
|
2016-01-03 05:48:37 +05:30
|
|
|
}
|