HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/SBogers10/topswtwmobile.komma.pro/app/controllers/CustomerController.php
<?php


use KommaApp\Shop\Countries\CountryService;
use KommaApp\Shop\Orders\OrderService;
use KommaApp\Shop\Customers\CustomerService;
use KommaApp\Shop\Pages\PageService;
use KommaApp\Shop\Customers\Customer;

class CustomerController extends \BaseController
{
    /**
     * @var PageService
     */
    private $pageService;

    /**
     * @var CustomerService
     */
    private $customerService;

    /**
     * @var OrderService
     */
    private $orderService;

    /**
     * @var CountryService
     */
    private $countryService;

    /**
     * @param CustomerService $customerService
     */
    public function __construct(
        PageService $pageService,
        CustomerService $customerService,
        OrderService $orderService,
        CountryService $countryService)
    {
        $this->pageService = $pageService;
        $this->customerService = $customerService;
        $this->orderService = $orderService;
        $this->countryService = $countryService;
    }

    public function index()
    {
        if(\Request::isMethod('post')) return $this->store();
        return $this->showCustomerDetail();
    }

    public function showCustomerDetail()
    {
        if($this->customerService->isLoggedIn()) {
            $customer = $this->customerService->getLoggedInCustomer();
            return View::make( viewPrefix() . 'customers.overview', ['customer' => $customer]); 
        }else{
            return $this->showLoginPage();
        }
    }

    public function editAccount()
    {
        if(\Request::isMethod('post')) return $this->update();

        if($this->customerService->isLoggedIn()) {
            $customer = $this->customerService->getLoggedInCustomer();
            return View::make( viewPrefix() .'customers.createOrEdit', ['customer' => $customer]);
        }

        return $this->showLoginPage();
    }

    public function invoice($orderId)
    {
        if($this->customerService->isLoggedIn()){

            $agent = new \Jenssegers\Agent\Agent();
            if( $agent->isMobile() ) return $this->orderService->streamInvoicePdf($orderId);
            return $this->orderService->downloadInvoicePdf($orderId);
        }


        return $this->showLoginPage();
    }

    public function create()
    {
        $c = new Customer();
        //Set the domain country as default
        $c->country = \Shop::getDomainCountry();
        return View::make( viewPrefix() . 'customers.createOrEdit', [
            'customer' => $c,
            'new'=> true,
        ]);
    }

    public function update()
    {
        // Update
        return $this->customerService->updateCustomer(\Input::all());
    }

    public function store()
    {
        return $this->customerService->storeNewCustomer(\Input::all());
    }

    public function validate()
    {
        return $this->customerService->activateCustomer(\Input::get('token'));
    }

    public function showLoginPage()
    {
        // Show login page
        return View::make( viewPrefix() . 'customers.login');
    }

    /**
     * @return mixed
     */
    public function createAccount()
    {
        // Setup shop languages from URI
        \Shop::getLanguageService()->bootFromUri(\Shop::getId());

        // Store customer
        return $this->customerService->store(Input::all());
    }

    public function login()
    {
        // Setup shop languages from URI
        \Shop::getLanguageService()->bootFromUri(\Shop::getId());

        // Login customer and go to the page with $targetPageSlug

        if ($targetPageSlug = Input::get('targetPageSlug')) {
            $targetAnchor = '';
            if (\Input::has('targetAnchor')) $targetAnchor = '#'.\Input::get('targetAnchor');
            return $this->customerService->authorizeLogin(Input::only('email', 'password'), $targetPageSlug, $targetAnchor);
        }


        // Login customer and go to the default page
        return $this->customerService->authorizeLogin(Input::only('email', 'password'));
    }

    public function logout()
    {
        //Check if there is an checkout session
        if (Session::has('checkout')) {
            // delete shipping information
            Session::forget('checkout.shipping');
            //delete the customer information
            Session::forget('checkout.customer');
        }

        \Auth::customer()->logout();
        // todo: flash message
        return \Redirect::to('/');
    }

    public function createAccountFromOrder()
    {
        //If there is no token trow an error
        if (!\Input::has('token')) \App::abort(403, 'No token found');
 
        //Check if there is an order for this token
        if (!$order = $this->orderService->getOrderByToken( \Input::get('token'))) {
            //No order throw 404 page
            \App::abort(404, 'No order found based on the given token');
        }

        //Make the view with the order
        return \View::make( viewPrefix() . 'customers.create-from-order', [
            'order' => $order,
            'customerService' => $this->customerService
        ]);
    }

}