diff --git a/src/main.rs b/src/main.rs index 6046d5f..d7c92d3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -80,6 +80,7 @@ async fn main() { .route("/google_auth", get(google_auth)) .route("/discord_auth", get(discord_auth)) .route("/login", get(login)) + .route("/logout", get(logout)) .route("/dashboard", get(dashboard)) .route("/auth/callback", get(google_authorized)) .route("/auth/discord", get(discord_authorized)) @@ -98,17 +99,26 @@ async fn main() { // Session is optional async fn index(user: Option) -> impl IntoResponse { - let name = match user { - Some(u) => u.username, - None => "You're not logged in.".to_string(), - }; - let template = IndexTemplate { name }; + let (userid, name) = match user { + Some(u) => (true, u.username), + None => (false, "You're not logged in.".to_string()), + }; + let template = IndexTemplate { userid, name }; HtmlTemplate(template) } async fn login() -> impl IntoResponse { let name = "".to_string(); - let template = LoginTemplate { name }; + let userid = false; + let template = LoginTemplate { userid, name }; + HtmlTemplate(template) +} + +// Valid user session required. If there is none, redirect to the auth page +async fn dashboard(user: User) -> impl IntoResponse { + let name = user.username; + let userid = true; + let template = DashboardTemplate { userid, name }; HtmlTemplate(template) } @@ -157,8 +167,17 @@ fn discord_oauth_client() -> BasicClient { #[derive(Template)] #[template(path = "login.html")] struct LoginTemplate { + userid: bool, name: String, } + +#[derive(Template)] +#[template(path = "dashboard.html")] +struct DashboardTemplate { + userid: bool, + name: String, +} + struct FreshUserId { pub user_id: UserId, pub cookie: HeaderValue, @@ -248,6 +267,7 @@ impl UserId { #[derive(Template)] #[template(path = "index.html")] struct IndexTemplate { + userid: bool, name: String, } @@ -269,14 +289,6 @@ where } } -// Valid user session required. If there is none, redirect to the auth page -async fn dashboard(user: User) -> impl IntoResponse { - format!( - "Welcome to the protected area :)\nHere's your info:\n{:?}", - user - ) -} - async fn logout( Extension(store): Extension, TypedHeader(cookies): TypedHeader, diff --git a/templates/base.html b/templates/base.html index 225c40f..67a3f23 100644 --- a/templates/base.html +++ b/templates/base.html @@ -43,13 +43,14 @@ - - Menu - @@ -62,28 +63,7 @@
-
-
-
-
-

Copyright © 2020 Breezed Co., Ltd. - - - Design: TemplateMo

-
-
-
-
- -
-
-
-
+
diff --git a/templates/index.html b/templates/index.html index 6df8a25..00187a4 100644 --- a/templates/index.html +++ b/templates/index.html @@ -1,6 +1,5 @@ {% extends "base.html" %} {% block content %} -Hello {{ name }}