2FA/Remember Me Implementierung
Userprofile Implementierung Datatables Padding Anpassungen Usercontroller und User um Mobile erweitert
This commit is contained in:
88
application/UserTwofactor/UserTwofactor.php
Normal file
88
application/UserTwofactor/UserTwofactor.php
Normal file
@@ -0,0 +1,88 @@
|
||||
<?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();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user