add mobile api
This commit is contained in:
47
mobileapi/controllers/UserController.php
Normal file
47
mobileapi/controllers/UserController.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
* User: rocho
|
||||
* Date: 2018.08.29.
|
||||
* Time: 21:58
|
||||
*/
|
||||
|
||||
namespace mobileapi\controllers;
|
||||
|
||||
use common\models\Customer;
|
||||
use mobileapi\models\PasswordChangeForm;
|
||||
use yii\web\BadRequestHttpException;
|
||||
|
||||
/** @noinspection PhpUnused */
|
||||
|
||||
class UserController extends RestController
|
||||
{
|
||||
|
||||
/**
|
||||
* @throws \yii\base\InvalidConfigException
|
||||
* @throws \yii\base\Exception
|
||||
* @throws BadRequestHttpException
|
||||
*/
|
||||
public function actionPasswordChange()
|
||||
{
|
||||
$form = new PasswordChangeForm();
|
||||
$form->scenario = "default";
|
||||
|
||||
$form->load(\Yii::$app->request->post(), '');
|
||||
|
||||
if (!$form->validate()) {
|
||||
throw new BadRequestHttpException( $form->getErrorSummary(false)[0]);
|
||||
}
|
||||
|
||||
$customer = Customer::findOne(\Yii::$app->user->id);
|
||||
|
||||
if (!$customer->validatePassword($form->passwordOld)) {
|
||||
throw new BadRequestHttpException("Jelenlegi jelszó nem egyezik", "2");
|
||||
}
|
||||
|
||||
$customer->setPassword($form->password);
|
||||
|
||||
$customer->save();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user