mirror of
https://github.com/elyby/accounts.git
synced 2024-11-15 17:56:30 +05:30
bdc96d82c1
Добавлен механизм сохранения сессий и refresh_token
95 lines
2.6 KiB
PHP
95 lines
2.6 KiB
PHP
<?php
|
|
namespace api\controllers;
|
|
|
|
use api\models\authentication\ConfirmEmailForm;
|
|
use api\models\authentication\RepeatAccountActivationForm;
|
|
use api\models\authentication\RegistrationForm;
|
|
use Yii;
|
|
use yii\filters\AccessControl;
|
|
use yii\helpers\ArrayHelper;
|
|
|
|
class SignupController extends Controller {
|
|
|
|
public function behaviors() {
|
|
return ArrayHelper::merge(parent::behaviors(), [
|
|
'authenticator' => [
|
|
'except' => ['index', 'repeat-message', 'confirm'],
|
|
],
|
|
'access' => [
|
|
'class' => AccessControl::class,
|
|
'rules' => [
|
|
[
|
|
'actions' => ['index', 'repeat-message', 'confirm'],
|
|
'allow' => true,
|
|
'roles' => ['?'],
|
|
],
|
|
],
|
|
],
|
|
]);
|
|
}
|
|
|
|
public function verbs() {
|
|
return [
|
|
'register' => ['POST'],
|
|
'confirm' => ['POST'],
|
|
'new-message' => ['POST'],
|
|
];
|
|
}
|
|
|
|
public function actionIndex() {
|
|
$model = new RegistrationForm();
|
|
$model->load(Yii::$app->request->post());
|
|
if (!$model->signup()) {
|
|
return [
|
|
'success' => false,
|
|
'errors' => $this->normalizeModelErrors($model->getErrors()),
|
|
];
|
|
}
|
|
|
|
return [
|
|
'success' => true,
|
|
];
|
|
}
|
|
|
|
public function actionRepeatMessage() {
|
|
$model = new RepeatAccountActivationForm();
|
|
$model->load(Yii::$app->request->post());
|
|
if (!$model->sendRepeatMessage()) {
|
|
$response = [
|
|
'success' => false,
|
|
'errors' => $this->normalizeModelErrors($model->getErrors()),
|
|
];
|
|
|
|
if ($response['errors']['email'] === 'error.recently_sent_message') {
|
|
$activation = $model->getActivation();
|
|
$response['data'] = [
|
|
'canRepeatIn' => $activation->canRepeatIn(),
|
|
'repeatFrequency' => $activation->repeatTimeout,
|
|
];
|
|
}
|
|
|
|
return $response;
|
|
}
|
|
|
|
return [
|
|
'success' => true,
|
|
];
|
|
}
|
|
|
|
public function actionConfirm() {
|
|
$model = new ConfirmEmailForm();
|
|
$model->load(Yii::$app->request->post());
|
|
if (!($result = $model->confirm())) {
|
|
return [
|
|
'success' => false,
|
|
'errors' => $this->normalizeModelErrors($model->getErrors()),
|
|
];
|
|
}
|
|
|
|
return array_merge([
|
|
'success' => true,
|
|
], $result->getAsResponse());
|
|
}
|
|
|
|
}
|