UserToken Methoden static hinzugefügt

Bug bei Passwortlängencheck gefixt
JS Request URLs auf getUrl umgebaut
2FA Code wird bei eingabe nun üngiltig
This commit is contained in:
Spitzer_Daniel
2023-08-28 15:25:59 +02:00
parent f95d0b0074
commit 28ca65fa6d
6 changed files with 33 additions and 25 deletions

View File

@@ -78,7 +78,8 @@ if ($twofa == 0) {
<div class="form-group row">
<label class="col-lg-2 col-form-label" for="olt">Mobiltelefon</label>
<div class="col-lg-3">
<input placeholder="+4366411223344" type="text" class="form-control input-control"
<input placeholder="+4366411223344" type="text"
class="form-control input-control"
name="mobile" id="mobile"
value="<?= $userprofile->mobile ?>" <?php if ($twofa == 2) : ?> disabled="disabled" <?php endif; ?>/>
</div>
@@ -125,10 +126,7 @@ if ($twofa == 0) {
<script type="text/javascript">
$(document).ready(function () {
var verficationtype;
$.getJSON("https://<?= $_SERVER['SERVER_NAME']; ?>/UserProfile/api?do=checkverfication", {}).done(function (data) {
verficationtype = data.data.verficationtype;
});
var verficationtype = <?= $twofa ?>;
$('form').submit(function (e) {
var me = this;
if ($('#verification2fa').is(":hidden")) {
@@ -138,18 +136,15 @@ if ($twofa == 0) {
$('#verification2fa').show();
$('#code').attr("required", true);
$.getJSON("https://<?= $_SERVER['SERVER_NAME']; ?>/UserProfile/api?do=sendcode&twofactor=" + verficationtype, {}).done(function (data) {
$.getJSON("<?= self::getUrl("UserProfile", "api", ['do' => 'sendcode', 'twofactor' => $twofa]) ?>", {}).done(function (data) {
}).fail(function (jqxhr, textStatus, error) {
window.location.href = "/Dashboard";
});
} else {
}
}
});
$("body").on("click", "#new-authcode", function (event) {
$.getJSON("https://<?= $_SERVER['SERVER_NAME']; ?>/UserProfile/api?do=sendcode&twofactor=" + $('#new-authcode').data('codetype'), {}).done(function (data) {
$.getJSON("<?= self::getUrl("UserProfile", "api", ['do' => 'sendcode', 'twofactor' => $twofa]) ?>", {}).done(function (data) {
$("#new-authcode").hide(0).delay(5000).show(0);
}).fail(function (jqxhr, textStatus, error) {
window.location.href = "/Dashboard";

View File

@@ -188,13 +188,14 @@ if ($userprofile->twofactor == 0) {
$(document).ready(function () {
$("body").on("click", "#new-authcode", function (event) {
$.getJSON("https://<?= $_SERVER['SERVER_NAME']; ?>/UserProfile/api?do=sendcode&twofactor=" + $('#new-authcode').data('codetype'), {}).done(function (data) {
$.getJSON("<?= self::getUrl("UserProfile", "api", ['do' => 'sendcode', 'twofactor' => $verification]) ?>", {}).done(function (data) {
$("#new-authcode").hide(0).delay(5000).show(0);
}).fail(function (jqxhr, textStatus, error) {
window.location.href = "/Dashboard";
window.location.href = "<?= self::getUrl("Dashboard") ?>";
});
});
});
})
;
</script>

View File

@@ -18,14 +18,8 @@ class UserProfileController extends mfBaseController
protected function indexAction()
{
$this->layout()->setTemplate("UserProfile/Index");
$this->layout()->set("userprofile", $this->me);
// $email = new Emailnotification();
// $email->setSubject('testemail');
// $email->setBody('Testemail');
// $email->setTo('daniel.spitzer@inode.at');
// $email->send();
}
protected function addAction()
@@ -115,6 +109,7 @@ class UserProfileController extends mfBaseController
$r = $this->request;
$id = $this->me->id;
$User = new User($id);
$data = [];
if ($User->twofactor != 0) {
$requestcode2fa = $r->code;
$userCode2fa = $User->twofactorcode;
@@ -125,10 +120,11 @@ class UserProfileController extends mfBaseController
$this->layout()->setFlash("Verifizierungscode ungültig", "error");
$this->redirect("UserProfile/edit");
}
$data['twofactorcode'] = NULL;
$data['twofactortimestamp'] = NULL;
}
$data = [];
$data['name'] = trim($r->name);
if ($User->twofactor != 1) {
$data['email'] = trim($r->email);
@@ -184,7 +180,7 @@ class UserProfileController extends mfBaseController
$this->layout()->setFlash("altes Passwort falsch", "error");
$this->redirect("UserProfile");
}
if (strlen($newpwd < 8)) {
if (strlen($newpwd) < 8) {
$this->layout()->setFlash("neues Passwort muss min. 8 Zeichen haben", "error");
$this->redirect("UserProfile");
}
@@ -253,6 +249,9 @@ class UserProfileController extends mfBaseController
$id = $this->me->id;
$User = new User($id);
$data['twofactor'] = $r->twofactor;
$data['twofactorcode'] = NULL;
$data['twofactortimestamp'] = NULL;
$User->update($data);
$User->save();
$this->layout()->setFlash("Zwei-Faktor-Authentifizierung aktiv", "success");

View File

@@ -3,7 +3,7 @@
class UserToken extends mfBaseController
{
public function checkToken()
public static function checkToken()
{
if (isset($_COOKIE[MFAPPNAME . '_remembertoken'])) {
$cookie = explode(':', $_COOKIE[MFAPPNAME . '_remembertoken']);
@@ -36,7 +36,7 @@ class UserToken extends mfBaseController
}
}
public function generateToken($userId)
public static function generateToken($userId)
{
$db = new FronkDB();
$tokenExpireTime = time() + 2592000;
@@ -52,7 +52,7 @@ class UserToken extends mfBaseController
setcookie(MFAPPNAME . '_remembertoken', $selector . ':' . $token, $tokenExpireTime, "/");
}
public function deleteToken()
public static function deleteToken()
{
$db = new FronkDB();
$cookie = explode(':', $_COOKIE[MFAPPNAME . '_remembertoken']);

View File

@@ -85,4 +85,15 @@ class UserTwofactor
}
}
public function removeCode()
{
$id = $this->UserId;
$User = new User($id);
$data = [];
$data['twofactorcode']=NULL;
$data['twofactortimestamp']=NULL;
$User->update($data);
$User->save();
}
}

View File

@@ -209,6 +209,8 @@ class mfLoginController extends mfBaseController
#Token generieren in DB und Cookie schreiben
UserToken::generateToken($userid);
}
$twoFactor = new UserTwofactor($userid);
$twoFactor->removeCode();
}
//session_name(MFAPPNAME."_session");
//session_start();