add customer page: password-change.component.html

This commit is contained in:
Roland Schneider
2021-09-12 20:50:07 +02:00
parent 18cd8312b5
commit 3c03e49b99
78 changed files with 641 additions and 304 deletions

View File

@@ -105,7 +105,7 @@ class EventController extends CustomerApiController
->innerJoinWith('trainer')
->innerJoinWith('eventType')
->innerJoinWith('room')
->joinWith('activeEventRegistrations as registrations')
->joinWith('activeEventRegistrations')
->andWhere(['>=', 'event.start', $interval->firstActiveDate->getTimestamp()])
->andWhere(['<', 'event.start', (clone $interval->lastActiveDate)->modify('+1 day')->getTimestamp()])
->andWhere(['event.active' => '1']);

View File

@@ -10,13 +10,15 @@ namespace customerapi\controllers;
use common\models\Customer;
use customerapi\models\LoginForm;
use customerapi\models\PasswordChangeForm;
use sizeg\jwt\Jwt;
use sizeg\jwt\JwtHttpBearerAuth;
use Yii;
use yii\web\BadRequestHttpException;
/** @noinspection PhpUnused */
class UserController extends RestController
class UserController extends RestController
{
@@ -26,36 +28,36 @@ class UserController extends RestController
*
*/
/** @noinspection PhpUnused */
public function actionLogin( )
public function actionLogin()
{
// $customer = new Customer();
// $customer->setPassword("test");
$form = new LoginForm();
$form->load(\Yii::$app->request->post( ), '');
$form->load(\Yii::$app->request->post(), '');
if ( $form->validate() ){
if ($form->validate()) {
/** @var Jwt $jwt */
$jwt = Yii::$app->jwt;
$signer = $jwt->getSigner('HS256');
$key = $jwt->getKey();
$time = time();
/** @var Jwt $jwt */
$jwt = Yii::$app->jwt;
$signer = $jwt->getSigner('HS256');
$key = $jwt->getKey();
$time = time();
// Adoption for lcobucci/jwt ^4.0 version
$token = $jwt->getBuilder()
->issuedBy('customerapi')// Configures the issuer (iss claim)
->permittedFor('customer')// Configures the audience (aud claim)
->identifiedBy('A989C57D19E2AF756BA9585AC4CFAF7974AE3D2BCA7CCA7307B39AB28CC7C2C8', true)// Configures the id (jti claim), replicating as a header item
->issuedAt($time)// Configures the time that the token was issue (iat claim)
->expiresAt($time + 3600)// Configures the expiration time of the token (exp claim)
->withClaim('uid', $form->getCustomer()->getId())// Configures a new claim, called "uid"
->getToken($signer, $key); // Retrieves the generated token
// Adoption for lcobucci/jwt ^4.0 version
$token = $jwt->getBuilder()
->issuedBy('customerapi')// Configures the issuer (iss claim)
->permittedFor('customer')// Configures the audience (aud claim)
->identifiedBy('A989C57D19E2AF756BA9585AC4CFAF7974AE3D2BCA7CCA7307B39AB28CC7C2C8', true)// Configures the id (jti claim), replicating as a header item
->issuedAt($time)// Configures the time that the token was issue (iat claim)
->expiresAt($time + 3600)// Configures the expiration time of the token (exp claim)
->withClaim('uid', $form->getCustomer()->getId())// Configures a new claim, called "uid"
->getToken($signer, $key); // Retrieves the generated token
return $this->asJson([
'token' => (string)$token,
]);
return $this->asJson([
'token' => (string)$token,
]);
} else {
return $this->asJson(
[
@@ -66,6 +68,33 @@ 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();
}
protected function getOptionalActions()
{
return ['login'];

View File

@@ -0,0 +1,32 @@
<?php
namespace customerapi\models;
use yii\base\Model;
class PasswordChangeForm extends Model
{
public $passwordOld;
public $password;
/**
* @inheritdoc
*/
public function rules()
{
return [
// 123456123456123456123456123456123456
// passwordOld and password are both required
[['passwordOld', 'password'], 'required'],
[['passwordOld', 'password'], 'string', 'length' => [6, 24] ],
];
}
public function attributeLabels(){
return [
'passwordOld' => "Jelenlegi jelszó",
'password' => "Jelszó"
];
}
}