2023-10-11 13:44:21 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace frontend\modules\api\controllers;
|
|
|
|
|
2023-10-18 13:12:02 +03:00
|
|
|
use common\models\email\RegistrationEmail;
|
2023-10-11 13:44:21 +03:00
|
|
|
use common\models\User;
|
2023-10-18 13:12:02 +03:00
|
|
|
use common\services\EmailService;
|
2023-10-11 13:44:21 +03:00
|
|
|
use frontend\models\SignupForm;
|
|
|
|
use Yii;
|
|
|
|
|
|
|
|
class RegisterController extends ApiController
|
|
|
|
{
|
|
|
|
public function behaviors() {
|
|
|
|
$newBehavior = parent::behaviors();
|
|
|
|
unset($newBehavior['authenticator']);
|
|
|
|
|
|
|
|
return $newBehavior;
|
|
|
|
}
|
|
|
|
|
2023-10-18 13:12:02 +03:00
|
|
|
private EmailService $emailService;
|
|
|
|
|
|
|
|
public function __construct($id, $module, EmailService $emailService, $config = [])
|
|
|
|
{
|
|
|
|
$this->emailService = $emailService;
|
|
|
|
parent::__construct($id, $module, $config);
|
|
|
|
}
|
|
|
|
|
2023-10-11 13:44:21 +03:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @OA\Post(path="/register/sign-up",
|
|
|
|
* summary="Регистрация",
|
|
|
|
* description="Метод для регистрации",
|
2023-10-11 23:19:30 +03:00
|
|
|
* tags={"Registration"},
|
2023-10-11 13:44:21 +03:00
|
|
|
* @OA\RequestBody(
|
|
|
|
* @OA\MediaType(
|
|
|
|
* mediaType="multipart/form-data",
|
|
|
|
* @OA\Schema(
|
|
|
|
* required={"username", "email", "password"},
|
|
|
|
* @OA\Property(
|
|
|
|
* property="username",
|
|
|
|
* type="string",
|
|
|
|
* description="Имя пользрователя",
|
|
|
|
* ),
|
|
|
|
* @OA\Property(
|
|
|
|
* property="email",
|
|
|
|
* type="string",
|
|
|
|
* description="Электронная почта пользователя",
|
|
|
|
* ),
|
|
|
|
* @OA\Property(
|
|
|
|
* property="password",
|
|
|
|
* type="string",
|
|
|
|
* description="Пароль пользователя",
|
|
|
|
* ),
|
|
|
|
* ),
|
|
|
|
* ),
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response=200,
|
|
|
|
* description="Возвращает идентификатор пользователя",
|
|
|
|
* @OA\MediaType(
|
|
|
|
* mediaType="application/json",
|
|
|
|
* ),
|
|
|
|
* ),
|
|
|
|
* )
|
|
|
|
*/
|
|
|
|
public function actionSignUp()
|
|
|
|
{
|
|
|
|
$model = new SignupForm();
|
|
|
|
if ($model->load(Yii::$app->getRequest()->getBodyParams(), '')) {
|
|
|
|
/** @var User $user */
|
|
|
|
if ($user = $model->signup()) {
|
2023-10-18 13:12:02 +03:00
|
|
|
$this->emailService->sendEmail(new RegistrationEmail($user));
|
2023-10-11 13:44:21 +03:00
|
|
|
return [
|
|
|
|
'id' => $user->id,
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|