refactor
Some checks failed
ci/woodpecker/push/test Pipeline failed

This commit is contained in:
JMARyA 2024-12-29 21:35:48 +01:00
parent 439467f730
commit cd140f0160
Signed by: jmarya
GPG key ID: 901B2ADDF27C2263
4 changed files with 15 additions and 15 deletions

View file

@ -54,14 +54,14 @@ impl User {
/// Create a new user with the given details
///
/// Returns an Option containing the created user, or None if a user already exists with the same username
pub async fn create(username: &str, password: &str, role: UserRole) -> Option<Self> {
pub async fn create(username: String, password: &str, role: UserRole) -> Option<Self> {
// Check if a user already exists with the same username
if Self::find(username).await.is_some() {
if Self::find(&username).await.is_some() {
return None;
}
let u = Self {
username: username.to_string(),
username,
password: bcrypt::hash(password, bcrypt::DEFAULT_COST).unwrap(),
user_role: role,
session: String::new(),
@ -133,7 +133,7 @@ impl ToAPI for User {
/// extracts a user from a request with `session` cookie
async fn extract_user(request: &Request<'_>) -> Option<User> {
if let Some(session_id) = request.cookies().get("session") {
if let Some(user) = User::from_session(session_id.value()).await {
if let Some(user) = User::from_session(session_id.value().to_string()).await {
return Some(user);
}
return None;
@ -164,7 +164,7 @@ impl<'r> FromRequest<'r> for APIUser {
async fn from_request(request: &'r Request<'_>) -> rocket::request::Outcome<Self, Self::Error> {
match request.headers().get_one("token") {
Some(key) => {
if let Some(user) = User::from_session(key).await {
if let Some(user) = User::from_session(key.to_string()).await {
return Outcome::Success(APIUser(user));
}
return Outcome::Error((Status::Unauthorized, ()));