Pleased the linters

pull/36/head
Jef Roosens 2021-08-29 19:07:36 +02:00
parent 6858e9da62
commit 27b904b3f5
Signed by: Jef Roosens
GPG Key ID: 955C0660072F691F
4 changed files with 8 additions and 16 deletions

View File

@ -9,7 +9,7 @@ use sha2::Sha256;
use crate::{ use crate::{
db::{ db::{
tokens::{NewRefreshToken, RefreshToken}, tokens::{NewRefreshToken, RefreshToken},
users::{NewUser, User}, users::User,
}, },
errors::RbError, errors::RbError,
schema::{refresh_tokens::dsl as refresh_tokens, users::dsl as users}, schema::{refresh_tokens::dsl as refresh_tokens, users::dsl as users},

View File

@ -1,19 +1,11 @@
use ::jwt::SignWithKey;
use argon2::verify_encoded; use argon2::verify_encoded;
use chrono::Utc;
use diesel::{insert_into, prelude::*, PgConnection}; use diesel::{insert_into, prelude::*, PgConnection};
use hmac::{Hmac, NewMac};
use rand::{thread_rng, Rng}; use rand::{thread_rng, Rng};
use serde::{Deserialize, Serialize};
use sha2::Sha256;
use crate::{ use crate::{
db::{ db::users::{NewUser, User},
tokens::{NewRefreshToken, RefreshToken},
users::{NewUser, User},
},
errors::RbError, errors::RbError,
schema::{refresh_tokens::dsl as refresh_tokens, users::dsl as users}, schema::users::dsl as users,
}; };
pub mod jwt; pub mod jwt;

View File

@ -39,10 +39,10 @@ impl<'r> FromRequest<'r> for Bearer<'r>
} }
/// Verifies the provided JWT is valid. /// Verifies the provided JWT is valid.
pub struct JWT(Claims); pub struct Jwt(Claims);
#[rocket::async_trait] #[rocket::async_trait]
impl<'r> FromRequest<'r> for JWT impl<'r> FromRequest<'r> for Jwt
{ {
type Error = rb::errors::RbError; type Error = rb::errors::RbError;
@ -91,7 +91,7 @@ impl<'r> FromRequest<'r> for User
async fn from_request(req: &'r Request<'_>) -> Outcome<Self, Self::Error> async fn from_request(req: &'r Request<'_>) -> Outcome<Self, Self::Error>
{ {
let claims = try_outcome!(req.guard::<JWT>().await).0; let claims = try_outcome!(req.guard::<Jwt>().await).0;
// Verify key hasn't yet expired // Verify key hasn't yet expired
if chrono::Utc::now().timestamp() > claims.exp { if chrono::Utc::now().timestamp() > claims.exp {

View File

@ -10,13 +10,13 @@ pub fn routes() -> Vec<rocket::Route>
} }
#[get("/users")] #[get("/users")]
async fn get_users(admin: Admin, conn: RbDbConn) -> rb::Result<Json<Vec<db::User>>> async fn get_users(_admin: Admin, conn: RbDbConn) -> rb::Result<Json<Vec<db::User>>>
{ {
Ok(Json(conn.run(|c| db::users::all(c)).await?)) Ok(Json(conn.run(|c| db::users::all(c)).await?))
} }
#[post("/users", data = "<user>")] #[post("/users", data = "<user>")]
async fn create_user(admin: Admin, conn: RbDbConn, user: Json<db::NewUser>) -> rb::Result<()> async fn create_user(_admin: Admin, conn: RbDbConn, user: Json<db::NewUser>) -> rb::Result<()>
{ {
Ok(conn Ok(conn
.run(move |c| db::users::create(c, &user.into_inner())) .run(move |c| db::users::create(c, &user.into_inner()))