changePassword($VARS['oldpass'], $VARS['newpass'], $VARS['conpass']); if ($result === TRUE) { returnToSender("password_updated"); } } catch (PasswordMatchException $e) { returnToSender("passwords_same"); } catch (PasswordMismatchException $e) { returnToSender("new_password_mismatch"); } catch (IncorrectPasswordException $e) { returnToSender("old_password_mismatch"); } catch (WeakPasswordException $e) { returnToSender("weak_password"); } break; case "chpin": engageRateLimit(); $error = []; if (!($VARS['newpin'] == "" || (is_numeric($VARS['newpin']) && strlen($VARS['newpin']) >= 1 && strlen($VARS['newpin']) <= 8))) { returnToSender("invalid_pin_format"); } if ($VARS['newpin'] == $VARS['conpin']) { $database->update('accounts', ['pin' => ($VARS['newpin'] == "" ? null : $VARS['newpin'])], ['uid' => $_SESSION['uid']]); returnToSender("pin_updated"); } returnToSender("new_pin_mismatch"); break; case "add2fa": if (empty($VARS['secret'])) { returnToSender("invalid_parameters"); } $user = new User($_SESSION['uid']); $totp = new TOTP(null, $VARS['secret']); if (!$totp->verify($VARS["totpcode"])) { returnToSender("2fa_wrong_code"); } $user->save2fa($VARS['secret']); Log::insert(LogType::ADDED_2FA, $user); returnToSender("2fa_enabled"); case "rm2fa": engageRateLimit(); (new User($_SESSION['uid']))->save2fa(""); Log::insert(LogType::REMOVED_2FA, $_SESSION['uid']); returnToSender("2fa_removed"); break; case "readnotification": $user = new User($_SESSION['uid']); if (empty($VARS['id'])) { returnToSender("invalid_parameters#notifications"); } try { Notifications::read($user, $VARS['id']); returnToSender("#notifications"); } catch (Exception $ex) { returnToSender("invalid_parameters#notifications"); } break; case "deletenotification": $user = new User($_SESSION['uid']); if (empty($VARS['id'])) { returnToSender("invalid_parameters#notifications"); } try { Notifications::delete($user, $VARS['id']); returnToSender("notification_deleted#notifications"); } catch (Exception $ex) { returnToSender("invalid_parameters#notifications"); } break; case "resetfeedkey": $database->delete('userkeys', ['AND' => ['uid' => $_SESSION['uid'], 'typeid' => 1]]); returnToSender("feed_key_reset"); break; }