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); $mobile = str_replace(' ', '', $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(); } } public function removeCode() { $id = $this->UserId; $User = new User($id); $data = []; $data['twofactorcode']=NULL; $data['twofactortimestamp']=NULL; $User->update($data); $User->save(); } }