Initial import
This commit is contained in:
@@ -0,0 +1,380 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace app\controllers;
|
||||
|
||||
use app\models\Order;
|
||||
use app\models\register\PhplistUserUser;
|
||||
use app\models\Ts;
|
||||
use app\models\UserSession;
|
||||
use app\services\Auth;
|
||||
use app\services\Cart;
|
||||
use app\services\IdServer;
|
||||
use app\services\payment\Payment;
|
||||
use app\services\UserRequest;
|
||||
use app\services\ViewReg;
|
||||
use app\services\OpenIdService;
|
||||
use app\services\ZipCollection;
|
||||
|
||||
class UserController extends BaseController
|
||||
{
|
||||
public $layout = 'portal';
|
||||
public $partnerSlug;
|
||||
/** @var UserRequest */
|
||||
private $userRequest;
|
||||
/** @var \app\models\UserPublic */
|
||||
private $user;
|
||||
|
||||
private function base64_urlencode($string)
|
||||
{
|
||||
return rtrim(strtr(base64_encode($string), '+/', '-_'), '=');
|
||||
}
|
||||
|
||||
public function beforeAction($action)
|
||||
{
|
||||
|
||||
date_default_timezone_set("Europe/Sofia");
|
||||
|
||||
ViewReg::localeSwitchUser();
|
||||
$this->userRequest = new UserRequest();
|
||||
$this->user = Auth::getUser();
|
||||
if ($this->user && $this->user->open_id) {
|
||||
$us = UserSession::find()->where(['sub' => $this->user->open_id])->one();
|
||||
if (!$us) {
|
||||
Auth::setUser();
|
||||
return $this->redirect(\Yii::$app->goHome());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return parent::beforeAction($action); // TODO: Change the autogenerated stub
|
||||
|
||||
//\Yii::$app->language = 'en';
|
||||
//exit;
|
||||
}
|
||||
|
||||
public function actionDashboard()
|
||||
{
|
||||
if (!$this->user) return $this->redirect(\Yii::$app->goTo('login'));
|
||||
if (!empty($_COOKIE['redirect'])) {
|
||||
return $this->redirect(\Yii::$app->goToAction($_COOKIE['redirect']));
|
||||
}
|
||||
Ts::set([56, 57, 58, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 195, 204, 198, 205, 206, 207, 208, 209, 210, 211, 217, 220, 221, 222, 239, 241, 242, 243, 251]);
|
||||
|
||||
if (!empty($_GET['da'])) {
|
||||
if ($_GET['da'] == 'off') {
|
||||
$this->user->has_double_auth = null;
|
||||
\Yii::$app->flash('success', Ts::get(208));
|
||||
} else {
|
||||
$this->user->has_double_auth = 1;
|
||||
\Yii::$app->flash('success', Ts::get(207));
|
||||
}
|
||||
$idServer = new IdServer();
|
||||
$idServer->turnTFA($this->user->open_id);
|
||||
$this->user->save();
|
||||
return $this->redirect('/user/dashboard');
|
||||
}
|
||||
|
||||
if (!empty($_GET['na'])) {
|
||||
|
||||
$phpListUser = PhplistUserUser::find()->where(['email' => $this->user->email])->one();
|
||||
if ($_GET['na'] == 'off') {
|
||||
if ($phpListUser)
|
||||
$phpListUser->delete();
|
||||
$this->user->has_newsletter = null;
|
||||
\Yii::$app->flash('success', Ts::get(222));
|
||||
} else {
|
||||
$phpListUser = PhplistUserUser::find()->where(['email' => $this->user->email])->one();
|
||||
if (!$phpListUser) {
|
||||
PhplistUserUser::add($this->user->email);
|
||||
}
|
||||
$this->user->has_newsletter = 1;
|
||||
\Yii::$app->flash('success', Ts::get(221));
|
||||
}
|
||||
$this->user->save();
|
||||
return $this->redirect('/user/dashboard');
|
||||
}
|
||||
$this->pageTitle = Ts::get(75);
|
||||
$this->userRequest->call('editProfile');
|
||||
return $this->render('dashboard', ['user' => $this->user]);
|
||||
}
|
||||
|
||||
public function actionProfileTabs()
|
||||
{
|
||||
|
||||
if (!empty($_GET['tab'])) {
|
||||
return $this->renderPartial('profile-tabs/' . $_GET['tab']);
|
||||
}
|
||||
}
|
||||
|
||||
public function actionCheckout()
|
||||
{
|
||||
if (!$this->user) {
|
||||
(new OpenIdService())->authenticationServerCheckout();
|
||||
} else {
|
||||
return $this->redirect(\Yii::$app->goHome() . 'user/');
|
||||
}
|
||||
}
|
||||
|
||||
public function actionLogin()
|
||||
{
|
||||
if (!$this->user) {
|
||||
(new OpenIdService())->authenticationServerCheckout();
|
||||
} else {
|
||||
return $this->redirect('user');
|
||||
}
|
||||
}
|
||||
|
||||
public function actionLogoutAll()
|
||||
{
|
||||
$user = Auth::getUser();
|
||||
|
||||
//die('test');
|
||||
|
||||
|
||||
if ($user && $user->open_id || !empty($_SESSION['register_user'])) {
|
||||
$q = "";
|
||||
if (!empty($_SESSION['id_token_hint'])) {
|
||||
$redirect = \Yii::$app->params['portal'] . '/bg/user/checkout/';
|
||||
$q = '?id_token_hint=' . $_SESSION['id_token_hint'] . '&post_logout_redirect_uri=' . $redirect;
|
||||
}
|
||||
$logoutUrl = \Yii::$app->params['sso_logout_url'] . $q;
|
||||
header('Location: ' . $logoutUrl);
|
||||
exit;
|
||||
} else {
|
||||
header('Location: ' . \Yii::$app->params['sso_logout_url']);
|
||||
}
|
||||
exit;
|
||||
}
|
||||
|
||||
public function actionLogoutRedirect()
|
||||
{
|
||||
Auth::setUser();
|
||||
$logoutUrl = \Yii::$app->params['id_server'] . '/realms/' . \Yii::$app->params['realm'] . '/protocol/openid-connect/logout';
|
||||
header('Location: ' . $logoutUrl);
|
||||
exit;
|
||||
}
|
||||
|
||||
public function actionWrongUser()
|
||||
{
|
||||
Ts::set([219, 218, 73]);
|
||||
$lg = "/bg/user/logout-redirect/";
|
||||
\Yii::$app->flash('error', Ts::get(219) . '. ' . Ts::get(218) . ' <a style=\'color: #ffffff\' href=\'' . $lg . '\'>' . Ts::get(73) . '</a>');
|
||||
header('Location: ' . \Yii::$app->goHome());
|
||||
exit;
|
||||
}
|
||||
|
||||
public function actionSignUp()
|
||||
{
|
||||
Ts::set([53, 55, 56, 57, 58, 59, 60, 61, 62, 72, 194, 195, 196, 198, 199, 201]);
|
||||
$this->userRequest->call('signUp');
|
||||
if (empty($_GET['webview_mode'])) {
|
||||
return $this->render('sign-up');
|
||||
} else {
|
||||
return $this->render('sign-up-webview');
|
||||
}
|
||||
}
|
||||
|
||||
public function actionChangePassword()
|
||||
{
|
||||
Ts::set([67, 68, 212, 213, 214, 215, 216]);
|
||||
$this->userRequest->call('changePassword');
|
||||
}
|
||||
|
||||
public function actionIdAuth()
|
||||
{
|
||||
$idServer = new IdServer();
|
||||
echo json_encode($idServer->customGetRequest(($_GET['req'] ?? '')));
|
||||
exit;
|
||||
}
|
||||
|
||||
// region STEP 1
|
||||
public function actionCart()
|
||||
{
|
||||
Ts::set([85, 86, 88, 89, 90, 91, 94, 96, 97, 98, 99, 100, 101, 102, 103, 117, 170, 176, 106, 191, 194]);
|
||||
$this->pageTitle = Ts::get(96);
|
||||
return $this->render('order/cart', ['cartData' => Cart::getFormatedData()]);
|
||||
}
|
||||
|
||||
public function actionAddToCart()
|
||||
{
|
||||
Ts::set([122, 194]);
|
||||
Cart::add();
|
||||
return $this->asJson(Cart::getData());
|
||||
}
|
||||
|
||||
public function actionAddBookingToCart()
|
||||
{
|
||||
Ts::set([122, 194]);
|
||||
Cart::addBooking();
|
||||
return $this->asJson(Cart::getData());
|
||||
}
|
||||
|
||||
public function actionGetCart()
|
||||
{
|
||||
return $this->asJson(Cart::getData());
|
||||
}
|
||||
|
||||
public function actionCartClear()
|
||||
{
|
||||
Cart::clear();
|
||||
return $this->asJson(['message' => 'Cart is cleared']);
|
||||
}
|
||||
|
||||
public function actionUpdateCartQuantity()
|
||||
{
|
||||
Cart::updateItemQuantity();
|
||||
return $this->asJson(['success' => 1]);
|
||||
}
|
||||
|
||||
public function actionRemoveFromCart()
|
||||
{
|
||||
Cart::remove();
|
||||
return $this->asJson(Cart::getData());
|
||||
}
|
||||
|
||||
//endregion
|
||||
|
||||
//region STEP 2
|
||||
public function actionOrderData()
|
||||
{
|
||||
if (empty($_COOKIE['cart_data']))
|
||||
return $this->redirect(\Yii::$app->goToAction('user/cart'));
|
||||
|
||||
Ts::set([
|
||||
88, 89, 90, 91, 100, 101, 124, 125, 126, 127, 128, 129,
|
||||
130, 131, 132, 133, 134, 135, 136, 137, 138,
|
||||
139, 140, 141, 142, 143, 144, 145, 146, 147, 191, 194
|
||||
]);
|
||||
|
||||
$this->pageTitle = Ts::get(89);
|
||||
return $this->render('order/data', ['data' => Cart::getFormatedData()]);
|
||||
}
|
||||
|
||||
public function actionAddInvoiceData()
|
||||
{
|
||||
$this->userRequest->call('setInvoiceData');
|
||||
}
|
||||
|
||||
//endregion
|
||||
|
||||
//region STEP 3
|
||||
public function actionPurchaseInfo()
|
||||
{
|
||||
$user = null;
|
||||
if (!empty($_SESSION['token'])) {
|
||||
$user = Auth::getUserByToken($_SESSION['token']);
|
||||
} else {
|
||||
$user = Auth::getUser();
|
||||
}
|
||||
if ($user) {
|
||||
|
||||
setcookie('redirect', '', time() + (86400 * 30), "/");
|
||||
|
||||
if (empty($_COOKIE['cart_data']) || empty($_COOKIE['invoice_data']) || empty($_COOKIE['payment_method']))
|
||||
return $this->redirect(\Yii::$app->goToAction('user/cart'));
|
||||
|
||||
Ts::set([
|
||||
88, 89, 90, 91, 97, 99, 100, 101, 124, 125, 126, 127, 128, 129,
|
||||
130, 131, 132, 133, 134, 135, 136, 137, 138,
|
||||
139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 194
|
||||
]);
|
||||
$this->pageTitle = Ts::get(90);
|
||||
return $this->render('order/purchase-info', [
|
||||
'cart_data' => Cart::getFormatedData(),
|
||||
'invoice_data' => json_decode($_COOKIE['invoice_data']),
|
||||
'payment_method' => $_COOKIE['payment_method']
|
||||
]);
|
||||
} else {
|
||||
Ts::set([53, 54, 88, 89, 90, 91, 154, 191]);
|
||||
setcookie('redirect', 'user/purchase-info', time() + (86400 * 30), "/");
|
||||
return $this->render('order/user-authentication');
|
||||
}
|
||||
}
|
||||
//endregion
|
||||
|
||||
//region STEP 4
|
||||
public function actionSendOrder()
|
||||
{
|
||||
$user = Auth::getUser();
|
||||
|
||||
if (!empty($_GET['webview_mode'])) {
|
||||
if (!empty($_SESSION['token']))
|
||||
$user = Auth::getUserByToken($_SESSION['token']);
|
||||
}
|
||||
|
||||
//if ($_SERVER['REQUEST_METHOD'] == 'POST') {
|
||||
|
||||
//echo json_encode($_COOKIE);
|
||||
//exit;
|
||||
if (!empty($_COOKIE['cart_data']) &&
|
||||
!empty($_COOKIE['cart_key']) &&
|
||||
!empty($_COOKIE['payment_method']) &&
|
||||
!empty($_COOKIE['invoice_data']) &&
|
||||
$user
|
||||
) {
|
||||
$order = Order::record($_COOKIE, $user);
|
||||
if ($order) {
|
||||
$_SESSION['order_id'] = $order->id;
|
||||
Cart::clear();
|
||||
return $this->asJson(['success' => 1, 'paymentCheckout' => Payment::getCheckOut($order, $_COOKIE['payment_method'])]);
|
||||
}
|
||||
} else {
|
||||
return $this->asJson(['error' => 1]);
|
||||
}
|
||||
//}
|
||||
}
|
||||
//endregion
|
||||
|
||||
//region STEP 5
|
||||
public function actionFinalizeOrder()
|
||||
{
|
||||
if (!empty($_GET['webview_mode'])) {
|
||||
header('Location: /bg/mobile-api/browser-close-complete-order/');
|
||||
exit;
|
||||
}
|
||||
if (!empty($_SESSION['order_id'])) {
|
||||
$message = [
|
||||
'bg' => 'Поръчката е направена успешно. Вижте направените от Вас поръчки в рездел "Покупки" във Вашия порофил.',
|
||||
'en' => 'The order has been placed successfully. View your orders in the "Purchases" section of your profile.'
|
||||
];
|
||||
$_SESSION['flash'] = [];
|
||||
$_SESSION['flash']['success'] = true;
|
||||
$_SESSION['flash']['msg'] = $message[\Yii::$app->language];
|
||||
header('Location: /'.\Yii::$app->language . '/user/?orders=1');
|
||||
}
|
||||
exit;
|
||||
}
|
||||
|
||||
public function actionFinalizeOrderCancel() {
|
||||
return $this->render('finalize-order-cancel');
|
||||
}
|
||||
|
||||
public function actionReceivePaymentNotification()
|
||||
{
|
||||
Payment::setPaymentNotification();
|
||||
}
|
||||
//endregion
|
||||
|
||||
|
||||
public function actionTicketDetails() {
|
||||
return $this->renderPartial('ticket-details');
|
||||
}
|
||||
|
||||
|
||||
public function actionCollectionZip() {
|
||||
if (!$this->user) return $this->redirect(\Yii::$app->goTo('login'));
|
||||
ZipCollection::zipByCollectionId();
|
||||
//echo phpinfo();
|
||||
exit;
|
||||
}
|
||||
|
||||
public function actionCollectionDownloadZip() {
|
||||
if (!$this->user) return $this->redirect(\Yii::$app->goTo('login'));
|
||||
ZipCollection::downloadZip();
|
||||
//echo phpinfo();
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user