/** * delete current user account from DB * @param $f3 */ public function deleteAccount($f3) { $data = $f3->get('POST.formData'); $return = (object) []; $captcha = $f3->get('SESSION.deleteAccount'); // reset captcha -> forces user to enter new one $f3->clear('SESSION.deleteAccount'); if (isset($data['captcha']) && !empty($data['captcha']) && $data['captcha'] === $captcha) { $user = $this->_getUser(0); $validUser = $this->_verifyUser($user->name, $data['password']); if (is_object($validUser) && is_object($user) && $user->id === $validUser->id) { // send delete account mail $msg = 'Hello ' . $user->name . ',<br><br>'; $msg .= 'your account data has been successfully deleted.'; $mailController = new MailController(); $status = $mailController->sendDeleteAccount($user->email, $msg); if ($status) { // save log $logText = "id: %s, name: %s, ip: %s"; self::getLogger($this->f3->get('PATHFINDER.LOGFILES.DELETE_ACCOUNT'))->write(sprintf($logText, $user->id, $user->name, $f3->get('IP'))); // remove user $user->erase(); $this->logOut($f3); die; } } else { // password does not match current user pw $passwordError = (object) []; $passwordError->type = 'error'; $passwordError->message = 'Invalid password'; $return->error[] = $passwordError; } } else { // captcha not valid -> return error $captchaError = (object) []; $captchaError->type = 'error'; $captchaError->message = 'Captcha does not match'; $return->error[] = $captchaError; } echo json_encode($return); }
/** * delete current user account from DB * @param \Base $f3 */ public function deleteAccount(\Base $f3) { $data = $f3->get('POST.formData'); $return = (object) []; $captcha = $f3->get(self::SESSION_CAPTCHA_ACCOUNT_DELETE); // reset captcha -> forces user to enter new one $f3->clear(self::SESSION_CAPTCHA_ACCOUNT_DELETE); if (isset($data['captcha']) && !empty($data['captcha']) && $data['captcha'] === $captcha) { $activeCharacter = $this->getCharacter(0); $user = $activeCharacter->getUser(); if ($user) { // send delete account mail $msg = 'Hello ' . $user->name . ',<br><br>'; $msg .= 'your account data has been successfully deleted.'; $mailController = new MailController(); $status = $mailController->sendDeleteAccount($user->email, $msg); if ($status) { // save log self::getLogger('DELETE_ACCOUNT')->write(sprintf(self::LOG_DELETE_ACCOUNT, $user->id, $user->name, $f3->get('IP'))); // remove user $user->erase(); $this->logout($f3); die; } } } else { // captcha not valid -> return error $captchaError = (object) []; $captchaError->type = 'error'; $captchaError->message = 'Captcha does not match'; $return->error[] = $captchaError; } echo json_encode($return); }