add newsletter changes

This commit is contained in:
2016-05-26 08:50:10 +02:00
parent 07d5041126
commit 1fed67a650
16 changed files with 335 additions and 34 deletions

View File

@@ -17,6 +17,7 @@ use common\components\Helper;
use common\models\Log;
use common\models\Customer;
use yii\web\NotFoundHttpException;
use frontend\models\SubscribeForm;
/**
* Site controller
@@ -181,6 +182,8 @@ class SiteController extends Controller
public function actionNewsletterUnsubscribe($id,$token)
{
$this->layout = "main-nologin";
$customer = Customer::find()
->andWhere(['id_customer' => $id ])
@@ -196,8 +199,59 @@ class SiteController extends Controller
$customer->newsletter_token = Yii::$app->security->generateRandomString() . '_' . time();
$customer->save();
Log::logC([
'id_customer' => $customer->id_customer,
'type' => Log::$TYPE_NEWSLETTER_UNSUBSCRIBE,
"message" => "Hírlevél feliratkozás: ". $customer->name
]);
return $this->render("unsubscribe");
}
public function actionNewsletterSubscribe($id,$token)
{
$this->layout = "main-nologin";
$customer = Customer::find()
->andWhere(['id_customer' => $id ])
->andWhere(['newsletter_token' => $token])
->one();
if ( !isset($customer)){
throw new NotFoundHttpException("Az oldal nem található");
}
$model = new SubscribeForm([
'customer' => $customer
]);
if ($model->load(Yii::$app->request->post()) && $model->validate() ) {
$customer->newsletter = 1;
$customer->newsletter_token = Yii::$app->security->generateRandomString() . '_' . time();
$customer->save();
Log::logC([
'id_customer' => $customer->id_customer,
'type' => Log::$TYPE_NEWSLETTER_SUBSCRIBE,
"message" => "Hírlevél feliratkozás: ". $customer->name ." - " . $customer->email
]);
return $this->redirect(["newsletter-subscribe-success"]);
}
return $this->render("subscribeform",['model' => $model]);
}
public function actionNewsletterSubscribeSuccess( )
{
$this->layout = "main-nologin";
return $this->render("subscribe");
}
/**
* Signs user up.