Improve error message when the account does not define a password

This commit is contained in:
Maurus Decimus
2026-04-28 11:13:20 +02:00
parent 5c4e447728
commit 0ef9231fae
2 changed files with 19 additions and 12 deletions

View File

@@ -14,7 +14,7 @@ pub mod token;
pub const DEVICE_CODE_LEN: usize = 40;
pub const USER_CODE_LEN: usize = 8;
pub const RANDOM_CODE_LEN: usize = 32;
pub const CLIENT_ID_MAX_LEN: usize = 60;
pub const CLIENT_ID_MAX_LEN: usize = 100;
pub const USER_CODE_ALPHABET: &[u8] = b"ABCDEFGHJKLMNPQRSTUVWXYZ23456789"; // No 0, O, I, 1

View File

@@ -224,20 +224,27 @@ impl Server {
pub async fn password_hash(&self, account_id: u32) -> trc::Result<String> {
if account_id != u32::MAX {
self.registry()
let Some(account) = self
.registry()
.object::<Account>(account_id.into())
.await
.caused_by(trc::location!())?
.and_then(|account| {
account
.into_user()
.and_then(|account| account.into_password())
})
.ok_or_else(|| {
trc::AuthEvent::Error
.into_err()
.details("Account no longer exists")
})
else {
return Err(trc::AuthEvent::Error
.into_err()
.details("Account no longer exists"));
};
let Some(account) = account.into_user() else {
return Err(trc::AuthEvent::Error
.into_err()
.details("Account is not a user"));
};
account.into_password().ok_or_else(|| {
trc::AuthEvent::Error.into_err().details(concat!(
"Account does not have a password. ",
"If you are using an external directory, make sure to set the password attribute."
))
})
} else if let Some((_, secret)) = self.registry().recovery_admin() {
Ok(secret.into())
} else {