-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c0ff165
commit cfd230c
Showing
30 changed files
with
945 additions
and
450 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
.sqlx/query-d90c07428d370f724bd0e5ddc3d32d5736895d5c247d5eff0fcf27fa7dc63fe7.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
use crate::session_state::TypedSession; | ||
use crate::utils::{e500, see_other}; | ||
use actix_web::body::MessageBody; | ||
use actix_web::dev::{ServiceRequest, ServiceResponse}; | ||
use actix_web::error::InternalError; | ||
use actix_web::FromRequest; | ||
use actix_web::HttpMessage; | ||
use actix_web_lab::middleware::Next; | ||
use std::ops::Deref; | ||
use uuid::Uuid; | ||
|
||
#[derive(Copy, Clone, Debug)] | ||
pub struct UserId(Uuid); | ||
|
||
impl std::fmt::Display for UserId { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
self.0.fmt(f) | ||
} | ||
} | ||
|
||
impl Deref for UserId { | ||
type Target = Uuid; | ||
|
||
fn deref(&self) -> &Self::Target { | ||
&self.0 | ||
} | ||
} | ||
|
||
pub async fn reject_anonymous_users( | ||
mut req: ServiceRequest, | ||
next: Next<impl MessageBody>, | ||
) -> Result<ServiceResponse<impl MessageBody>, actix_web::Error> { | ||
let session = { | ||
let (http_request, payload) = req.parts_mut(); | ||
TypedSession::from_request(http_request, payload).await | ||
}?; | ||
|
||
match session.get_user_id().map_err(e500)? { | ||
Some(user_id) => { | ||
req.extensions_mut().insert(UserId(user_id)); | ||
next.call(req).await | ||
} | ||
None => { | ||
let response = see_other("/login"); | ||
let e = anyhow::anyhow!("The user has not logged in"); | ||
Err(InternalError::from_response(e, response).into()) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
mod middleware; | ||
mod password; | ||
|
||
pub use password::{change_password, validate_credentials, AuthError, Credentials}; | ||
|
||
pub use middleware::reject_anonymous_users; | ||
pub use middleware::UserId; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,4 @@ pub mod routes; | |
pub mod session_state; | ||
pub mod startup; | ||
pub mod telemetry; | ||
pub mod utils; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
use crate::session_state::TypedSession; | ||
use crate::utils::{e500, see_other}; | ||
use actix_web::HttpResponse; | ||
use actix_web_flash_messages::FlashMessage; | ||
|
||
pub async fn log_out(session: TypedSession) -> Result<HttpResponse, actix_web::Error> { | ||
if session.get_user_id().map_err(e500)?.is_none() { | ||
Ok(see_other("/login")) | ||
} else { | ||
session.log_out(); | ||
FlashMessage::info("You have successfully logged out.").send(); | ||
Ok(see_other("/login")) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,9 @@ | ||
mod dashboard; | ||
mod logout; | ||
mod newsletters; | ||
mod password; | ||
|
||
pub use dashboard::admin_dashboard; | ||
pub use logout::log_out; | ||
pub use newsletters::*; | ||
pub use password::*; |
Oops, something went wrong.