Skip to content

Commit

Permalink
fix template lang
Browse files Browse the repository at this point in the history
  • Loading branch information
aumetra committed Nov 29, 2024
1 parent 942f8df commit 9fafe02
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 64 deletions.
9 changes: 4 additions & 5 deletions kitsune/src/http/handler/oauth/authorize.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use crate::oauth2::{OAuthEndpoint, OAuthOwnerSolicitor};
use argon2::{Argon2, PasswordHash, PasswordVerifier};
use askama::Template;
use axum::{
debug_handler,
extract::{OriginalUri, State},
response::Redirect,
response::{Html, Redirect},
Form,
};
use axum_extra::{
Expand Down Expand Up @@ -50,12 +49,12 @@ pub struct LoginForm {
password: String,
}

#[derive(Template)]
#[template(path = "oauth/login.html")]
#[derive(Serialize)]
pub struct LoginPage {
flash_messages: IncomingFlashes,
}

#[debug_handler(state = crate::state::Zustand)]
pub async fn get(
#[cfg(feature = "oidc")] (State(oidc_service), Query(query)): (
State<Option<OidcService>>,
Expand All @@ -68,7 +67,7 @@ pub async fn get(
csrf_handle: CsrfHandle,
flash_messages: IncomingFlashes,
oauth_req: OAuthRequest,
) -> Result<Either3<OAuthResponse, LoginPage, Redirect>> {
) -> Result<Either3<OAuthResponse, Html<String>, Redirect>> {
#[cfg(feature = "oidc")]
if let Some(oidc_service) = oidc_service {
let application = with_connection!(db_pool, |db_conn| {
Expand Down
2 changes: 1 addition & 1 deletion kitsune/src/oauth2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ fn chrono_to_timestamp(ts: chrono::DateTime<Utc>) -> iso8601_timestamp::Timestam
.into()
}

#[derive(AsRefStr, Clone, Copy, Debug, EnumIter, EnumMessage, EnumString)]
#[derive(AsRefStr, Clone, Copy, Debug, EnumIter, EnumMessage, EnumString, Serialize)]
#[strum(serialize_all = "lowercase")]
pub enum OAuthScope {
#[strum(message = "Read admin-related data", serialize = "admin:read")]
Expand Down
3 changes: 0 additions & 3 deletions kitsune/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="/public/app.css" />

{% block head %} {% endblock %}

<title>{% block title %} {% endblock %}</title>
</head>

Expand Down
89 changes: 41 additions & 48 deletions kitsune/templates/oauth/consent.html
Original file line number Diff line number Diff line change
@@ -1,53 +1,46 @@
{% extends "../base.html" %}
{% extends "../base.html" %} {% block title %} OAuth Login {% endblock %} {%
macro add_query_params() -%}
<input type="hidden" name="client_id" value="{{ query.client_id }}" />
<input type="hidden" name="redirect_uri" value="{{ query.redirect_uri }}" />
<input type="hidden" name="response_type" value="{{ query.response_type }}" />
<input type="hidden" name="scope" value="{{ query.scope }}" />
<input type="hidden" name="state" value="{{ query.state }}" />
<input type="hidden" name="csrf_token" value="{{ csrf_token }}" />
{%- endmacro %} {% block body %}
<p class="header">Kitsune</p>

{% block title %}
OAuth Login
{% endblock %}

{% macro add_query_params() %}
<input type="hidden" name="client_id" value="{{ query.client_id }}" />
<input type="hidden" name="redirect_uri" value="{{ query.redirect_uri }}" />
<input type="hidden" name="response_type" value="{{ query.response_type }}" />
<input type="hidden" name="scope" value="{{ query.scope }}" />
<input type="hidden" name="state" value="{{ query.state.as_deref().unwrap_or("") }}" />
<input type="hidden" name="csrf_token" value="{{ csrf_token }}" />
{% endmacro %}

{% block body %}
<p class="header">
Kitsune
</p>

<div class="consent-text">
<span class="appName">{{app_name}}</span> wants the following access to your Kitsune account:
<p>
<ul>
{% for scope in scopes %}
<li>
{{ scope.get_message().unwrap() }}
</li>
{% endfor %}
</ul>
</p>
</div>
<div class="consent-text">
<span class="appName">{{app_name}}</span> wants the following access to your
Kitsune account:
<p></p>
<ul>
{% for scope in scopes %}
<li>{{ scope.get_message().unwrap() }}</li>
{% endfor %}
</ul>
</div>

<div class="consent-forms">
<form method="get">
{% call add_query_params() %}
<input type="hidden" name="login_consent" value="accept" />
<input class="formButton" type="submit" value="Accept" />
</form>
<div class="consent-forms">
<form method="get">
{% add_query_params() %}
<input type="hidden" name="login_consent" value="accept" />
<input class="formButton" type="submit" value="Accept" />
</form>

<form method="get">
{% call add_query_params() %}
<input type="hidden" name="login_consent" value="deny" />
<input class="formButton" type="submit" value="Deny" />
</form>
</div>
<form method="get">
{% add_query_params() %}
<input type="hidden" name="login_consent" value="deny" />
<input class="formButton" type="submit" value="Deny" />
</form>
</div>

<div class="disclaimer">
Authenticated as <span class="authUsername">{{ authenticated_username }}</span> ~
<a href="#"
onclick="document.cookie='user_id=; expires=Thu, 01 Jan 1970 00:00:00 UTC;';window.location.reload();">Logout</a>
</div>
<div class="disclaimer">
Authenticated as
<span class="authUsername">{{ authenticated_username }}</span> ~
<a
href="#"
onclick="document.cookie='user_id=; expires=Thu, 01 Jan 1970 00:00:00 UTC;';window.location.reload();"
>Logout</a
>
</div>
{% endblock %}
21 changes: 14 additions & 7 deletions kitsune/templates/oauth/login.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
{% extends "../base.html" %} {% block title %}OAuth Login{% endblock %} {% block
body %}
{% extends "base.html" %}

<div></div>
{% block title %}OAuth Login{% endblock %}

<div></div>
{% block body %}
<p class="header">Kitsune</p>

{% for (_level, msg) in flash_messages %}
Expand All @@ -8,22 +13,24 @@

<form method="post">
<div>
<label class="label" for="username">Username</label><br />
<input
<label class="label" for="username">Username</label>
<br /><input
class="field"
type="text"
id="username"
name="username"
value=""
/><br />
<label class="label" for="password">Password</label><br />
/>
<br /><label class="label" for="password">Password</label><br />
<input
class="field"
type="password"
id="password"
name="password"
value=""
/><br /><br />
/>

<br /><br />
</div>
<input class="formButton" type="submit" value="Submit" />
</form>
Expand Down

0 comments on commit 9fafe02

Please sign in to comment.