-
-
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.
code is very dirty for now, to be cleaned up later, for now we just care about functionality
- Loading branch information
glendc
committed
Oct 22, 2023
1 parent
a85e5cc
commit 5e343ed
Showing
11 changed files
with
215 additions
and
12 deletions.
There are no files selected for viewing
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
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,13 +1,25 @@ | ||
use std::sync::Arc; | ||
|
||
use askama::Template; | ||
use askama_axum::{IntoResponse, Response}; | ||
use axum::extract::State; | ||
use tower_cookies::Cookies; | ||
|
||
#[derive(Template)] | ||
#[template(path = "../templates/index.html")] | ||
pub struct GetTemplate; | ||
pub struct GetTemplate { | ||
pub email: String, | ||
} | ||
|
||
#[derive(Template)] | ||
#[template(path = "../templates/content/login.html")] | ||
pub struct IndexLoginTemplate; | ||
|
||
pub async fn get() -> IndexLoginTemplate { | ||
IndexLoginTemplate | ||
pub async fn get(State(state): State<Arc<crate::router::State>>, cookies: Cookies) -> Response { | ||
if let Some(cookie) = cookies.get(crate::services::COOKIE_NAME) { | ||
if let Some(email) = state.auth.verify_cookie(cookie.value()) { | ||
return GetTemplate { email }.into_response(); | ||
} | ||
} | ||
IndexLoginTemplate.into_response() | ||
} |
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 |
---|---|---|
|
@@ -4,10 +4,14 @@ use serde::Deserialize; | |
|
||
#[derive(Template)] | ||
#[template(path = "../templates/index.html")] | ||
pub struct GetTemplate; | ||
pub struct GetTemplate { | ||
pub email: String, | ||
} | ||
|
||
pub async fn get() -> GetTemplate { | ||
GetTemplate | ||
GetTemplate { | ||
email: "[email protected]".to_string(), | ||
} | ||
} | ||
|
||
#[derive(Template)] | ||
|
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,19 @@ | ||
use axum::response::Redirect; | ||
use serde::Deserialize; | ||
use tower_cookies::{cookie::time::OffsetDateTime, Cookie, Cookies}; | ||
|
||
#[derive(Deserialize)] | ||
pub struct GetQuery { | ||
pub magic: Option<String>, | ||
} | ||
|
||
pub async fn get(cookies: Cookies) -> Redirect { | ||
let mut cookie = Cookie::new(crate::services::COOKIE_NAME, ""); | ||
cookie.set_path("/"); | ||
let offset = OffsetDateTime::from_unix_timestamp(0_i64).unwrap(); | ||
cookie.set_expires(offset); | ||
cookies.add(cookie); | ||
|
||
tracing::debug!("logout user upon their request"); | ||
Redirect::temporary("/") | ||
} |
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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
mod auth; | ||
pub use auth::Auth; | ||
pub use auth::{Auth, COOKIE_NAME}; |
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