Files
thetool/application/UserTwofactor/UserTwofactor.php
Spitzer_Daniel f95d0b0074 2FA/Remember Me Implementierung
Userprofile Implementierung

Datatables Padding Anpassungen

Usercontroller und User um Mobile erweitert
2023-08-17 09:42:18 +02:00

88 lines
2.2 KiB
PHP

<?php
class UserTwofactor
{
private $UserId;
private $Verification;
function __construct($UserId)
{
$this->UserId = $UserId;
$this->getVerification();
}
public function setVerification($verification)
{
$this->Verification = $verification;
}
protected function apiAction()
{
$do = $this->request->do;
$codetype = $this->request->twofactor;
switch ($do) {
case "sendcode":
$return = $this->sendCode();
break;
case "checkverfication":
$return = $this->checkVerfication();
break;
default:
$return = false;
}
}
private function getVerification()
{
$id = $this->UserId;
$User = new User($id);
$this->Verification = $User->twofactor;
}
private function checkVerfication()
{
$this->getVerification();
$response['data']['verficationtype'] = $this->Verification;
$response['success'] = "true";
echo json_encode($response);
exit;
}
public function sendCode()
{
$code = rand(0, 99999);
$code = str_pad($code, 5, 0, STR_PAD_LEFT);
$verification = $this->Verification;
$id = $this->UserId;
$User = new User($id);
$emailaddress = $User->email;
$mobile = str_replace('+', '', $User->mobile);
$data = [];
$data['twofactorcode'] = $code;
$data['twofactortimestamp'] = time();
$User->update($data);
$User->save();
if ($verification == 1) {
$fromMail = TT_OUTGOING_EMAIL_2FA;
$fromName = TT_OUTGOING_EMAIL_2FA_NAME;
$email = new Emailnotification();
$email->setSubject('Authentifizierungscode');
$email->setFrom($fromMail, $fromName);
$email->setBody($code);
$email->setTo($emailaddress);
$email->send();
} else if ($verification == 2) {
$sms = new SmsNotification();
$sms->setBody('Xinon 2FA Code: ' . $code);
$sms->setRecipient($mobile);
$sms->send();
}
}
}