Skip to content

Commit

Permalink
don't throw away the user credentials in case of a server error
Browse files Browse the repository at this point in the history
  • Loading branch information
bennet0496 committed Feb 22, 2024
1 parent fcd8891 commit b727204
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions nextcloud_attachments.php
Original file line number Diff line number Diff line change
Expand Up @@ -392,9 +392,10 @@ private function __check_login(): array
//test webdav login
try {
$res = $this->client->request("PROPFIND", $server . "/remote.php/dav/files/" . $username, ['auth' => [$username, $password]]);

switch ($res->getStatusCode()) {
$scode = $res->getStatusCode();
switch ($scode) {
case 401:
case 403:
unset($prefs["nextcloud_login"]);
$this->rcmail->user->save_prefs($prefs);
//we can't use the password
Expand All @@ -411,12 +412,16 @@ private function __check_login(): array
//we can log in
return ['status' => 'ok'];
default:
unset($prefs["nextcloud_login"]);
$this->rcmail->user->save_prefs($prefs);
// Persist for client error codes. keep trying for server errors
if ($scode < 500) {
$_SESSION['plugins']['nextcloud_attachments']['login_result'] =
['status' => null, 'code' => $scode, 'message' => $res->getReasonPhrase()];
}
//Probably bad idea as a single 500 error will kill the logins of all active users
//unset($prefs["nextcloud_login"]);
//$this->rcmail->user->save_prefs($prefs);
//something weired happened
$_SESSION['plugins']['nextcloud_attachments']['login_result'] =
['status' => null, 'code' => $res->getStatusCode(), 'message' => $res->getReasonPhrase()];
return ['status' => null, 'code' => $res->getStatusCode(), 'message' => $res->getReasonPhrase()];
return ['status' => null, 'code' => $scode, 'message' => $res->getReasonPhrase()];
}
} catch (GuzzleException $e) {
self::log($this->rcmail->get_user_name()." login check request failed: ". print_r($e, true));
Expand Down

0 comments on commit b727204

Please sign in to comment.