diff --git a/src/user_management/manager.rs b/src/user_management/manager.rs index 015132a..d9df8e1 100644 --- a/src/user_management/manager.rs +++ b/src/user_management/manager.rs @@ -4,7 +4,7 @@ use serde::{Deserialize, Serialize, de::DeserializeOwned}; use std::path::Path; use crate::user_management::{User, Result}; -use crate::user_management::user::{SignedInUser, NotSignedInUser, PartialUser}; +use crate::user_management::user::{RegisteredUser, NotSignedInUser, PartialUser}; #[derive(Debug, Clone, Deserialize, Serialize)] /// Data stored in the certificate tree about a certain certificate @@ -74,13 +74,13 @@ impl UserManager { pub fn lookup_user( &self, username: impl AsRef - ) -> Result>> + ) -> Result>> where UserData: Serialize + DeserializeOwned { if let Some(bytes) = self.users.get(username.as_ref())? { let inner: PartialUser = bincode::deserialize_from(bytes.as_ref())?; - Ok(Some(SignedInUser::new(username.as_ref().to_owned(), None, self.clone(), inner))) + Ok(Some(RegisteredUser::new(username.as_ref().to_owned(), None, self.clone(), inner))) } else { Ok(None) } diff --git a/src/user_management/mod.rs b/src/user_management/mod.rs index 2e56a81..1864e8a 100644 --- a/src/user_management/mod.rs +++ b/src/user_management/mod.rs @@ -12,9 +12,9 @@ //! * Ask users with a certificate not yet linked to an account to create an account using //! [`NotSignedInUser::register()`] or link their certificate to an existing account //! with a password using [`NotSignedInUser::attach()`]. -//! * You should now have a [`SignedInUser`] either from registering/attaching a +//! * You should now have a [`RegisteredUser`] either from registering/attaching a //! [`NotSignedInUser`] or because the user was already registered -//! * Access and modify user data using [`SignedInUser::as_mut()`], changes are +//! * Access and modify user data using [`RegisteredUser::as_mut()`], changes are //! automatically persisted to the database (on user drop). //! //! Use of this module requires the `user_management` feature to be enabled diff --git a/src/user_management/user.rs b/src/user_management/user.rs index 96cdad2..049c0cc 100644 --- a/src/user_management/user.rs +++ b/src/user_management/user.rs @@ -5,14 +5,14 @@ //! //! [`User`] is the most common for of user struct, and typically comes from calling //! [`Request::user()`](crate::types::Request::user()). This is an enum with several -//! variants, and can be specialized into a [`NotSignedInUser`] or a [`SignedInUser`] if +//! variants, and can be specialized into a [`NotSignedInUser`] or a [`RegisteredUser`] if //! the user has presented a certificate. These two subtypes have more specific //! information, like the user's username and active certificate. //! -//! [`SignedInUser`] is particularly signifigant in that this is the struct used to modify +//! [`RegisteredUser`] is particularly signifigant in that this is the struct used to modify //! the data stored for almost all users. This is accomplished through the -//! [`as_mut()`](SignedInUser::as_mut) method. Changes made this way must be persisted -//! using [`save()`](SignedInUser::save()) or by dropping the user. +//! [`as_mut()`](RegisteredUser::as_mut) method. Changes made this way must be persisted +//! using [`save()`](RegisteredUser::save()) or by dropping the user. use rustls::Certificate; use serde::{Deserialize, Serialize, de::DeserializeOwned}; use sled::Transactional; @@ -83,7 +83,7 @@ pub enum User { NotSignedIn(NotSignedInUser), /// A user connecting with an identified account - SignedIn(SignedInUser), + SignedIn(RegisteredUser), } #[derive(Clone, Debug)] @@ -109,13 +109,13 @@ impl NotSignedInUser { pub fn register( self, username: String, - ) -> Result> { + ) -> Result> { if self.manager.users.contains_key(username.as_str())? { Err(super::UserManagerError::UsernameNotUnique) } else { let cert_hash = UserManager::hash_certificate(&self.certificate); - let newser = SignedInUser::new( + let newser = RegisteredUser::new( username.clone(), Some(self.certificate.clone()), self.manager, @@ -158,7 +158,7 @@ impl NotSignedInUser { /// log in with either this certificate or any of the certificates they already had /// registered. /// - /// This method returns the new SignedInUser instance representing the now-attached + /// This method returns the new RegisteredUser instance representing the now-attached /// user. /// /// # Errors @@ -170,7 +170,7 @@ impl NotSignedInUser { pub fn attach( username: impl AsRef<[u8]>, password: impl AsRef<[u8]>, - ) -> Result> { + ) -> Result> { todo!() } } @@ -179,16 +179,16 @@ impl NotSignedInUser { /// Data about a logged in user /// /// For more information about the user lifecycle and sign-in stages, see [`User`] -pub struct SignedInUser { +pub struct RegisteredUser { username: String, active_certificate: Option, manager: UserManager, inner: PartialUser, - /// Indicates that [`SignedInUser::as_mut()`] has been called, but [`SignedInUser::save()`] has not + /// Indicates that [`RegisteredUser::as_mut()`] has been called, but [`RegisteredUser::save()`] has not has_changed: bool, } -impl SignedInUser { +impl RegisteredUser { /// Create a new user from parts pub (crate) fn new( @@ -268,7 +268,7 @@ impl SignedInUser { /// users are able to add more devices to their account, and recover their account if /// it's lost. Note that this will completely overwrite the users old password. /// - /// Use [`SignedInUser::check_password()`] and [`NotSignedInUser::attach()`] to check + /// Use [`RegisteredUser::check_password()`] and [`NotSignedInUser::attach()`] to check /// the password against another one, or to link a new certificate. /// /// Because this method uses a key derivation algorithm, this should be considered a @@ -305,7 +305,7 @@ impl SignedInUser { } } -impl std::ops::Drop for SignedInUser { +impl std::ops::Drop for RegisteredUser { fn drop(&mut self) { if self.has_changed { if let Err(e) = self.save() { @@ -315,14 +315,14 @@ impl std::ops::Drop for SignedInUser AsRef for SignedInUser { +impl AsRef for RegisteredUser { fn as_ref(&self) -> &UserData { &self.inner.data } } -impl AsMut for SignedInUser { - /// NOTE: Changes made to the user data won't be persisted until SignedInUser::save +impl AsMut for RegisteredUser { + /// NOTE: Changes made to the user data won't be persisted until RegisteredUser::save /// is called fn as_mut(&mut self) -> &mut UserData { self.has_changed = true;