2018-10-17 23:48:20 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This Software is the property of Data Development and is protected
|
|
|
|
* by copyright law - it is NOT Freeware.
|
|
|
|
* Any unauthorized use of this software without a valid license
|
|
|
|
* is a violation of the license agreement and will be prosecuted by
|
|
|
|
* civil and criminal law.
|
|
|
|
* http://www.shopmodule.com
|
|
|
|
*
|
|
|
|
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
|
|
|
|
* @author D3 Data Development - Daniel Seifert <support@shopmodule.com>
|
|
|
|
* @link http://www.oxidmodule.com
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace D3\Totp\Application\Controller\Admin;
|
|
|
|
|
2018-10-18 15:33:59 +02:00
|
|
|
use D3\Totp\Application\Model\d3totp;
|
2019-07-28 23:00:30 +02:00
|
|
|
use D3\Totp\Application\Model\Exceptions\d3backupcodelist;
|
2018-10-19 14:16:37 +02:00
|
|
|
use D3\Totp\Modules\Application\Model\d3_totp_user;
|
2019-07-28 23:00:30 +02:00
|
|
|
use Exception;
|
2018-10-17 23:48:20 +02:00
|
|
|
use OxidEsales\Eshop\Application\Controller\Admin\AdminDetailsController;
|
2018-10-19 14:16:37 +02:00
|
|
|
use OxidEsales\Eshop\Application\Model\User;
|
|
|
|
use OxidEsales\Eshop\Core\Exception\StandardException;
|
|
|
|
use OxidEsales\Eshop\Core\Registry;
|
2018-10-17 23:48:20 +02:00
|
|
|
|
|
|
|
class d3user_totp extends AdminDetailsController
|
|
|
|
{
|
2018-10-19 14:16:37 +02:00
|
|
|
protected $_sSaveError = null;
|
|
|
|
|
2018-10-17 23:48:20 +02:00
|
|
|
protected $_sThisTemplate = 'd3user_totp.tpl';
|
2018-10-18 15:33:59 +02:00
|
|
|
|
2019-07-28 23:00:30 +02:00
|
|
|
public $aBackupCodes = array();
|
|
|
|
|
2018-10-18 15:33:59 +02:00
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function render()
|
|
|
|
{
|
|
|
|
parent::render();
|
|
|
|
|
2018-10-19 14:16:37 +02:00
|
|
|
$soxId = $this->getEditObjectId();
|
|
|
|
|
2018-10-18 15:33:59 +02:00
|
|
|
if (isset($soxId) && $soxId != "-1") {
|
2018-10-19 14:16:37 +02:00
|
|
|
/** @var d3_totp_user $oUser */
|
|
|
|
$oUser = oxNew(User::class);
|
|
|
|
if ($oUser->load($soxId)) {
|
|
|
|
$this->addTplParam("oxid", $oUser->getId());
|
|
|
|
} else {
|
|
|
|
$this->addTplParam("oxid", '-1');
|
|
|
|
}
|
|
|
|
$this->addTplParam("edit", $oUser);
|
2018-10-18 15:33:59 +02:00
|
|
|
}
|
|
|
|
|
2018-10-19 14:16:37 +02:00
|
|
|
if ($this->_sSaveError) {
|
|
|
|
$this->addTplParam("sSaveError", $this->_sSaveError);
|
2018-10-18 15:33:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return $this->_sThisTemplate;
|
|
|
|
}
|
2018-10-19 14:16:37 +02:00
|
|
|
|
|
|
|
/**
|
2019-07-28 23:00:30 +02:00
|
|
|
* @throws Exception
|
2018-10-19 14:16:37 +02:00
|
|
|
*/
|
|
|
|
public function save()
|
|
|
|
{
|
|
|
|
parent::save();
|
|
|
|
|
|
|
|
$aParams = Registry::getRequest()->getRequestEscapedParameter("editval");
|
|
|
|
|
|
|
|
try {
|
|
|
|
$pwd = Registry::getRequest()->getRequestEscapedParameter("pwd");
|
|
|
|
|
|
|
|
/** @var d3_totp_user $oUser */
|
|
|
|
$oUser = oxNew(User::class);
|
2018-10-22 12:10:43 +02:00
|
|
|
$oUser->load($this->getEditObjectId());
|
2019-07-28 23:00:30 +02:00
|
|
|
|
2018-10-22 12:10:43 +02:00
|
|
|
if (false == $oUser->isSamePassword($pwd)) {
|
2018-10-20 23:20:23 +02:00
|
|
|
$oException = oxNew(StandardException::class, 'D3_TOTP_ERROR_PWDONTPASS');
|
2018-10-19 14:16:37 +02:00
|
|
|
throw $oException;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @var d3totp $oTotp */
|
|
|
|
$oTotp = oxNew(d3totp::class);
|
2019-07-28 23:00:30 +02:00
|
|
|
$oTotpBackupCodes = oxNew(d3backupcodelist::class);
|
2018-10-19 14:16:37 +02:00
|
|
|
if ($aParams['d3totp__oxid']) {
|
|
|
|
$oTotp->load($aParams['d3totp__oxid']);
|
|
|
|
} else {
|
|
|
|
$aParams['d3totp__usetotp'] = 1;
|
|
|
|
$seed = Registry::getRequest()->getRequestEscapedParameter("secret");
|
|
|
|
$otp = Registry::getRequest()->getRequestEscapedParameter("otp");
|
|
|
|
|
2018-10-22 12:10:43 +02:00
|
|
|
$oTotp->saveSecret($seed);
|
2018-10-19 14:16:37 +02:00
|
|
|
$oTotp->assign($aParams);
|
|
|
|
$oTotp->verify($otp, $seed);
|
2019-07-28 23:00:30 +02:00
|
|
|
$oTotpBackupCodes->generateBackupCodes($this->getEditObjectId());
|
2018-10-19 14:16:37 +02:00
|
|
|
$oTotp->setId();
|
|
|
|
}
|
|
|
|
$oTotp->save();
|
2019-07-28 23:00:30 +02:00
|
|
|
$oTotpBackupCodes->save();
|
|
|
|
} catch (Exception $oExcp) {
|
2018-10-19 14:16:37 +02:00
|
|
|
$this->_sSaveError = $oExcp->getMessage();
|
|
|
|
}
|
|
|
|
}
|
2018-10-23 22:33:14 +02:00
|
|
|
|
|
|
|
public function delete()
|
|
|
|
{
|
|
|
|
$aParams = Registry::getRequest()->getRequestEscapedParameter("editval");
|
|
|
|
|
|
|
|
/** @var d3totp $oTotp */
|
|
|
|
$oTotp = oxNew(d3totp::class);
|
|
|
|
if ($aParams['d3totp__oxid']) {
|
|
|
|
$oTotp->load($aParams['d3totp__oxid']);
|
|
|
|
$oTotp->delete();
|
|
|
|
}
|
|
|
|
}
|
2019-07-28 23:00:30 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param $aCodes
|
|
|
|
*/
|
|
|
|
public function setBackupCodes($aCodes)
|
|
|
|
{
|
|
|
|
$this->aBackupCodes = $aCodes;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getBackupCodes()
|
|
|
|
{
|
|
|
|
return implode(PHP_EOL, $this->aBackupCodes);
|
|
|
|
}
|
2018-10-17 23:48:20 +02:00
|
|
|
}
|