<?php
/**
 * Magetop Quotesystem .ls
 *
 * @category  Magetop Extensions
 * @package   Magetop_Quotesystem
 * @author    Magetop Developer
 * @copyright Copyright (c) Magetop (https://www.magetop.com)
 * @license   https://www.magetop.com/license.html
 */


namespace Magetop\Quotesystem\Controller\Buyerquote;

use Magento\Framework\Controller\ResultFactory;
use Magento\Framework\App\Action\Context;
use Magento\Framework\App\Action\Action;
use Magento\Framework\App\Response\RedirectInterface;

class RedirectAfterLogin extends Action
{
    /**
     * @var Context
     */
    protected $_context;

    /**
     * @var RedirectInterface
     */
    protected $_redirectInterface;

    /**
     * Constructor
     *
     * @param Context           $context
     * @param RedirectInterface $redirectInterface
     */
    public function __construct(
        Context $context,
        RedirectInterface $redirectInterface
    ) {
        $this->_context = $context;
        $this->_redirectInterface = $redirectInterface;
        parent::__construct($context);
    }

    /**
     * Redirect action
     */
    public function execute()
    {
        $url = $this->_redirectInterface->getRefererUrl();
        $login_url = $this->_url->getUrl(
            'customer/account/login',
            ['referer' => base64_encode($url)]
        );
        $resultRedirect = $this->resultRedirectFactory->create();
        $resultRedirect->setUrl($login_url);
        return $resultRedirect;
    }
}
