add login email sending

This commit is contained in:
Roland Schneider 2016-01-08 22:49:18 +01:00
parent 0084526094
commit b83d13ad2f
10 changed files with 292 additions and 104 deletions

View File

@ -7,6 +7,8 @@ use yii\web\Controller;
use common\models\LoginForm;
use yii\filters\VerbFilter;
use backend\models\UploadForm;
use common\components\Helper;
use common\models\User;
/**
* Site controller
@ -71,6 +73,9 @@ class SiteController extends Controller
'employee'
];
if ($model->load(Yii::$app->request->post()) && $model->login()) {
$this->sendLoginMail();
return $this->goBack();
} else {
return $this->render('login', [
@ -79,6 +84,23 @@ class SiteController extends Controller
}
}
protected function sendLoginMail(){
if ( \Yii::$app->params['login_admin_email'] == true){
$geoip = Helper::getGeoIp();
$user = User::findOne(\Yii::$app->user->id);
$message = \Yii::$app->mailer->compose('login_admin', [
'model' => $user,
'geoip' => $geoip
]);
$message->setFrom( \Yii::$app->params['infoEmail'] )
->setTo( \Yii::$app->params['notify_mail'] )
->setSubject('Admin bejelentkezés - ' . $user->username )
->send();
}
}
public function actionLogout()
{
Yii::$app->user->logout();

View File

@ -1,101 +1,184 @@
<?php
namespace common\components;
use \Yii;
class Helper
{
public static function hufRound($m){
$result = round($m/5, 0) * 5;
class Helper {
public static function hufRound($m) {
$result = round ( $m / 5, 0 ) * 5;
return $result;
}
public static function notInInterval($query ,$field , $start,$end ){
$query->andFilterWhere( ['or', [ '<', $field , isset( $start ) ? $start : '1900-01-01' ] ,[ '>=' , $field , isset($end) ? $end : '3000-01-01' ] ] );
public static function notInInterval($query, $field, $start, $end) {
$query->andFilterWhere ( [
'or',
[
'<',
$field,
isset ( $start ) ? $start : '1900-01-01'
],
[
'>=',
$field,
isset ( $end ) ? $end : '3000-01-01'
]
] );
}
public static function notPaid($query ,$field , $start,$end ){
$query->andFilterWhere( ['or', [ '<', $field , isset( $start ) ? $start : '1900-01-01' ] ,[ '>=' , $field , isset($end) ? $end : '3000-01-01' ] ,[ "transfer.status" => Transfer::STATUS_NOT_PAID ] ] );
public static function notPaid($query, $field, $start, $end) {
$query->andFilterWhere ( [
'or',
[
'<',
$field,
isset ( $start ) ? $start : '1900-01-01'
],
[
'>=',
$field,
isset ( $end ) ? $end : '3000-01-01'
],
[
"transfer.status" => Transfer::STATUS_NOT_PAID
]
] );
}
public static function inInterval($query ,$field , $start,$end ){
$query->andFilterWhere([ '>=', $field , $start ] );
$query->andFilterWhere([ '<' , $field , $end ] );
public static function inInterval($query, $field, $start, $end) {
$query->andFilterWhere ( [
'>=',
$field,
$start
] );
$query->andFilterWhere ( [
'<',
$field,
$end
] );
}
public static function queryInIntervalRule( $field , $start,$end ){
return ['and',[ '>=', $field , $start ] , [ '<' , $field , $end ] ];
public static function queryInIntervalRule($field, $start, $end) {
return [
'and',
[
'>=',
$field,
$start
],
[
'<',
$field,
$end
]
];
}
public static function queryExpireRule( $field_start,$field_end , $start,$end ){
return ['and' ,['<',$field_start, $end], ['>=' , $field_end , $start ], ['<=' , $field_end , $end ] ];
public static function queryExpireRule($field_start, $field_end, $start, $end) {
return [
'and',
[
'<',
$field_start,
$end
],
[
'>=',
$field_end,
$start
],
[
'<=',
$field_end,
$end
]
];
}
public static function queryValidRule( $field_start ,$field_end , $start,$end ){
return ['and' ,['<',$field_start, $end], ['>=' , $field_end , $start ] ];
public static function queryValidRule($field_start, $field_end, $start, $end) {
return [
'and',
[
'<',
$field_start,
$end
],
[
'>=',
$field_end,
$start
]
];
}
public static function sqlInIntervalRule( $field , $paramStart,$paramEnd ){
return ' ' .$field . ' >= ' . $paramStart . ' and ' . $field . ' < ' . $paramEnd ;
public static function sqlInIntervalRule($field, $paramStart, $paramEnd) {
return ' ' . $field . ' >= ' . $paramStart . ' and ' . $field . ' < ' . $paramEnd;
}
public static function sqlExpireRule( $field_start,$field_end , $paramStart,$paramEnd ){
return ' ' .$field_start . ' < ' . $paramEnd . ' and ' . $field_end . ' < ' . $paramEnd ;
public static function sqlExpireRule($field_start, $field_end, $paramStart, $paramEnd) {
return ' ' . $field_start . ' < ' . $paramEnd . ' and ' . $field_end . ' < ' . $paramEnd;
}
public static function sqlValidRule( $field_start ,$field_end , $paramStart,$paramEnd ){
return ' ' .$field_start . ' < ' . $paramEnd . ' and ' . $field_end . ' >=' . $paramStart ;
public static function sqlValidRule($field_start, $field_end, $paramStart, $paramEnd) {
return ' ' . $field_start . ' < ' . $paramEnd . ' and ' . $field_end . ' >=' . $paramStart;
}
public static function queryAccountConstraint($query,$field){
if ( !RoleDefinition::isAdmin() ){
$query->innerJoin("user_account_assignment", $field . ' = user_account_assignment.id_account' );
$query->andWhere(['user_account_assignment.id_user' => Yii::$app->user->id ]);
public static function queryAccountConstraint($query, $field) {
if (! RoleDefinition::isAdmin ()) {
$query->innerJoin ( "user_account_assignment", $field . ' = user_account_assignment.id_account' );
$query->andWhere ( [
'user_account_assignment.id_user' => Yii::$app->user->id
] );
}
}
public static function roleLabels(){
public static function roleLabels() {
return [
'reception' => Yii::t('common/role' ,'Reception'),
'admin' => Yii::t('common/role' ,'Administrator'),
'employee' => Yii::t('common/role' ,'Alkalmazott'),
'reception' => Yii::t ( 'common/role', 'Reception' ),
'admin' => Yii::t ( 'common/role', 'Administrator' ),
'employee' => Yii::t ( 'common/role', 'Alkalmazott' )
];
}
public static function roleDefinitions(){
public static function roleDefinitions() {
return [
'employee' => [
'canAllow' => [ 'employee'],
'employee' => [
'canAllow' => [
'employee'
]
],
'admin' => [
'canAllow' => ['admin','reception','employee'],
],
'reception' => [
'canAllow' => [ ],
'admin' => [
'canAllow' => [
'admin',
'reception',
'employee'
]
],
'reception' => [
'canAllow' => [ ]
]
];
}
public static function flash($mode,$message){
\Yii::$app->session->setFlash($mode, $message );
public static function flash($mode, $message) {
\Yii::$app->session->setFlash ( $mode, $message );
}
public static function fixAsciiChars($in){
$out = str_replace("ö", "0", $in);
$out = str_replace("Ö", "0", $out);
public static function fixAsciiChars($in) {
$out = str_replace ( "ö", "0", $in );
$out = str_replace ( "Ö", "0", $out );
return $out;
}
public static function isCompanyMovar(){
return \Yii::$app->params['company'] == 'movar';
public static function isCompanyMovar() {
return \Yii::$app->params ['company'] == 'movar';
}
public static function isProductVisibilityAccount(){
return \Yii::$app->params['product_visiblity'] == 'account';
public static function isProductVisibilityAccount() {
return \Yii::$app->params ['product_visiblity'] == 'account';
}
public static function getRealUserIp() {
$client = @$_SERVER ['HTTP_CLIENT_IP'];
$forward = @$_SERVER ['HTTP_X_FORWARDED_FOR'];
$remote = $_SERVER ['REMOTE_ADDR'];
if (filter_var ( $client, FILTER_VALIDATE_IP )) {
$ip = $client;
} elseif (filter_var ( $forward, FILTER_VALIDATE_IP )) {
$ip = $forward;
} else {
$ip = $remote;
}
return $ip;
}
public static function getGeoIp() {
$ip = Helper::getRealUserIp ();
$details = json_decode ( file_get_contents ( "http://ipinfo.io/{$ip}/json" ) );
return $details;
}
}

View File

@ -14,47 +14,54 @@ use common\components\DailyListing;
class AccountStateMail extends Object {
public $controller;
public $model;
public $user;
public $account;
public $message;
public $details;
public function init(){
$this->user = User::findOne($this->model->id_user);
$this->account = Account::findOne($this->model->id_account);
}
$this->details = null;
public function sednMail(){
$details = null;
if ($this->model ->isTypeClose ()) {
$prev;
if ($this->model ->type == AccountState::TYPE_CLOSE) {
if (isset ( $accountState->prev_state )) {
$prev = AccountState::findOne ( $accountState->prev_state );
if ($this->model->type == AccountState::TYPE_CLOSE) {
if (isset ( $this->model->prev_state )) {
$prev = AccountState::findOne ( $this->model->prev_state );
}
if (isset ( $prev )) {
$this->model ->start_date = $prev->created_at;
}
}
$details = new DailyListing();
$details->loadAccountState ( $this->model );
$this->details = new DailyListing();
$this->details->loadAccountState ( $this->model );
$details->readTotalEasy ();
$details->readTotalDetailed ();
$details->readTotalMedium ();
$this->details->readTotalEasy ();
$this->details->readTotalDetailed ();
$this->details->readTotalMedium ();
}
}
public function sednMail(){
$user = User::findOne($this->model->id_user);
$account = Account::findOne($this->model->id_account);
$subject = $this->model->isTypeOpen() ? "Kassza nyitás " : "Kassza zárás";
$subject .= " - " . $user->username ." - ". $account->name;
$subject .= " - " . $this->user->username ." - ". $this->account->name;
$mail = \Yii::$app->mailer->compose('account_state', [
$this->message = \Yii::$app->mailer->compose('account_state', [
'model' => $this->model,
'details' => $details
'details' => $this->details
]);
$mail->setFrom('noreplay@fitnessadmin.hu')
$this->attachPdf();
$this->message->setFrom('noreplay@fitnessadmin.hu')
->setTo( \Yii::$app->params['notify_mail'] )
->setSubject($subject )
->send();
@ -62,6 +69,30 @@ class AccountStateMail extends Object {
}
protected function attachPdf(){
$mpdf=new \mPDF('utf-8', 'A4-L');
$mpdf->useSubstitutions=false;
$mpdf->simpleTables = true;
$mpdf->SetHeader( \Yii::$app->params[ "company_name" ] . " - Létrehozva: " .$user->username . ", ".\Yii::$app->formatter->asDatetime(time()) );
$mpdf->setFooter('{PAGENO} / {nb}');
$stylesheet = file_get_contents( \Yii::getAlias('@vendor'.'/bower/bootstrap/dist/css/bootstrap.css')); // external css
$mpdf->WriteHTML($stylesheet,1);
$mpdf->WriteHTML($this->controller->renderPartial("@common/views/account-state/account_state_pdf", [
'model' => $this->model,
'details' => $this->details
]));
$type = $this->model->isTypeOpen() ? "kassza_nyitas" : "kassza_zaras";
$dt= "_letrehozva_".date("Ymd_His"). "_" . $this->user->username;
$fn= $type .$dt.".pdf";
$content = $mpdf->Output($fn, 'S');
$this->message->attachContent($content, ['fileName' => $fn, 'contentType' => 'application/pdf']);
}
}

View File

@ -2,6 +2,7 @@
return [
'adminEmail' => 'rocho02@gmail.com',
'supportEmail' => 'rocho02@gmail.com',
'infoEmail' => 'info@rocho-net.hu',
'user.passwordResetTokenExpire' => 3600,
'version' => 'v0.0.19',
'company' => 'movar',//gyor
@ -9,4 +10,7 @@ return [
'product_visiblity' => 'account',// on reception which products to display. account or global
'notify_mail' => ['rocho02@gmail.com' ],
'mail_account_state_open' => true,
'login_reception_email' => true, //if reception login should send email
'login_admin_email' => true, //if admin login should send email
];

View File

@ -79,9 +79,6 @@ if ( $model ->type == AccountState::TYPE_OPEN ){
<?php echo TotalMediumProductsWidget::widget(['dailyListing' => $details]);?>
<h3>Pénzmozgások típus szerint</h3>
<?php echo TotalMediumMoneyMovementsWidget::widget(['dailyListing' => $details]);?>
<?php }else{?>
<h2>Címletek</h2>
<?php echo BankNotesWidget::widget(['model' => $model]);?>
<?php }?>
<?php } ?>
</div>

View File

@ -0,0 +1,12 @@
<?php
?>
<h1>Admin bejelentkezés:</h1>
<b>Felhasználó:</b> <?php echo $model->username ;?><br>
<b>Idő:</b> <?php echo \Yii::$app->formatter->asDatetime(time());?><br>
<?php
if ( isset($geoip->city)){
?>
<b>Ip cím:</b> <?php echo $geoip->ip?><br>
<b>Város:</b> <?php echo $geoip->city?><br>
<?php }?>

View File

@ -0,0 +1,12 @@
<?php
?>
<h1>Recepció bejelentkezés:</h1>
<b>Felhasználó:</b> <?php echo $model->username ;?><br>
<b>Idő:</b> <?php echo \Yii::$app->formatter->asDatetime(time());?><br>
<?php
if ( isset($geoip->city)){
?>
<b>Ip cím:</b> <?php echo $geoip->ip?><br>
<b>Város:</b> <?php echo $geoip->city?><br>
<?php }?>

View File

@ -11,8 +11,14 @@ return [
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
'viewPath' => '@common/mail',
'fileTransport' => true,
'transport' =>[]
],
],
'useFileTransport' =>false,
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'smtp.websiter.hu',
'username' => 'info@rocho-net.hu',
'password' => 'botond2015',
'port' => '25',
],
],
]
];

View File

@ -80,7 +80,7 @@ class AccountStateController extends Controller {
// return $this->redirect(['view', 'id' => $model->id_account_state]);
$mail = new AccountStateMail(['model' => $model]);
$mail = new AccountStateMail(['model' => $model,'controller' => $this]);
$mail->sednMail();
@ -114,7 +114,7 @@ class AccountStateController extends Controller {
if ($model->load ( Yii::$app->request->post () ) && $model->save ()) {
$mail = new AccountStateMail(['model' => $model]);
$mail = new AccountStateMail(['model' => $model,'controller' => $this]);
$mail->sednMail();
return $this->redirect ( [

View File

@ -12,6 +12,8 @@ use yii\web\BadRequestHttpException;
use yii\web\Controller;
use yii\filters\VerbFilter;
use yii\filters\AccessControl;
use common\models\User;
use common\components\Helper;
/**
* Site controller
@ -88,6 +90,8 @@ class SiteController extends Controller
$model = new LoginForm();
if ($model->load(Yii::$app->request->post()) && $model->login()) {
// return $this->goBack();
return $this->redirect(['account/select']);
} else {
@ -95,6 +99,23 @@ class SiteController extends Controller
}
}
protected function sendLoginIp(){
if ( \Yii::$app->params['login_reception_email'] == true){
$geoip = Helper::getGeoIp();
$user = User::findOne(\Yii::$app->user->id);
$message = \Yii::$app->mailer->compose('login_frontend', [
'model' => $user,
'geoip' => $geoip
]);
$message->setFrom( \Yii::$app->params['infoEmail'] )
->setTo( \Yii::$app->params['notify_mail'] )
->setSubject('Recepció bejelentkezés - ' . $user->username )
->send();
}
}
/**
* Logs out the current user.
*