[add] BODY_EMBED support

[fix] support callback in login buttons
This commit is contained in:
hkau 2024-03-30 14:51:14 -04:00
parent 35edda448e
commit a02a4145b4
7 changed files with 35 additions and 7 deletions

View File

@ -20,6 +20,7 @@ struct LoginTemplate {
auth_state: bool,
bundlrs: String,
puffer: String,
body_embed: String,
}
#[derive(Template)]
@ -31,6 +32,7 @@ struct RegisterTemplate {
auth_state: bool,
bundlrs: String,
puffer: String,
body_embed: String,
}
#[derive(Template)]
@ -42,6 +44,7 @@ struct LoginSecondaryTokenTemplate {
auth_state: bool,
bundlrs: String,
puffer: String,
body_embed: String,
}
#[derive(Template)]
@ -54,6 +57,7 @@ struct UserProfileTemplate {
auth_state: bool,
bundlrs: String,
puffer: String,
body_embed: String,
}
#[derive(Default, PartialEq, serde::Deserialize)]
@ -72,6 +76,7 @@ struct FollowersTemplate {
auth_state: bool,
bundlrs: String,
puffer: String,
body_embed: String,
}
#[derive(Template)]
@ -85,6 +90,7 @@ struct FollowingTemplate {
auth_state: bool,
bundlrs: String,
puffer: String,
body_embed: String,
}
#[derive(Default, PartialEq, serde::Deserialize)]
@ -102,6 +108,7 @@ struct SettingsTemplate {
auth_state: bool,
bundlrs: String,
puffer: String,
body_embed: String,
}
#[get("/d/auth/register")]
@ -123,6 +130,7 @@ pub async fn register_request(
auth_state: base.auth_state,
bundlrs: base.bundlrs,
puffer: base.puffer,
body_embed: base.body_embed,
}
.render()
.unwrap(),
@ -147,6 +155,7 @@ pub async fn login_request(
auth_state: base.auth_state,
bundlrs: base.bundlrs,
puffer: base.puffer,
body_embed: base.body_embed,
}
.render()
.unwrap(),
@ -171,6 +180,7 @@ pub async fn login_secondary_token_request(
auth_state: base.auth_state,
bundlrs: base.bundlrs,
puffer: base.puffer,
body_embed: base.body_embed,
}
.render()
.unwrap(),
@ -505,7 +515,8 @@ pub async fn profile_view_request(
auth_state: base.auth_state,
info: base.info,
bundlrs: base.bundlrs,
puffer: base.puffer
puffer: base.puffer,
body_embed: base.body_embed,
};
return HttpResponse::Ok()
@ -576,7 +587,8 @@ pub async fn followers_request(
auth_state: base.auth_state,
info: base.info,
bundlrs: base.bundlrs,
puffer: base.puffer
puffer: base.puffer,
body_embed: base.body_embed,
};
return HttpResponse::Ok()
@ -648,7 +660,8 @@ pub async fn following_request(
auth_state: base.auth_state,
info: base.info,
bundlrs: base.bundlrs,
puffer: base.puffer
puffer: base.puffer,
body_embed: base.body_embed,
};
return HttpResponse::Ok()
@ -722,7 +735,8 @@ pub async fn user_settings_request(
auth_state: base.auth_state,
info: base.info,
bundlrs: base.bundlrs,
puffer: base.puffer
puffer: base.puffer,
body_embed: base.body_embed,
};
return HttpResponse::Ok()

View File

@ -3,6 +3,7 @@ pub struct BaseTemplate {
pub auth_state: bool,
pub bundlrs: String,
pub puffer: String,
pub body_embed: String,
}
pub fn get_base_values(token_cookie: bool) -> BaseTemplate {
@ -15,11 +16,19 @@ pub fn get_base_values(token_cookie: bool) -> BaseTemplate {
info = info_req.unwrap();
}
let body_embed_req = std::env::var("BODY_EMBED");
let body_embed = if body_embed_req.is_ok() {
body_embed_req.unwrap()
} else {
String::new()
};
// return
BaseTemplate {
info,
auth_state: token_cookie,
bundlrs: std::env::var("BUNDLRS_ROOT").unwrap(),
puffer: std::env::var("PUFFER_ROOT").unwrap(),
body_embed,
}
}

View File

@ -13,6 +13,7 @@ struct HomeTemplate {
auth_state: bool,
bundlrs: String,
puffer: String,
body_embed: String,
}
#[get("/")]
@ -51,6 +52,7 @@ pub async fn home_request(req: HttpRequest, data: web::Data<guppydb::AppData>) -
auth_state: base.auth_state,
bundlrs: base.bundlrs,
puffer: base.puffer,
body_embed: base.body_embed,
}
.render()
.unwrap(),

View File

@ -28,7 +28,7 @@
</form>
</div>
<a class="button round border" href="/d/auth/login-st" style="width: 25rem" id="switch-button">
<a class="button round border" href="/d/auth/login-st?callback={{ callback }}" style="width: 25rem" id="switch-button">
Use Secondary Token
</a>

View File

@ -28,7 +28,8 @@
</form>
</div>
<a class="button round border" href="/d/auth/login" style="width: 25rem" id="switch-button">
<a class="button round border" href="/d/auth/login?callback={{ callback }}" style="width: 25rem"
id="switch-button">
Use Account ID
</a>

View File

@ -5,7 +5,7 @@
{% block toolbar %}
<a class="button" href="/{{ user.username }}" style="border-left: 0">
{{ user.username }}
<span class="chip badge role-{{ user.role }}" style="padding: 0 0.5rem;">{{ user.username }}</span>
<span class="chip badge role-{{ user.role }}" style="padding: 0 0.5rem;">{{ user.role }}</span>
</a>
{% endblock %}

View File

@ -169,6 +169,8 @@
<div class="toolbar-layout-wrapper" id="_page">
{% block content %}{% endblock %}
</div>
{{ body_embed|safe }}
</body>
</html>