Added a bunch of logging to user management
This commit is contained in:
parent
ac9650977b
commit
33114616e0
|
@ -152,7 +152,7 @@ impl NotSignedInUser {
|
||||||
)?;
|
)?;
|
||||||
Ok(id)
|
Ok(id)
|
||||||
})?;
|
})?;
|
||||||
info!("User {}#{:08x} registered!", partial.username, id);
|
info!("User {}#{:08X} registered!", partial.username, id);
|
||||||
|
|
||||||
Ok(RegisteredUser::new(
|
Ok(RegisteredUser::new(
|
||||||
id,
|
id,
|
||||||
|
@ -203,7 +203,6 @@ impl NotSignedInUser {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
info!("User {} attached certificate with fingerprint {:x?}", username, &self.certificate[..]);
|
|
||||||
user.add_certificate(self.certificate)?;
|
user.add_certificate(self.certificate)?;
|
||||||
user.active_certificate = Some(self.certificate);
|
user.active_certificate = Some(self.certificate);
|
||||||
Ok(Some(user))
|
Ok(Some(user))
|
||||||
|
@ -295,13 +294,18 @@ impl<UserData: Serialize + DeserializeOwned> RegisteredUser<UserData> {
|
||||||
try_password: impl AsRef<[u8]>
|
try_password: impl AsRef<[u8]>
|
||||||
) -> Result<bool> {
|
) -> Result<bool> {
|
||||||
if let Some((hash, salt)) = &self.inner.pass_hash {
|
if let Some((hash, salt)) = &self.inner.pass_hash {
|
||||||
Ok(argon2::verify_raw(
|
let result = argon2::verify_raw(
|
||||||
try_password.as_ref(),
|
try_password.as_ref(),
|
||||||
salt,
|
salt,
|
||||||
hash.as_ref(),
|
hash.as_ref(),
|
||||||
&ARGON2_CONFIG,
|
&ARGON2_CONFIG,
|
||||||
)?)
|
)?;
|
||||||
|
if !result {
|
||||||
|
info!("Someone failed to log in to the account of {} (wrong)", self);
|
||||||
|
}
|
||||||
|
Ok(result)
|
||||||
} else {
|
} else {
|
||||||
|
info!("Someone failed to log in to the account of {} (not set)", self);
|
||||||
Err(super::UserManagerError::PasswordNotSet)
|
Err(super::UserManagerError::PasswordNotSet)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -350,6 +354,8 @@ impl<UserData: Serialize + DeserializeOwned> RegisteredUser<UserData> {
|
||||||
salt,
|
salt,
|
||||||
));
|
));
|
||||||
self.has_changed = true;
|
self.has_changed = true;
|
||||||
|
|
||||||
|
info!("Updated password for user {}", self);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -363,6 +369,7 @@ impl<UserData: Serialize + DeserializeOwned> RegisteredUser<UserData> {
|
||||||
{
|
{
|
||||||
self.inner.store(&self.manager.users, self.uid)?;
|
self.inner.store(&self.manager.users, self.uid)?;
|
||||||
self.has_changed = false;
|
self.has_changed = false;
|
||||||
|
debug!("Changes to user {} saved", self);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -394,6 +401,8 @@ impl<UserData: Serialize + DeserializeOwned> RegisteredUser<UserData> {
|
||||||
Ok(())
|
Ok(())
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
|
info!("User {} added certificate with fingerprint {:X?}", self, certificate);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -436,6 +445,8 @@ impl<UserData: Serialize + DeserializeOwned> RegisteredUser<UserData> {
|
||||||
Ok(())
|
Ok(())
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
|
info!("Deleted user {}", self);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -469,6 +480,19 @@ impl<UserData: Serialize + DeserializeOwned> RegisteredUser<UserData> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl <UD: Serialize + DeserializeOwned> std::fmt::Display for RegisteredUser<UD> {
|
||||||
|
/// Synthesize a unique identifier for the user including their username
|
||||||
|
///
|
||||||
|
/// This is literally just the user's username postfixed with `#` and eight characters
|
||||||
|
/// representing the hex encoding of the users id. This is not guaranteed not to
|
||||||
|
/// change, but is great for logging, because it is simultaniously human-readable but
|
||||||
|
/// at the same time the last 8 characters offer a way to look up a user even with
|
||||||
|
/// username changes
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
write!(f, "{}#{:08X}", self.username(), self.uid)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<UserData: Serialize + DeserializeOwned> std::ops::Drop for RegisteredUser<UserData> {
|
impl<UserData: Serialize + DeserializeOwned> std::ops::Drop for RegisteredUser<UserData> {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
if self.has_changed {
|
if self.has_changed {
|
||||||
|
@ -491,6 +515,7 @@ impl<UserData: Serialize + DeserializeOwned> AsMut<UserData> for RegisteredUser<
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[cfg(all(feature = "user_management_advanced", not(feature = "ring")))]
|
#[cfg(all(feature = "user_management_advanced", not(feature = "ring")))]
|
||||||
/// Inexpensive but low quality random
|
/// Inexpensive but low quality random
|
||||||
fn pcg8(state: &mut u16) -> u8 {
|
fn pcg8(state: &mut u16) -> u8 {
|
||||||
|
|
Loading…
Reference in a new issue