clean code with clippy
This commit is contained in:
@ -121,11 +121,11 @@ WHERE name like ?
|
||||
Ok(user)
|
||||
}
|
||||
|
||||
fn get_hashed_pw(pw: String) -> String {
|
||||
fn get_hashed_pw(pw: &str) -> String {
|
||||
let salt = SaltString::from_b64("dS/X5/sPEKTj4Rzs/CuvzQ").unwrap();
|
||||
let argon2 = Argon2::default();
|
||||
argon2
|
||||
.hash_password(&pw.as_bytes(), &salt)
|
||||
.hash_password(pw.as_bytes(), &salt)
|
||||
.unwrap()
|
||||
.to_string()
|
||||
}
|
||||
@ -135,7 +135,7 @@ WHERE name like ?
|
||||
|
||||
match user.pw.clone() {
|
||||
Some(user_pw) => {
|
||||
let password_hash = Self::get_hashed_pw(pw);
|
||||
let password_hash = Self::get_hashed_pw(&pw);
|
||||
if password_hash == user_pw {
|
||||
return Ok(user);
|
||||
}
|
||||
@ -167,7 +167,7 @@ FROM user
|
||||
}
|
||||
|
||||
pub async fn update_pw(&self, db: &SqlitePool, pw: String) {
|
||||
let pw = Self::get_hashed_pw(pw);
|
||||
let pw = Self::get_hashed_pw(&pw);
|
||||
sqlx::query!("UPDATE user SET pw = ? where id = ?", pw, self.id)
|
||||
.execute(db)
|
||||
.await
|
||||
@ -182,7 +182,7 @@ impl<'r> FromRequest<'r> for User {
|
||||
async fn from_request(req: &'r Request<'_>) -> request::Outcome<Self, Self::Error> {
|
||||
match req.cookies().get_private("loggedin_user") {
|
||||
Some(user) => {
|
||||
let user: User = serde_json::from_str(&user.value()).unwrap(); //TODO: fixme
|
||||
let user: User = serde_json::from_str(user.value()).unwrap(); //TODO: fixme
|
||||
Outcome::Success(user)
|
||||
}
|
||||
None => Outcome::Failure((Status::Unauthorized, LoginError::NotLoggedIn)),
|
||||
@ -197,7 +197,7 @@ impl<'r> FromRequest<'r> for AdminUser {
|
||||
async fn from_request(req: &'r Request<'_>) -> request::Outcome<Self, Self::Error> {
|
||||
match req.cookies().get_private("loggedin_user") {
|
||||
Some(user) => {
|
||||
let user: User = serde_json::from_str(&user.value()).unwrap(); //TODO: fixme
|
||||
let user: User = serde_json::from_str(user.value()).unwrap(); //TODO: fixme
|
||||
match user.try_into() {
|
||||
Ok(user) => Outcome::Success(user),
|
||||
Err(_) => Outcome::Failure((Status::Unauthorized, LoginError::NotAnAdmin)),
|
||||
@ -215,7 +215,7 @@ impl<'r> FromRequest<'r> for CoxUser {
|
||||
async fn from_request(req: &'r Request<'_>) -> request::Outcome<Self, Self::Error> {
|
||||
match req.cookies().get_private("loggedin_user") {
|
||||
Some(user) => {
|
||||
let user: User = serde_json::from_str(&user.value()).unwrap(); //TODO: fixme
|
||||
let user: User = serde_json::from_str(user.value()).unwrap(); //TODO: fixme
|
||||
match user.try_into() {
|
||||
Ok(user) => Outcome::Success(user),
|
||||
Err(_) => Outcome::Failure((Status::Unauthorized, LoginError::NotAnAdmin)),
|
||||
|
Reference in New Issue
Block a user