oxtotp/src/Application/Controller/d3totplogin.php

122 lines
3.4 KiB
PHP
Raw Normal View History

<?php
/**
2022-09-26 15:22:26 +02:00
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* https://www.d3data.de
*
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
2022-09-26 15:22:26 +02:00
* @author D3 Data Development - Daniel Seifert <info@shopmodule.com>
* @link https://www.oxidmodule.com
*/
2022-09-28 00:08:36 +02:00
declare(strict_types=1);
namespace D3\Totp\Application\Controller;
use D3\Totp\Application\Model\d3backupcodelist;
use D3\Totp\Application\Model\d3totp;
use OxidEsales\Eshop\Application\Controller\FrontendController;
use OxidEsales\Eshop\Core\Exception\DatabaseConnectionException;
use OxidEsales\Eshop\Core\Registry;
2019-08-05 22:59:26 +02:00
use OxidEsales\Eshop\Core\Utils;
class d3totplogin extends FrontendController
{
protected $_sThisTemplate = 'd3totplogin.tpl';
public function render()
{
if (Registry::getSession()->hasVariable(d3totp::TOTP_SESSION_VARNAME) ||
false == Registry::getSession()->hasVariable(d3totp::TOTP_SESSION_CURRENTUSER)
) {
2022-09-28 00:08:36 +02:00
$this->getUtils()->redirect('index.php?cl=start');
2019-08-05 22:59:26 +02:00
if (false == defined('OXID_PHP_UNIT')) {
// @codeCoverageIgnoreStart
2019-08-05 22:59:26 +02:00
exit;
// @codeCoverageIgnoreEnd
2019-08-05 22:59:26 +02:00
}
}
$this->addTplParam('navFormParams', Registry::getSession()->getVariable(d3totp::TOTP_SESSION_NAVFORMPARAMS));
return parent::render();
}
2019-08-05 22:59:26 +02:00
/**
* @return Utils
*/
2022-10-01 14:44:36 +02:00
public function getUtils(): Utils
2019-08-05 22:59:26 +02:00
{
return Registry::getUtils();
}
/**
* @return string|void
* @throws DatabaseConnectionException
*/
public function getBackupCodeCountMessage()
{
2019-08-05 22:59:26 +02:00
$oBackupCodeList = $this->getBackupCodeListObject();
$iCount = $oBackupCodeList->getAvailableCodeCount(Registry::getSession()->getVariable(d3totp::TOTP_SESSION_CURRENTUSER));
if ($iCount < 4) {
return sprintf(
Registry::getLang()->translateString('D3_TOTP_AVAILBACKUPCODECOUNT', null, true),
$iCount
);
2022-09-28 00:08:36 +02:00
}
}
2019-08-05 22:59:26 +02:00
/**
* @return d3backupcodelist
*/
2022-10-01 14:44:36 +02:00
public function getBackupCodeListObject(): d3backupcodelist
2019-08-05 22:59:26 +02:00
{
return oxNew(d3backupcodelist::class);
}
public function getPreviousClass()
{
return Registry::getSession()->getVariable(d3totp::TOTP_SESSION_CURRENTCLASS);
}
2022-10-01 14:44:36 +02:00
public function previousClassIsOrderStep(): bool
{
$sClassKey = Registry::getSession()->getVariable(d3totp::TOTP_SESSION_CURRENTCLASS);
$resolvedClass = Registry::getControllerClassNameResolver()->getClassNameById($sClassKey);
2022-09-28 00:08:36 +02:00
$resolvedClass = $resolvedClass ?: 'start';
/** @var FrontendController $oController */
$oController = oxNew($resolvedClass);
return $oController->getIsOrderStep();
}
/**
* @return bool
*/
2022-10-01 14:44:36 +02:00
public function getIsOrderStep(): bool
{
return $this->previousClassIsOrderStep();
}
/**
* Returns Bread Crumb - you are here page1/page2/page3...
*
* @return array
*/
2022-10-01 14:44:36 +02:00
public function getBreadCrumb(): array
{
$aPaths = [];
$aPath = [];
2022-10-01 14:44:36 +02:00
$iBaseLanguage = (int) Registry::getLang()->getBaseLanguage();
$aPath['title'] = Registry::getLang()->translateString('D3_TOTP_BREADCRUMB', $iBaseLanguage, false);
$aPath['link'] = $this->getLink();
$aPaths[] = $aPath;
return $aPaths;
}
2022-09-30 21:06:30 +02:00
}