termes. | termes. | ||||
*/ | */ | ||||
$serverName = $_SERVER['SERVER_NAME'] ; | |||||
return [ | return [ | ||||
'vendorPath' => dirname(dirname(__DIR__)) . '/vendor', | 'vendorPath' => dirname(dirname(__DIR__)) . '/vendor', | ||||
'components' => [ | 'components' => [ | ||||
'enableAutoLogin' => true, | 'enableAutoLogin' => true, | ||||
'identityCookie' => [ | 'identityCookie' => [ | ||||
'name' => 'laboiteapain', | 'name' => 'laboiteapain', | ||||
'domain' => '.'.Yii::getAlias('@domainName'), | |||||
'domain' => (($serverName != 'localhost') ? '.' : '') . Yii::getAlias('@domainName'), | |||||
'path' => '/', | 'path' => '/', | ||||
] | ] | ||||
], | ], | ||||
'class' => 'yii\web\Session', | 'class' => 'yii\web\Session', | ||||
'name' => 'PHPLABOITEAPAINSESSID', | 'name' => 'PHPLABOITEAPAINSESSID', | ||||
'cookieParams' => [ | 'cookieParams' => [ | ||||
'domain' => '.'.Yii::getAlias('@domainName'), | |||||
'domain' => (($serverName != 'localhost') ? '.' : '') . Yii::getAlias('@domainName'), | |||||
'httpOnly' => true, | 'httpOnly' => true, | ||||
], | ], | ||||
], | ], |
} | } | ||||
$query = (new Query()) | $query = (new Query()) | ||||
->select(['user.id AS user_id', 'user.name', 'user.lastname', 'user.phone', 'user.email', 'user.created_at', 'user.date_last_connection', 'user_producer.*']) | |||||
->select(['user.id AS user_id', 'user.name', 'user.lastname', 'user.phone', 'user.email', 'user.created_at', 'CAST(FROM_UNIXTIME(user.created_at) AS date) as date_created_at','user.date_last_connection', 'user_producer.*']) | |||||
->from('user'); | ->from('user'); | ||||
$active = (isset($params['inactive']) && $params['inactive']) ? 0 : 1 ; | $active = (isset($params['inactive']) && $params['inactive']) ? 0 : 1 ; |
*/ | */ | ||||
class SiteController extends FrontendController | class SiteController extends FrontendController | ||||
{ | { | ||||
/** | /** | ||||
* @inheritdoc | * @inheritdoc | ||||
*/ | */ | ||||
public function actionLogin() | public function actionLogin() | ||||
{ | { | ||||
if (!\Yii::$app->user->isGuest) { | if (!\Yii::$app->user->isGuest) { | ||||
return Yii::$app->getResponse()->redirect(['order/index']); | |||||
return Yii::$app->getResponse()->redirect(['site/index']); | |||||
} | } | ||||
$model = new LoginForm(); | $model = new LoginForm(); |
$user->setPassword($this->password); | $user->setPassword($this->password); | ||||
$user->generateAuthKey(); | $user->generateAuthKey(); | ||||
if ($user->save()) { | if ($user->save()) { | ||||
// on ajoute l'établissement sélectionnée par l'user en favoris | // on ajoute l'établissement sélectionnée par l'user en favoris | ||||
if ($this->option_user_producer == 'user') { | |||||
if ($this->id_producer) { | |||||
$producer = Producer::find()->where(['id' => $this->id_producer])->one(); | |||||
if ($producer) { | |||||
Producer::addUser($user->id, $this->id_producer) ; | |||||
if ($this->option_user_producer == 'user' && $this->id_producer) { | |||||
$producer = Producer::find()->where(['id' => $this->id_producer])->one(); | |||||
// envoi d'un email à l'utilisateur | |||||
Yii::$app->mailer->compose( | |||||
[ | |||||
'html' => 'signup-html', | |||||
'text' => 'signup-text' | |||||
], | |||||
[ | |||||
'user' => $user, | |||||
'producer' => $producer | |||||
]) | |||||
->setTo($user->email) | |||||
->setFrom([Yii::$app->params['adminEmail'] => 'La boîte à pain']) | |||||
->setSubject('[La boîte à pain] Inscription') | |||||
->send(); | |||||
} | |||||
if ($producer) { | |||||
Producer::addUser($user->id, $this->id_producer) ; | |||||
// envoi d'un email à l'utilisateur | |||||
Yii::$app->mailer->compose( | |||||
[ | |||||
'html' => 'signup-html', | |||||
'text' => 'signup-text' | |||||
], | |||||
[ | |||||
'user' => $user, | |||||
'producer' => $producer | |||||
]) | |||||
->setTo($user->email) | |||||
->setFrom([Yii::$app->params['adminEmail'] => 'La boîte à pain']) | |||||
->setSubject('[La boîte à pain] Inscription') | |||||
->send(); | |||||
} | } | ||||
} | } | ||||
if ($this->option_user_producer == 'user') { | |||||
$userProducer = new UserProducer; | |||||
$userProducer->id_producer = $producer->id; | |||||
$userProducer->id_user = $user->id; | |||||
$userProducer->credit = 0; | |||||
$userProducer->active = 1; | |||||
$userProducer->save(); | |||||
} | |||||
return $user; | return $user; | ||||
} | } | ||||
} | } |
Yii::info($log, __METHOD__); | Yii::info($log, __METHOD__); | ||||
$this->afterLogin($identity, false, $duration); | $this->afterLogin($identity, false, $duration); | ||||
} | } | ||||
return !$this->getIsGuest(); | return !$this->getIsGuest(); | ||||
} | } | ||||