frontend: send customer password
This commit is contained in:
parent
3c03e49b99
commit
65fa335a7b
25
common/mail/customer_password_change.php
Normal file
25
common/mail/customer_password_change.php
Normal 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
|
||||
?>
|
||||
@ -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);
|
||||
}
|
||||
|
||||
|
||||
@ -12,4 +12,3 @@
|
||||
</ng-container>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@ -1,31 +1,29 @@
|
||||
<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">
|
||||
|
||||
<form class="login-form w-100" [formGroup]="loginForm" (ngSubmit)="onSubmit()">
|
||||
<div class="form-group">
|
||||
<label for="inputUsername">Felhasználónév</label>
|
||||
<input type="text" formControlName="username" class="form-control" id="inputUsername"
|
||||
placeholder="E-mail cím megadása">
|
||||
<div *ngIf="submitted && username.errors" class="text-danger">
|
||||
<div *ngIf="username.errors.required">Felhasználónév megadása kötelező</div>
|
||||
<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 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">
|
||||
<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>
|
||||
<div class="form-group">
|
||||
<label for="inputPassword1">Jelszó</label>
|
||||
<input type="password" formControlName="password" class="form-control" id="inputPassword1"
|
||||
placeholder="Jelszó">
|
||||
<div *ngIf="submitted && f.password.errors" class="text-danger">
|
||||
<div *ngIf="f.password.errors.required">Jelszó megadása kötelezú</div>
|
||||
<div class="form-group mt-2">
|
||||
<label for="inputPassword1">Jelszó</label>
|
||||
<input type="password" formControlName="password" class="form-control" id="inputPassword1"
|
||||
placeholder="Jelszó">
|
||||
<div *ngIf="submitted && f.password.errors" class="text-danger">
|
||||
<div *ngIf="f.password.errors.required">Jelszó megadása kötelezú</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<button [disabled]="loading" class="btn btn-primary ">Bejelentkezés</button>
|
||||
<div *ngIf="error" class="alert alert-danger mt-2">{{error}}</div>
|
||||
</form>
|
||||
</div>
|
||||
<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>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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;
|
||||
@ -23,9 +27,9 @@ use common\models\Log;
|
||||
*/
|
||||
class CustomerController extends Controller
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public function behaviors()
|
||||
{
|
||||
return [
|
||||
@ -47,7 +51,7 @@ class CustomerController extends Controller
|
||||
// everything else is denied
|
||||
],
|
||||
],
|
||||
|
||||
|
||||
];
|
||||
}
|
||||
|
||||
@ -70,9 +74,9 @@ class CustomerController extends Controller
|
||||
|
||||
public function actionReception($number = ""){
|
||||
$model = new ReceptionForm();
|
||||
|
||||
|
||||
$model->number = $number;
|
||||
|
||||
|
||||
$model->readCard();
|
||||
|
||||
if ( $model->defaultAccount && $model->defaultAccount->isLogCardReadInReceptionOn()) {
|
||||
@ -88,7 +92,7 @@ class CustomerController extends Controller
|
||||
}else if ( $model->isCardWithCustomer() ){
|
||||
return $this->redirect([ 'ticket/create', 'number' => $model->card->number ]);
|
||||
}
|
||||
|
||||
|
||||
return $this->render('reception',['model' => $model]);
|
||||
}
|
||||
|
||||
@ -122,7 +126,7 @@ class CustomerController extends Controller
|
||||
public function actionCreate($number = null)
|
||||
{
|
||||
$model = new CustomerCreate();
|
||||
|
||||
|
||||
$model->country = "Magyarország";
|
||||
$model->id_user = Yii::$app->user->id;
|
||||
$model->warn_mail_ticket_expire_enabled = 1;
|
||||
@ -131,21 +135,21 @@ class CustomerController extends Controller
|
||||
$receptionForm = new ReceptionForm();
|
||||
$receptionForm->number = $number;
|
||||
$receptionForm->readCard();
|
||||
|
||||
|
||||
if ( isset($number)){
|
||||
$model->cardNumber = $number;
|
||||
}
|
||||
|
||||
|
||||
if ($model->load(Yii::$app->request->post()) && $model->save()) {
|
||||
$this->saveBinaryImage($model);
|
||||
\Yii::$app->session->setFlash( 'success','Vendég létrehozva!' );
|
||||
|
||||
|
||||
Log::log([
|
||||
'type' =>Log::$TYPE_CREATE_CUSTOMER,
|
||||
'message' => 'Új vendég:' .$model->name,
|
||||
'message' => 'Új vendég:' .$model->name,
|
||||
'id_customer' => $model->id_customer
|
||||
]);
|
||||
|
||||
|
||||
return $this->redirect(['update', 'number' => $model->cardNumber]);
|
||||
} else {
|
||||
return $this->render('create', [
|
||||
@ -170,11 +174,11 @@ class CustomerController extends Controller
|
||||
|
||||
/** @var \backend\models\CustomerUpdate $model */
|
||||
$model = null;
|
||||
|
||||
|
||||
$receptionForm = new ReceptionForm();
|
||||
$receptionForm->number = $number;
|
||||
$receptionForm->readCard();
|
||||
|
||||
|
||||
if ( $number != null ){
|
||||
$card = Card::readCard($number);
|
||||
if ( $card != null ){
|
||||
@ -183,7 +187,7 @@ class CustomerController extends Controller
|
||||
->andWhere( [ 'customer.id_customer_card' => $card->id_card ])->one();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ( $model == null) {
|
||||
throw new NotFoundHttpException('The requested page does not exist.');
|
||||
}
|
||||
@ -197,22 +201,22 @@ class CustomerController extends Controller
|
||||
}
|
||||
|
||||
if ($model->load(Yii::$app->request->post()) && $model->save()) {
|
||||
|
||||
|
||||
$this->saveBinaryImage($model);
|
||||
|
||||
|
||||
|
||||
|
||||
\Yii::$app->session->setFlash( 'success','Vendég módosításai elmentve' );
|
||||
|
||||
|
||||
$cardNumber = $card->number;
|
||||
if ( isset( $model->replacementCard ) ){
|
||||
$cardNumber = $model->replacementCard->number;
|
||||
}
|
||||
|
||||
|
||||
return $this->redirect(['update', 'number' => $cardNumber ]);
|
||||
} else {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return $this->render('update', [
|
||||
'model' => $model,
|
||||
'receptionForm' => $receptionForm
|
||||
@ -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
|
||||
@ -236,9 +272,9 @@ class CustomerController extends Controller
|
||||
$image = new Image();
|
||||
$image->path = $path;
|
||||
$image->save();
|
||||
|
||||
|
||||
//todo delete old image
|
||||
|
||||
|
||||
$model->id_image = $image->id_image;
|
||||
$model->save(false);
|
||||
}
|
||||
|
||||
83
frontend/models/PasswordChangeModel.php
Normal file
83
frontend/models/PasswordChangeModel.php
Normal 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;
|
||||
}
|
||||
}
|
||||
@ -2,7 +2,7 @@
|
||||
use yii\helpers\Url;
|
||||
?>
|
||||
|
||||
<?php
|
||||
<?php
|
||||
|
||||
|
||||
$route = Yii::$app->controller->id .'/'. Yii::$app->controller->action->id;
|
||||
@ -15,16 +15,17 @@ $todayDateTime = Yii::$app->formatter->asDatetime(strtotime('today UTC'));
|
||||
|
||||
|
||||
$items = [
|
||||
[ 'Recepció', ['customer/reception', 'number' => $card->number ]],
|
||||
[ 'Termék eladás', ['product/sale', 'number' => $card->number ]],
|
||||
[ 'Adatlap', ['customer/update', 'number' => $card->number ]],
|
||||
[ 'Befizetések', ['ticket/index', 'number' => $card->number] ],
|
||||
[ 'Kulcsok', ['key/index', 'id_card' => $card->id_card] ],
|
||||
[ 'Szerződések', ['contract/index', 'id_card' => $card->id_card ]],
|
||||
[ 'Kosár', ['transfer/customer-cart', 'id_card' => $card->id_card ]],
|
||||
[ 'Recepció', ['customer/reception', 'number' => $card->number ]],
|
||||
[ 'Termék eladás', ['product/sale', 'number' => $card->number ]],
|
||||
[ 'Adatlap', ['customer/update', 'number' => $card->number ]],
|
||||
[ 'Befizetések', ['ticket/index', 'number' => $card->number] ],
|
||||
[ 'Kulcsok', ['key/index', 'id_card' => $card->id_card] ],
|
||||
[ 'Szerződések', ['contract/index', 'id_card' => $card->id_card ]],
|
||||
[ 'Kosár', ['transfer/customer-cart', 'id_card' => $card->id_card ]],
|
||||
[ '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 ]],
|
||||
];
|
||||
|
||||
|
||||
@ -38,7 +39,7 @@ $items = [
|
||||
|
||||
<ul class="nav nav-tabs">
|
||||
<?php foreach ($items as $item){?>
|
||||
<?php
|
||||
<?php
|
||||
if ( empty($title)){
|
||||
if ( $item[1][0] == $route) {
|
||||
$title = $item[0];
|
||||
|
||||
35
frontend/views/customer/password-change.php
Normal file
35
frontend/views/customer/password-change.php
Normal 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>
|
||||
Loading…
Reference in New Issue
Block a user