frontend: send customer password

This commit is contained in:
Roland Schneider 2021-09-15 20:52:33 +02:00
parent 3c03e49b99
commit 65fa335a7b
9 changed files with 263 additions and 77 deletions

View File

@ -0,0 +1,25 @@
<?php
use yii\helpers\Html;
use yii\helpers\Url;
use common\components\Helper;
?>
<h1 style="font-size: 12px;">Kedves <?php echo $model->customer->name?>!</h1>
<p style="font-size: 12px;">
Az Ön új jelszava:
</p>
<ul style="font-size: 12px;">
<li>
"<?php echo $model->plainPassword ?>"
</li>
</ul>
<p style="font-size: 12px;">
Üdvözlettel:
</p>
<p style="font-size: 12px;">
<?php echo $model->companyName ?>
</p>
<p>
Ez egy automatikus e-mail üzenet, amelyre nem tud válaszolni.
</p>
<?php
?>

View File

@ -75,10 +75,10 @@ class EventRegistrationManager extends BaseObject
throw new NotFoundHttpException('Customer not found', self::CUSTOMER_NOT_FOUND);
}
// $activeTickets = $card->getActiveTickets();
// if (count($activeTickets) === 0) {
// throw new NotFoundHttpException('Ticket not found', self::TICKET_NOT_FOUND);
// }
$activeTickets = $card->getActiveTickets();
if (count($activeTickets) === 0) {
throw new NotFoundHttpException('Ticket not found', self::TICKET_NOT_FOUND);
}
/** @var Event $event */
$event = Event::find()->andWhere(['id' => $cardEventForm->event_id])->one();
@ -100,26 +100,35 @@ class EventRegistrationManager extends BaseObject
throw new ServerErrorHttpException('Event type not found', self::EVENT_TYPE_NOT_FOUND);
}
// $selectedTicket = $eventType->findTicketAllowingEventType($activeTickets);
//
//
// if (!isset($selectedTicket)) {
// throw new NotFoundHttpException('Ticket not found', self::TICKET_INSUFFICIENT);
// }
//
// if ($selectedTicket->hasOpenReservationCount()) {
// $selectedTicket->consumeReservationCount(1);
// }
// $selectedTicket->save();
//detect if customer is already registered to event
$registrations = $event->getActiveEventRegistrations()->all();
foreach ($registrations as $registration ){
if ($registration->customer_id == $card->customer->id_customer){
throw new BadRequestHttpException("Already registered");
}
}
$selectedTicket = $eventType->findTicketAllowingEventType($activeTickets);
if (!isset($selectedTicket)) {
throw new NotFoundHttpException('Ticket not found', self::TICKET_INSUFFICIENT);
}
if ($selectedTicket->hasOpenReservationCount()) {
$selectedTicket->consumeReservationCount(1);
}
$selectedTicket->save();
$registration = new EventRegistration();
$registration->id_event = $event->id;
$registration->id_card = $card->id_card;
// $registration->id_ticket = $selectedTicket->id_ticket;
$registration->id_ticket = $selectedTicket->id_ticket;
$registration->id_customer = $card->customer->id_customer;
try {
$registration->save(false);
} catch (Throwable $exception) {
} catch (\yii\db\Exception $exception) {
throw new ServerErrorHttpException('Failed to save', self::UNKNOWN_ERROR);
}

View File

@ -12,4 +12,3 @@
</ng-container>
</div>
</div>

View File

@ -1,20 +1,18 @@
<div class="container h-100">
<div class="row h-100">
<div class="col-lg-6 col-sm-12 offset-lg-3 " >
<div class="col-lg-4 col-sm-12 offset-lg-4 p-3 ">
<div class="d-flex align-items-center justify-content-center h-100 flex-column ">
<img class="mw2-sm-50 mw2-100" src="/assets/images/cutlercross-logo-light.svg">
<img class="mw2-sm-80 mw2-80" src="/assets/images/cutlercross-logo-dark.svg">
<form class="login-form w-100" [formGroup]="loginForm" (ngSubmit)="onSubmit()">
<div class="form-group">
<label for="inputUsername">Felhasználónév</label>
<div class="form-group mt-2">
<label for="inputUsername">E-mail cím</label>
<input type="text" formControlName="username" class="form-control" id="inputUsername"
placeholder="E-mail cím megadása">
placeholder="E-mail cím">
<div *ngIf="submitted && username.errors" class="text-danger">
<div *ngIf="username.errors.required">Felhasználónév megadása kötelező</div>
</div>
</div>
<div class="form-group">
<div class="form-group mt-2">
<label for="inputPassword1">Jelszó</label>
<input type="password" formControlName="password" class="form-control" id="inputPassword1"
placeholder="Jelszó">
@ -22,7 +20,7 @@
<div *ngIf="f.password.errors.required">Jelszó megadása kötelezú</div>
</div>
</div>
<button [disabled]="loading" class="btn btn-primary ">Bejelentkezés</button>
<button [disabled]="loading" class="btn btn-primary mt-2 ">Bejelentkezés</button>
<div *ngIf="error" class="alert alert-danger mt-2">{{error}}</div>
</form>
</div>

