namespace OC\Core\Controller;
+use OC\Authentication\TwoFactorAuth\Manager;
use OC\HintException;
use \OCP\AppFramework\Controller;
use OCP\AppFramework\Http\JSONResponse;
* @package OC\Core\Controller
*/
class LostController extends Controller {
-
/** @var IURLGenerator */
protected $urlGenerator;
/** @var IUserManager */
protected $timeFactory;
/** @var ICrypto */
protected $crypto;
+ /** @var Manager */
+ private $twoFactorManager;
/**
* @param string $appName
IManager $encryptionManager,
IMailer $mailer,
ITimeFactory $timeFactory,
- ICrypto $crypto) {
+ ICrypto $crypto,
+ Manager $twoFactorManager) {
parent::__construct($appName, $request);
$this->urlGenerator = $urlGenerator;
$this->userManager = $userManager;
$this->mailer = $mailer;
$this->timeFactory = $timeFactory;
$this->crypto = $crypto;
+ $this->twoFactorManager = $twoFactorManager;
}
/**
\OC_Hook::emit('\OC\Core\LostPassword\Controller\LostController', 'post_passwordReset', array('uid' => $userId, 'password' => $password));
+ $this->twoFactorManager->clearTwoFactorPending($userId);
+
$this->config->deleteUserValue($userId, 'core', 'lostpassword');
@\OC::$server->getUserSession()->unsetMagicInCookie();
} catch (HintException $e){
use function array_filter;
use BadMethodCallException;
use Exception;
+use OC\Authentication\Exceptions\ExpiredTokenException;
use OC\Authentication\Exceptions\InvalidTokenException;
use OC\Authentication\Token\IProvider as TokenProvider;
use OCP\Activity\IManager;
$this->config->setUserValue($user->getUID(), 'login_token_2fa', $token->getId(), $this->timeFactory->getTime());
}
+ public function clearTwoFactorPending(string $userId) {
+ $tokensNeeding2FA = $this->config->getUserKeys($userId, 'login_token_2fa');
+
+ foreach ($tokensNeeding2FA as $tokenId) {
+ $this->tokenProvider->invalidateTokenById($userId, $tokenId);
+ }
+ }
+
}
namespace Tests\Core\Controller;
+use OC\Authentication\TwoFactorAuth\Manager;
use OC\Core\Controller\LostController;
use OC\Mail\Message;
use OCP\AppFramework\Http\JSONResponse;
private $request;
/** @var ICrypto|\PHPUnit_Framework_MockObject_MockObject */
private $crypto;
+ /** @var Manager|\PHPUnit_Framework_MockObject_MockObject */
+ private $twofactorManager;
protected function setUp() {
parent::setUp();
->method('isEnabled')
->willReturn(true);
$this->crypto = $this->createMock(ICrypto::class);
+ $this->twofactorManager = $this->createMock(Manager::class);
$this->lostController = new LostController(
'Core',
$this->request,
$this->encryptionManager,
$this->mailer,
$this->timeFactory,
- $this->crypto
+ $this->crypto,
+ $this->twofactorManager
);
}