Fix deprecation warnings

This commit is contained in:
Pierre HUBERT 2022-04-18 17:13:41 +02:00
parent fad92c5930
commit 5cf1f63674
9 changed files with 39 additions and 51 deletions

View File

@ -16,21 +16,21 @@ use crate::utils::string_utils::rand_str;
#[derive(Template)] #[derive(Template)]
#[template(path = "settings/clients_list.html")] #[template(path = "settings/clients_list.html")]
struct ClientsListTemplate { struct ClientsListTemplate {
_parent: BaseSettingsPage, _p: BaseSettingsPage,
clients: Vec<Client>, clients: Vec<Client>,
} }
#[derive(Template)] #[derive(Template)]
#[template(path = "settings/users_list.html")] #[template(path = "settings/users_list.html")]
struct UsersListTemplate { struct UsersListTemplate {
_parent: BaseSettingsPage, _p: BaseSettingsPage,
users: Vec<User>, users: Vec<User>,
} }
#[derive(Template)] #[derive(Template)]
#[template(path = "settings/edit_user.html")] #[template(path = "settings/edit_user.html")]
struct EditUserTemplate { struct EditUserTemplate {
_parent: BaseSettingsPage, _p: BaseSettingsPage,
u: User, u: User,
clients: Vec<Client>, clients: Vec<Client>,
} }
@ -38,7 +38,7 @@ struct EditUserTemplate {
pub async fn clients_route(user: CurrentUser, clients: web::Data<ClientManager>) -> impl Responder { pub async fn clients_route(user: CurrentUser, clients: web::Data<ClientManager>) -> impl Responder {
HttpResponse::Ok().body(ClientsListTemplate { HttpResponse::Ok().body(ClientsListTemplate {
_parent: BaseSettingsPage::get( _p: BaseSettingsPage::get(
"Clients list", "Clients list",
&user, &user,
None, None,
@ -122,7 +122,7 @@ pub async fn users_route(user: CurrentUser, users: web::Data<Addr<UsersActor>>,
let users = users.send(users_actor::GetAllUsersRequest).await.unwrap().0; let users = users.send(users_actor::GetAllUsersRequest).await.unwrap().0;
HttpResponse::Ok().body(UsersListTemplate { HttpResponse::Ok().body(UsersListTemplate {
_parent: BaseSettingsPage::get( _p: BaseSettingsPage::get(
"Users list", "Users list",
&user, &user,
danger, danger,
@ -134,7 +134,7 @@ pub async fn users_route(user: CurrentUser, users: web::Data<Addr<UsersActor>>,
pub async fn create_user(user: CurrentUser, clients: web::Data<ClientManager>) -> impl Responder { pub async fn create_user(user: CurrentUser, clients: web::Data<ClientManager>) -> impl Responder {
HttpResponse::Ok().body(EditUserTemplate { HttpResponse::Ok().body(EditUserTemplate {
_parent: BaseSettingsPage::get("Create a new user", user.deref(), None, None), _p: BaseSettingsPage::get("Create a new user", user.deref(), None, None),
u: Default::default(), u: Default::default(),
clients: clients.cloned(), clients: clients.cloned(),
}.render().unwrap()) }.render().unwrap())
@ -155,7 +155,7 @@ pub async fn edit_user(user: CurrentUser,
HttpResponse::Ok().body(EditUserTemplate { HttpResponse::Ok().body(EditUserTemplate {
_parent: BaseSettingsPage::get( _p: BaseSettingsPage::get(
"Edit user account", "Edit user account",
user.deref(), user.deref(),
match edited_account.is_none() { match edited_account.is_none() {

View File

@ -11,8 +11,6 @@ use crate::controllers::base_controller::{FatalErrorPage, redirect_user};
use crate::data::remote_ip::RemoteIP; use crate::data::remote_ip::RemoteIP;
use crate::data::session_identity::{SessionIdentity, SessionStatus}; use crate::data::session_identity::{SessionIdentity, SessionStatus};
#[derive(Template)]
#[template(path = "login/base_login_page.html")]
struct BaseLoginPage { struct BaseLoginPage {
danger: String, danger: String,
success: String, success: String,
@ -24,14 +22,14 @@ struct BaseLoginPage {
#[derive(Template)] #[derive(Template)]
#[template(path = "login/login.html")] #[template(path = "login/login.html")]
struct LoginTemplate { struct LoginTemplate {
_parent: BaseLoginPage, _p: BaseLoginPage,
login: String, login: String,
} }
#[derive(Template)] #[derive(Template)]
#[template(path = "login/password_reset.html")] #[template(path = "login/password_reset.html")]
struct PasswordResetTemplate { struct PasswordResetTemplate {
_parent: BaseLoginPage, _p: BaseLoginPage,
min_pass_len: usize, min_pass_len: usize,
} }
@ -153,7 +151,7 @@ pub async fn login_route(
if SessionIdentity(&id).need_new_password() { if SessionIdentity(&id).need_new_password() {
return HttpResponse::Ok().content_type("text/html").body( return HttpResponse::Ok().content_type("text/html").body(
PasswordResetTemplate { PasswordResetTemplate {
_parent: BaseLoginPage { _p: BaseLoginPage {
page_title: "Password reset", page_title: "Password reset",
danger, danger,
success, success,
@ -169,7 +167,7 @@ pub async fn login_route(
HttpResponse::Ok().content_type("text/html").body( HttpResponse::Ok().content_type("text/html").body(
LoginTemplate { LoginTemplate {
_parent: BaseLoginPage { _p: BaseLoginPage {
page_title: "Login", page_title: "Login",
danger, danger,
success, success,

View File

@ -10,8 +10,6 @@ use crate::data::current_user::CurrentUser;
use crate::data::remote_ip::RemoteIP; use crate::data::remote_ip::RemoteIP;
use crate::data::user::User; use crate::data::user::User;
#[derive(Template)]
#[template(path = "settings/base_settings_page.html")]
pub(crate) struct BaseSettingsPage { pub(crate) struct BaseSettingsPage {
pub danger_message: Option<String>, pub danger_message: Option<String>,
pub success_message: Option<String>, pub success_message: Option<String>,
@ -38,18 +36,14 @@ impl BaseSettingsPage {
#[derive(Template)] #[derive(Template)]
#[template(path = "settings/account_details.html")] #[template(path = "settings/account_details.html")]
struct AccountDetailsPage { struct AccountDetailsPage {
_parent: BaseSettingsPage, _p: BaseSettingsPage,
user_id: String, u: User,
first_name: String,
last_name: String,
username: String,
email: String,
} }
#[derive(Template)] #[derive(Template)]
#[template(path = "settings/change_password.html")] #[template(path = "settings/change_password.html")]
struct ChangePasswordPage { struct ChangePasswordPage {
_parent: BaseSettingsPage, _p: BaseSettingsPage,
min_pwd_len: usize, min_pwd_len: usize,
} }
@ -58,12 +52,8 @@ pub async fn account_settings_details_route(user: CurrentUser) -> impl Responder
let user = user.into(); let user = user.into();
HttpResponse::Ok() HttpResponse::Ok()
.body(AccountDetailsPage { .body(AccountDetailsPage {
_parent: BaseSettingsPage::get("Account details", &user, None, None), _p: BaseSettingsPage::get("Account details", &user, None, None),
user_id: user.uid, u: user,
first_name: user.first_name,
last_name: user.last_name,
username: user.username,
email: user.email,
}.render().unwrap()) }.render().unwrap())
} }
@ -121,7 +111,7 @@ pub async fn change_password_route(user: CurrentUser,
HttpResponse::Ok() HttpResponse::Ok()
.body(ChangePasswordPage { .body(ChangePasswordPage {
_parent: BaseSettingsPage::get("Change password", &user, danger, success), _p: BaseSettingsPage::get("Change password", &user, danger, success),
min_pwd_len: MIN_PASS_LEN, min_pwd_len: MIN_PASS_LEN,
}.render().unwrap()) }.render().unwrap())
} }

View File

@ -4,7 +4,7 @@
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="Auth service"> <meta name="description" content="Auth service">
<title>{{ app_name }} - {{ page_title }}</title> <title>{{ _p.app_name }} - {{ _p.page_title }}</title>
<!-- Bootstrap core CSS --> <!-- Bootstrap core CSS -->
<link href="/assets/css/bootstrap.css" rel="stylesheet" crossorigin="anonymous"/> <link href="/assets/css/bootstrap.css" rel="stylesheet" crossorigin="anonymous"/>
@ -41,14 +41,14 @@
<main class="form-signin"> <main class="form-signin">
<h1 class="h3 mb-3 fw-normal">{{ page_title }}</h1> <h1 class="h3 mb-3 fw-normal">{{ _p.page_title }}</h1>
<div class="alert alert-danger" role="alert"> <div class="alert alert-danger" role="alert">
{{ danger }} {{ _p.danger }}
</div> </div>
<div class="alert alert-success" role="alert"> <div class="alert alert-success" role="alert">
{{ success }} {{ _p.success }}
</div> </div>
{% block content %} {% block content %}

View File

@ -1,6 +1,6 @@
{% extends "base_login_page.html" %} {% extends "base_login_page.html" %}
{% block content %} {% block content %}
<form action="/login?redirect={{ redirect_uri }}" method="post"> <form action="/login?redirect={{ _p.redirect_uri }}" method="post">
<div> <div>
<div class="form-floating"> <div class="form-floating">
<input name="login" type="text" required class="form-control" id="floatingName" placeholder="unsername" <input name="login" type="text" required class="form-control" id="floatingName" placeholder="unsername"

View File

@ -1,6 +1,6 @@
{% extends "base_login_page.html" %} {% extends "base_login_page.html" %}
{% block content %} {% block content %}
<form action="/login?redirect={{ redirect_uri }}" method="post" id="reset_password_form"> <form action="/login?redirect={{ _p.redirect_uri }}" method="post" id="reset_password_form">
<div> <div>
<p>You need to configure a new password:</p> <p>You need to configure a new password:</p>

View File

@ -5,27 +5,27 @@
<tbody> <tbody>
<tr> <tr>
<th scope="row">User ID</th> <th scope="row">User ID</th>
<td>{{ user_id }}</td> <td>{{ u.uid }}</td>
</tr> </tr>
<tr> <tr>
<th scope="row">First name</th> <th scope="row">First name</th>
<td>{{ first_name }}</td> <td>{{ u.first_name }}</td>
</tr> </tr>
<tr> <tr>
<th scope="row">Last name</th> <th scope="row">Last name</th>
<td>{{ last_name }}</td> <td>{{ u.last_name }}</td>
</tr> </tr>
<tr> <tr>
<th scope="row">Username</th> <th scope="row">Username</th>
<td>{{ username }}</td> <td>{{ u.username }}</td>
</tr> </tr>
<tr> <tr>
<th scope="row">Email</th> <th scope="row">Email</th>
<td>{{ email }}</td> <td>{{ u.email }}</td>
</tr> </tr>
<tr> <tr>
<th scope="row">Account type</th> <th scope="row">Account type</th>
<td>{% if is_admin %}Admin{% else %}Regular user{% endif %}</td> <td>{% if u.admin %}Admin{% else %}Regular user{% endif %}</td>
</tr> </tr>
</tbody> </tbody>
</table> </table>

View File

@ -2,7 +2,7 @@
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<title>{{ page_title }} - {{ app_name }}</title> <title>{{ _p.page_title }} - {{ _p.app_name }}</title>
<!-- Bootstrap core CSS --> <!-- Bootstrap core CSS -->
<link href="/assets/css/bootstrap.css" rel="stylesheet" crossorigin="anonymous"/> <link href="/assets/css/bootstrap.css" rel="stylesheet" crossorigin="anonymous"/>
@ -12,7 +12,7 @@
<body> <body>
<div class="d-flex flex-column flex-shrink-0 p-3 bg-light" style="width: 280px;"> <div class="d-flex flex-column flex-shrink-0 p-3 bg-light" style="width: 280px;">
<a href="/" class="d-flex align-items-center mb-3 mb-md-0 me-md-auto link-dark text-decoration-none"> <a href="/" class="d-flex align-items-center mb-3 mb-md-0 me-md-auto link-dark text-decoration-none">
<span class="fs-4">{{ app_name }}</span> <span class="fs-4">{{ _p.app_name }}</span>
</a> </a>
<hr> <hr>
<ul class="nav nav-pills flex-column mb-auto"> <ul class="nav nav-pills flex-column mb-auto">
@ -27,7 +27,7 @@
</a> </a>
</li> </li>
{% if is_admin %} {% if _p.is_admin %}
<hr/> <hr/>
<li> <li>
<a href="/admin/clients" class="nav-link link-dark"> <a href="/admin/clients" class="nav-link link-dark">
@ -46,7 +46,7 @@
<a href="#" class="d-flex align-items-center link-dark text-decoration-none dropdown-toggle" id="dropdownUser" <a href="#" class="d-flex align-items-center link-dark text-decoration-none dropdown-toggle" id="dropdownUser"
data-bs-toggle="dropdown" aria-expanded="false"> data-bs-toggle="dropdown" aria-expanded="false">
<img src="/assets/img/account.png" alt="" width="32" height="32" class="rounded-circle me-2"> <img src="/assets/img/account.png" alt="" width="32" height="32" class="rounded-circle me-2">
<strong>{{ user_name }}</strong> <strong>{{ _p.user_name }}</strong>
</a> </a>
<ul class="dropdown-menu text-small shadow" aria-labelledby="dropdownUser"> <ul class="dropdown-menu text-small shadow" aria-labelledby="dropdownUser">
<li><a class="dropdown-item" href="/logout">Sign out</a></li> <li><a class="dropdown-item" href="/logout">Sign out</a></li>
@ -55,14 +55,14 @@
</div> </div>
<div class="page_body" style="flex: 1"> <div class="page_body" style="flex: 1">
{% if let Some(msg) = danger_message %} {% if let Some(msg) = _p.danger_message %}
<div class="alert alert-danger">{{ msg }}</div> <div class="alert alert-danger">{{ msg }}</div>
{% endif %} {% endif %}
{% if let Some(msg) = success_message %} {% if let Some(msg) = _p.success_message %}
<div class="alert alert-success">{{ msg }}</div> <div class="alert alert-success">{{ msg }}</div>
{% endif %} {% endif %}
<h2 class="bd-title mt-0" style="margin-bottom: 40px;">{{ page_title }}</h2> <h2 class="bd-title mt-0" style="margin-bottom: 40px;">{{ _p.page_title }}</h2>
{% block content %} {% block content %}
TO_REPLACE TO_REPLACE

View File

@ -101,7 +101,7 @@
</div> </div>
</fieldset> </fieldset>
<input type="submit" class="btn btn-primary mt-4" value="{{ page_title }}"> <input type="submit" class="btn btn-primary mt-4" value="{{ _p.page_title }}">
</form> </form>
<script> <script>