View File

@ -21,7 +21,7 @@ $utilities: map-merge(
property: max-width,
responsive: true,
class: mw2,
values: ( 25: 25%, 50: 50%, 100: 100%)
values: ( 25: 25%, 50: 50%, 80: 80%, 100: 100%)
),
),
$utilities

View File

@ -4,11 +4,15 @@ namespace frontend\controllers;
use backend\models\CustomerActivateForm;
use frontend\models\SingleCustomerActivateForm;
use common\components\Helper;
use frontend\components\HtmlHelper;
use frontend\models\PasswordChangeModel;
use frontend\models\TowelForm;
use Yii;
use common\models\Customer;
use frontend\models\ReceptionForm;
use yii\base\InvalidConfigException;
use yii\web\BadRequestHttpException;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
@ -221,6 +225,38 @@ class CustomerController extends Controller
}
public function actionPasswordChange($id_card){
$card = Card::findOne($id_card);
if ( !isset($card)){
throw new BadRequestHttpException("card not found");
}
$customer = $card->customer;
if ( !isset($card)){
throw new BadRequestHttpException("customer not found");
}
$model = new PasswordChangeModel();
$model->card = $card;
$model->customer = $customer;
$model->email = $customer->email;
$model->companyName = Helper::getCompanyName();
if ( \Yii::$app->request->isPost ){
$model->load(\Yii::$app->request->post());
if ( $model->changePassword() ){
return $this->redirect(['password-change', 'id_card' => $card->id_card ]);
}
}
return $this->render("password-change",[
'card' => $card,
'model' => $model
]);
}
/**
* Save images as binary data.
* @param $model \common\models\Customer

View File

@ -0,0 +1,83 @@
<?php
namespace frontend\models;
use common\components\Helper;
use common\models\Customer;
use common\models\User;
use yii\base\Model;
use Yii;
/**
* Signup form
* @property \common\models\Customer $customer
*/
class PasswordChangeModel extends Model
{
public $email;
public $customer;
public $card;
public $companyName;
public $plainPassword;
/**
* @inheritdoc
*/
public function rules()
{
return [
['email', 'filter', 'filter' => 'trim'],
['email', 'required'],
['email', 'email'],
['email', 'string', 'max' => 255],
['email', 'validateUnique'],
];
}
public function validateUnique($attribute, $params)
{
$customerWithProvidedEmail = Customer::findOne(['email' => $this->email]);
if (isset($customerWithProvidedEmail)) {
if ($customerWithProvidedEmail->id_customer != $this->customer->id_customer) {
$this->addError("email", "Az e-mail cím már használatban van");
}
}
}
/**
* Signs user up.
*
* @return boolean
*/
public function changePassword()
{
if ($this->validate()) {
$this->customer->email = $this->email;
$this->plainPassword = Helper::generateRandomString(
8,
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXabcdefghijklmnopqrstuvwx"
);
$this->customer->setPassword($this->plainPassword);
if ($this->customer->save(false)) {
$message = \Yii::$app->mailer->compose("customer_password_change", ['model' => $this]);
$message
->setFrom(["noreply@fitnessadmin.hu" => Helper::getCompanyName()])
->setTo($this->customer->email)
->setSubject("Értesítés - " . Helper::getCompanyName() . " - új jelszó")
->send();
\Yii::$app->session->setFlash('success', 'Email módosítva, jelszó elküldve');
return true;
}
}
return false;
}
}

View File

@ -25,6 +25,7 @@ $items = [
[ 'Kártya', ['card/info', 'id_card' => $card->id_card ]],
[ 'Törölköző Bérlés', ['log/towel', 'id_card' => $card->id_card , 'LogSearch[start]' => $todayDateTime ]],
[ 'Ujjlenyomat', ['fingerprint/index', 'FingerprintSearch[id_card]' => $card->id_card ]],
[ 'Jelszó küldése', ['customer/password-change', 'id_card' => $card->id_card ]],
];

View File

@ -0,0 +1,35 @@
<?php
use yii\helpers\Html;
use yii\grid\GridView;
use yii\helpers\Url;
use frontend\components\CustomerTabWidget;
use yii\widgets\ActiveForm;
/* @var $this yii\web\View */
/* @var $searchModel frontend\models\KeySearch */
/* @var $dataProvider yii\data\ActiveDataProvider */
/* @var $model frontend\models\PasswordChangeModel */
/* @var $card common\models\Card */
$this->title = Yii::t('frontend/key', 'Vendéghez rendelt kulcsok');
$this->params['breadcrumbs'][] = $this->title;
?>
<?php echo CustomerTabWidget::widget(['card' => $card])?>
<div class="row">
<div class="col-lg-5">
<?php $form = ActiveForm::begin(['id' => 'contact-form']); ?>
<?= $form->field($model, 'email') ?>
<div class="form-group">
<?= Html::submitButton('E-mail beállítása és jelszó küldése', ['class' => 'btn btn-primary', 'name' => 'contact-button']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>
</div>