Skip to content

Commit 07b228c

Browse files
committed
Merge branch 'master' into v2.1
# Conflicts: # src/lib/Plugin.php # src/lib/Services/AuthenticatorService.php # version.json
2 parents 85f0fcc + 37138e0 commit 07b228c

File tree

7 files changed

+57
-38
lines changed

7 files changed

+57
-38
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "syspass/plugin-authenticator",
33
"type": "syspass-plugin",
4-
"description": "Plugin to use two factor based authentication with Google Authenticator.",
4+
"description": "2FA authentication plugin for sysPass based on TOTP algorithm (RFC 6238)",
55
"homepage": "https://syspass.org",
66
"minimum-stability": "stable",
77
"license": "GPL-3.0",

src/lib/Controllers/AuthenticatorController.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ public function checkCodeAction()
250250

251251
$authenticatorData = $this->plugin->getData();
252252

253-
if ($authenticatorData === null) {
253+
if ($authenticatorData === false) {
254254
$this->pluginContext->setTwoFApass(false);
255255
$this->session->setAuthCompleted(false);
256256

@@ -339,6 +339,8 @@ private function sendResetEmail(AuthenticatorData $authenticatorData)
339339
}
340340

341341
return false;
342+
} catch (AuthenticatorException $e) {
343+
throw $e;
342344
} catch (\Exception $e) {
343345
processException($e);
344346

src/lib/Controllers/AuthenticatorLoginController.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ final class AuthenticatorLoginController extends ControllerBase
5454
* @throws \DI\NotFoundException
5555
* @throws \SP\Core\Exceptions\SessionTimeout
5656
* @throws \SP\Services\Auth\AuthException
57+
* @throws \SP\Core\Exceptions\SessionTimeout
5758
*/
5859
public function indexAction()
5960
{
@@ -70,6 +71,8 @@ public function indexAction()
7071
$this->view->assign('useFixedHeader', true);
7172
$this->view->assign('useMenu', false);
7273
$this->view->assign('route', 'authenticator/checkCode');
74+
$this->view->assign('isMailEnabled', $this->configData->isMailEnabled());
75+
$this->view->assign('recoveryGraceTime', Plugin::RECOVERY_GRACE_TIME / 3600);
7376

7477
$this->checkExpireTime();
7578

src/lib/Services/AuthenticatorService.php

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -185,11 +185,6 @@ public function getQrCodeFromServer(string $login, string $iv)
185185
* @return string
186186
* @throws AuthenticatorException
187187
* @throws EnvironmentIsBrokenException
188-
* @throws \Defuse\Crypto\Exception\CryptoException
189-
* @throws \SP\Core\Exceptions\ConstraintException
190-
* @throws \SP\Core\Exceptions\NoSuchPropertyException
191-
* @throws \SP\Core\Exceptions\QueryException
192-
* @throws \SP\Services\ServiceException
193188
*/
194189
public function pickRecoveryCode(AuthenticatorData $authenticatorData)
195190
{
@@ -198,11 +193,7 @@ public function pickRecoveryCode(AuthenticatorData $authenticatorData)
198193
$numCodes = count($codes);
199194

200195
if ($numCodes > 0) {
201-
$code = array_pop($codes);
202-
203-
$this->saveRecoveryCodes($codes, $authenticatorData);
204-
205-
return $code;
196+
return $codes[1];
206197
}
207198

208199
if ($recoveryTime === 0
@@ -211,11 +202,7 @@ public function pickRecoveryCode(AuthenticatorData $authenticatorData)
211202
) {
212203
$codes = $this->generateRecoveryCodes();
213204

214-
$code = array_pop($codes);
215-
216-
$this->saveRecoveryCodes($codes, $authenticatorData);
217-
218-
return $code;
205+
return $codes[1];
219206
}
220207

221208
throw new AuthenticatorException(_t('authenticator', 'There aren\'t any recovery codes available'));

src/public/js/plugin.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,15 @@ sysPass.Plugins.Authenticator = function (Common) {
3838
sysPassApp.msg.out(json);
3939

4040
if (json.status === 0) {
41-
setTimeout(function () {
42-
sysPassApp.util.redirect(json.data.url);
43-
}, 1000);
41+
if (json.data.url !== undefined) {
42+
setTimeout(function () {
43+
sysPassApp.util.redirect(json.data.url);
44+
}, 1000);
45+
}
4446
}
47+
48+
document.querySelector('.mdl-js-checkbox').MaterialCheckbox.uncheck();
49+
$obj.find("#pin").val('');
4550
});
4651
},
4752
save: function ($obj) {

src/public/js/plugin.min.js

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/themes/material-blue/views/login/index.inc

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<?php
22
/**
3-
* @var \SP\Core\UI\ThemeIcons $icons
4-
* @var \SP\Config\ConfigData $configData
5-
* @var callable $_getvar
6-
* @var \SP\Mvc\View\Template $this
3+
* @var \SP\Core\UI\ThemeIcons $icons
4+
* @var \SP\Config\ConfigData $configData
5+
* @var callable $_getvar
6+
* @var \SP\Mvc\View\Template $this
77
*/
88
?>
99
<div id="actions" class="authenticator-2fa" align="center">
@@ -17,20 +17,41 @@
1717
<legend><?php echo _t('authenticator', 'Two Factor Authentication'); ?></legend>
1818
<div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label">
1919
<input id="pin" name="pin" type="text"
20-
pattern="([0-9]{6}|[0-9a-f]{20})" class="mdl-textfield__input mdl-color-text--indigo-400"
20+
pattern="([0-9]{6}|[0-9a-f]{20})"
21+
class="mdl-textfield__input mdl-color-text--indigo-400"
2122
maxlength="20"/>
2223
<label class="mdl-textfield__label"
2324
for="pin"><?php echo _t('authenticator', 'Enter code'); ?></label>
2425
</div>
2526

26-
<label class="mdl-checkbox mdl-js-checkbox mdl-js-ripple-effect" for="code_reset">
27-
<input type="checkbox" name="code_reset" id="code_reset" class="mdl-checkbox__input">
28-
<span class="mdl-checkbox__label"><?php echo _t('authenticator', 'Forgot my code'); ?></span>
29-
</label>
27+
<?php if ($_getvar('isMailEnabled')): ?>
28+
<label class="mdl-checkbox mdl-js-checkbox mdl-js-ripple-effect"
29+
for="code_reset">
30+
<input type="checkbox" name="code_reset" id="code_reset"
31+
class="mdl-checkbox__input">
32+
<span class="mdl-checkbox__label"><?php echo _t('authenticator', 'Forgot my code'); ?></span>
33+
34+
<div id="help-2fa"
35+
class="icon material-icons <?php echo $icons->getIconHelp()->getClass(); ?>"><?php echo $icons->getIconHelp()->getIcon(); ?></div>
36+
</label>
37+
38+
39+
<div class="mdl-tooltip mdl-tooltip--large" for="help-2fa">
40+
<p>
41+
<?php echo _t('authenticator', 'This will send an email with a recovery code. You don\'t need to enter any code, only click on "Log In".'); ?>
42+
</p>
43+
44+
<p>
45+
<?php echo _t('authenticator', sprintf('If there aren\'t any recovery codes left, you will need to wait %dh for new codes', $_getvar('recoveryGraceTime'))); ?>
46+
</p>
47+
</div>
48+
<?php endif; ?>
3049

3150
<?php if ($_getvar('from') && $_getvar('from_hash')): ?>
32-
<input type="hidden" name="from" value="<?php echo $_getvar('from'); ?>"/>
33-
<input type="hidden" name="h" value="<?php echo $_getvar('from_hash'); ?>"/>
51+
<input type="hidden" name="from"
52+
value="<?php echo $_getvar('from'); ?>"/>
53+
<input type="hidden" name="h"
54+
value="<?php echo $_getvar('from_hash'); ?>"/>
3455
<?php endif; ?>
3556

3657
<input type="hidden" name="sk" value=""/>
@@ -46,7 +67,8 @@
4667
<?php echo _t('authenticator', 'Back'); ?>
4768
</button>
4869

49-
<button id="btnLogin" class="mdl-button mdl-js-button mdl-button--raised mdl-button--primary">
70+
<button id="btnLogin"
71+
class="mdl-button mdl-js-button mdl-button--raised mdl-button--primary">
5072
<?php echo _t('authenticator', 'Log in'); ?>
5173
<i class="material-icons"
5274
title="<?php echo _t('authenticator', 'Request'); ?>"><?php echo $icons->getIconPlay()->getIcon(); ?></i>

0 commit comments

Comments
 (0)