add subscriber
This commit is contained in:
@@ -18,6 +18,7 @@ use common\models\Log;
|
||||
use common\models\Customer;
|
||||
use yii\web\NotFoundHttpException;
|
||||
use frontend\models\SubscribeForm;
|
||||
use common\models\Subscriber;
|
||||
|
||||
/**
|
||||
* Site controller
|
||||
@@ -185,9 +186,9 @@ class SiteController extends Controller
|
||||
|
||||
$this->layout = "main-nologin";
|
||||
|
||||
$customer = Customer::find()
|
||||
->andWhere(['id_customer' => $id ])
|
||||
->andWhere(['newsletter_token' => $token])
|
||||
$customer = Subscriber::find()
|
||||
->andWhere(['id_subscriber' => $id ])
|
||||
->andWhere(['token' => $token])
|
||||
->one();
|
||||
|
||||
|
||||
@@ -195,51 +196,32 @@ class SiteController extends Controller
|
||||
throw new NotFoundHttpException("Az oldal nem található");
|
||||
}
|
||||
|
||||
$customer->newsletter = 0;
|
||||
$customer->newsletter_token = Yii::$app->security->generateRandomString() . '_' . time();
|
||||
$customer->status = 0;
|
||||
$customer->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
|
||||
"message" => "Hírlevél leiratkozás: ". $customer->name
|
||||
]);
|
||||
|
||||
|
||||
return $this->render("unsubscribe");
|
||||
return $this->render("unsubscribe",['subscriber' => $customer]);
|
||||
}
|
||||
|
||||
public function actionNewsletterSubscribe($id,$token)
|
||||
public function actionNewsletterSubscribe()
|
||||
{
|
||||
$this->layout = "main-nologin";
|
||||
|
||||
$model = new Subscriber(['scenario' => 'subscribe']);
|
||||
|
||||
|
||||
|
||||
$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() ) {
|
||||
|
||||
|
||||
if ($model->load(Yii::$app->request->post()) && $model->save() ) {
|
||||
|
||||
$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
|
||||
"message" => "Hírlevél feliratkozás: ". $model->name ." - " . $model->email
|
||||
]);
|
||||
|
||||
return $this->redirect(["newsletter-subscribe-success"]);
|
||||
|
||||
Reference in New Issue
Block a user