Skip to content

Commit

Permalink
move constants to module
Browse files Browse the repository at this point in the history
  • Loading branch information
fairingrey committed Feb 15, 2022
1 parent 661497b commit c923879
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 15 deletions.
11 changes: 6 additions & 5 deletions src/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ use axum::{
};
use redis::AsyncCommands;

use crate::{error::MixiniError, models::User, server::State};

pub(crate) const SESSION_COOKIE_NAME: &str = "msessid";
pub(crate) const SESSION_KEY_PREFIX: &str = "session:";
pub(crate) const SESSION_DURATION_SECS: usize = 1209600;
use crate::{
constants::{SESSION_COOKIE_NAME, SESSION_DURATION_SECS, SESSION_KEY_PREFIX},
error::MixiniError,
models::User,
server::State,
};

/// The authorization of a user making a request.
///
Expand Down
17 changes: 17 additions & 0 deletions src/constants.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//! Constants
use lazy_static::lazy_static;

lazy_static! {
pub(crate) static ref DOMAIN: String =
std::env::var("DOMAIN").expect("DOMAIN is not set in env");
}

// for authorized sessions
pub(crate) const SESSION_COOKIE_NAME: &str = "msessid";
pub(crate) const SESSION_KEY_PREFIX: &str = "session:";
pub(crate) const SESSION_DURATION_SECS: usize = 1209600;

// for user verify requests
pub(crate) const VERIFY_KEY_PREFIX: &str = "verify:";
pub(crate) const VERIFY_EXPIRY_SECONDS: usize = 86400;
7 changes: 1 addition & 6 deletions src/handlers/login.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@ use axum::{
headers::Cookie,
http::{header, Response, StatusCode},
};
use lazy_static::lazy_static;
use libreauth::pass::HashBuilder;
use redis::AsyncCommands;
use serde::Deserialize;
use std::sync::Arc;
use validator::Validate;

use crate::{
auth::{SESSION_COOKIE_NAME, SESSION_DURATION_SECS, SESSION_KEY_PREFIX},
constants::{DOMAIN, SESSION_COOKIE_NAME, SESSION_DURATION_SECS, SESSION_KEY_PREFIX},
error::MixiniError,
handlers::{ValidatedForm, RE_PASSWORD, RE_USERNAME},
models::User,
Expand All @@ -23,10 +22,6 @@ use crate::{
},
};

lazy_static! {
static ref DOMAIN: String = std::env::var("DOMAIN").expect("DOMAIN is not set in env");
}

/// The form input of a `POST /user/login` request.
#[derive(Debug, Validate, Deserialize)]
pub(crate) struct LoginForm {
Expand Down
8 changes: 4 additions & 4 deletions src/handlers/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ use uuid::Uuid;
use validator::Validate;

use crate::{
auth::{Auth, SESSION_COOKIE_NAME, SESSION_KEY_PREFIX},
auth::Auth,
constants::{
SESSION_COOKIE_NAME, SESSION_KEY_PREFIX, VERIFY_EXPIRY_SECONDS, VERIFY_KEY_PREFIX,
},
error::MixiniError,
handlers::{ValidatedForm, RE_PASSWORD, RE_USERNAME},
models::{Role, User},
server::State,
utils::{mail::send_email_verification_request, pass::HASHER, RKeys},
};

const VERIFY_KEY_PREFIX: &str = "verify:";
const VERIFY_EXPIRY_SECONDS: usize = 86400;

/// The form input for `POST /user`
#[derive(Debug, Validate, Deserialize)]
pub(crate) struct CreateUserForm {
Expand Down
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
)]

pub(crate) mod auth;
pub(crate) mod constants;
pub(crate) mod error;
pub(crate) mod handlers;
pub(crate) mod macros;
Expand Down

0 comments on commit c923879

Please sign in to comment.