diff options
author | Tyler Murphy <tylermurphy534@gmail.com> | 2023-01-28 18:04:00 -0500 |
---|---|---|
committer | Tyler Murphy <tylermurphy534@gmail.com> | 2023-01-28 18:04:00 -0500 |
commit | b58654fd70958d89b344a6f7acac204f67ae9879 (patch) | |
tree | 60a1960d0d265c9f661e633022164f33e099c81c /src/types/session.rs | |
parent | new rust, clippy (diff) | |
download | xssbook-b58654fd70958d89b344a6f7acac204f67ae9879.tar.gz xssbook-b58654fd70958d89b344a6f7acac204f67ae9879.tar.bz2 xssbook-b58654fd70958d89b344a6f7acac204f67ae9879.zip |
fmt
Diffstat (limited to 'src/types/session.rs')
-rw-r--r-- | src/types/session.rs | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/src/types/session.rs b/src/types/session.rs index 176e389..e704ac7 100644 --- a/src/types/session.rs +++ b/src/types/session.rs @@ -3,16 +3,15 @@ use serde::Serialize; use tracing::instrument; use crate::database; -use crate::types::http::{Result, ResponseCode}; +use crate::types::http::{ResponseCode, Result}; #[derive(Serialize)] pub struct Session { pub user_id: u64, - pub token: String + pub token: String, } impl Session { - #[instrument()] pub fn from_token(token: &str) -> Result<Self> { let Ok(Some(session)) = database::sessions::get_session(token) else { @@ -24,10 +23,14 @@ impl Session { #[instrument()] pub fn new(user_id: u64) -> Result<Self> { - let token: String = rand::thread_rng().sample_iter(&Alphanumeric).take(32).map(char::from).collect(); + let token: String = rand::thread_rng() + .sample_iter(&Alphanumeric) + .take(32) + .map(char::from) + .collect(); match database::sessions::set_session(user_id, &token) { Err(_) => Err(ResponseCode::BadRequest.text("Failed to create session")), - Ok(_) => Ok(Self {user_id, token}) + Ok(_) => Ok(Self { user_id, token }), } } @@ -39,5 +42,4 @@ impl Session { }; Ok(()) } - -}
\ No newline at end of file +} |