Add views to test user login

This commit is contained in:
Douze Bé 2024-10-21 22:20:39 +02:00
parent c917942591
commit 6abb380c05
9 changed files with 142 additions and 15 deletions

View file

@ -1,6 +1,6 @@
<!DOCTYPE html>
<html lang="en">
<html lang="en" class="h-full bg-white">
<head>
<title>{% block title %}{% endblock title %}</title>
@ -12,7 +12,7 @@
{% endblock head %}
</head>
<body class="prose p-10">
<body class="prose p-10 h-full">
<div id="content">
{% block content %}
{% endblock content %}

View file

@ -1,12 +0,0 @@
<html><body>
<img src="/static/image.png" width="200"/>
<br/>
find this tera template at <code>assets/views/home/hello.html</code>:
<br/>
<br/>
{{ t(key="hello-world", lang="en-US") }},
<br/>
{{ t(key="hello-world", lang="de-DE") }}
</body></html>

View file

@ -0,0 +1,15 @@
{% extends "base.html" %}
{% block title %}
Login
{% endblock title %}
{% block content %}
<div class="flex min-h-full flex-col justify-center px-6 py-12 lg:px-8">
<div class="sm:mx-auto sm:w-full sm:max-w-sm">
<img class="mx-auto h-12 w-auto" src="https://nixin.distrilab.eu/logo-nixin.svg" alt="NixiN">
<h2 class="mt-10 text-center text-2xl font-bold leading-9 tracking-tight text-gray-900">Index</h2>
</div>
</div>
{% endblock content %}

View file

@ -0,0 +1,68 @@
{% extends "base.html" %}
{% block title %}
Login
{% endblock title %}
{% block content %}
<!--
This example requires some changes to your config:
```
// tailwind.config.js
module.exports = {
// ...
plugins: [
// ...
require('@tailwindcss/forms'),
],
}
```
-->
<!--
This example requires updating your template:
```
<html class="h-full bg-white">
<body class="h-full">
```
-->
<div class="flex min-h-full flex-col justify-center px-6 py-12 lg:px-8">
<div class="sm:mx-auto sm:w-full sm:max-w-sm">
<img class="mx-auto h-12 w-auto" src="https://nixin.distrilab.eu/logo-nixin.svg" alt="NixiN">
<h2 class="mt-10 text-center text-2xl font-bold leading-9 tracking-tight text-gray-900">Sign in to your account</h2>
</div>
<div class="mt-10 sm:mx-auto sm:w-full sm:max-w-sm">
<form class="space-y-6" action="#" method="POST">
<div>
<label for="email" class="block text-sm font-medium leading-6 text-gray-900">Email address</label>
<div class="mt-2">
<input id="email" name="email" type="email" autocomplete="email" required class="block w-full rounded-md border-0 py-1.5 text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:ring-2 focus:ring-inset focus:ring-indigo-600 sm:text-sm sm:leading-6">
</div>
</div>
<div>
<div class="flex items-center justify-between">
<label for="password" class="block text-sm font-medium leading-6 text-gray-900">Password</label>
<div class="text-sm">
<a href="#" class="font-semibold text-indigo-600 hover:text-indigo-500">Forgot password?</a>
</div>
</div>
<div class="mt-2">
<input id="password" name="password" type="password" autocomplete="current-password" required class="block w-full rounded-md border-0 py-1.5 text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:ring-2 focus:ring-inset focus:ring-indigo-600 sm:text-sm sm:leading-6">
</div>
</div>
<div>
<button type="submit" class="flex w-full justify-center rounded-md bg-indigo-600 px-3 py-1.5 text-sm font-semibold leading-6 text-white shadow-sm hover:bg-indigo-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600">Sign in</button>
</div>
</form>
<p class="mt-10 text-center text-sm text-gray-500">
No account yet?
<a href="#" class="font-semibold leading-6 text-indigo-600 hover:text-indigo-500">Register a new account</a>
</p>
</div>
</div>
{% endblock content %}

View file

@ -3,8 +3,40 @@
#![allow(clippy::unused_async)]
use loco_rs::prelude::*;
use axum::debug_handler;
use axum::{extract::State, Json};
use loco_rs::{
app::AppContext,
controller::middleware,
Result,
};
use crate::{
models::users,
views,
};
#[debug_handler]
pub async fn home(
//auth: auth::JWT,
ViewEngine(v): ViewEngine<TeraView>,
State(ctx): State<AppContext>,
) -> Result<Response> {
//let current_user = users::Model::find_by_pid(&ctx.db, &auth.claims.pid).await;
// match current_user {
// Ok(user) => {
// views::home::index(&v,&user)
// }
// Err(_) => {
// views::home::login(&v)
// }
// }
views::home::login(&v)
}
pub fn routes() -> Routes {
Routes::new()
.prefix("homes")
//.prefix("homes")
.add("/", get(home))
}

View file

@ -0,0 +1,22 @@
use loco_rs::prelude::*;
use crate::models::users;
/// Display the login form.
///
/// # Errors
///
/// When there is an issue with rendering the view.
pub fn login(v: &impl ViewRenderer) -> Result<Response> {
format::render().view(v, "home/login.html", data!({}))
}
/// Display the index page for lged-in user
///
/// # Errors
///
/// When there is an issue with rendering the view.
pub fn index(v: &impl ViewRenderer, user: &users::Model) -> Result<Response> {
format::render().view(v, "server/show.html", data!({"user": user}))
}

View file

@ -1,6 +1,8 @@
pub mod auth;
pub mod user;
pub mod home;
pub mod server;
pub mod bundle;
pub mod service;