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)]
#[template(path = "settings/clients_list.html")]
struct ClientsListTemplate {
_parent: BaseSettingsPage,
_p: BaseSettingsPage,
clients: Vec<Client>,
}
#[derive(Template)]
#[template(path = "settings/users_list.html")]
struct UsersListTemplate {
_parent: BaseSettingsPage,
_p: BaseSettingsPage,
users: Vec<User>,
}
#[derive(Template)]
#[template(path = "settings/edit_user.html")]
struct EditUserTemplate {
_parent: BaseSettingsPage,
_p: BaseSettingsPage,
u: User,
clients: Vec<Client>,
}
@ -38,7 +38,7 @@ struct EditUserTemplate {
pub async fn clients_route(user: CurrentUser, clients: web::Data<ClientManager>) -> impl Responder {
HttpResponse::Ok().body(ClientsListTemplate {
_parent: BaseSettingsPage::get(
_p: BaseSettingsPage::get(
"Clients list",
&user,
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;
HttpResponse::Ok().body(UsersListTemplate {
_parent: BaseSettingsPage::get(
_p: BaseSettingsPage::get(
"Users list",
&user,
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 {
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(),
clients: clients.cloned(),
}.render().unwrap())
@ -155,7 +155,7 @@ pub async fn edit_user(user: CurrentUser,
HttpResponse::Ok().body(EditUserTemplate {
_parent: BaseSettingsPage::get(
_p: BaseSettingsPage::get(
"Edit user account",
user.deref(),
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::session_identity::{SessionIdentity, SessionStatus};
#[derive(Template)]
#[template(path = "login/base_login_page.html")]
struct BaseLoginPage {
danger: String,
success: String,
@ -24,14 +22,14 @@ struct BaseLoginPage {
#[derive(Template)]
#[template(path = "login/login.html")]
struct LoginTemplate {
_parent: BaseLoginPage,
_p: BaseLoginPage,
login: String,
}
#[derive(Template)]
#[template(path = "login/password_reset.html")]
struct PasswordResetTemplate {
_parent: BaseLoginPage,
_p: BaseLoginPage,
min_pass_len: usize,
}
@ -141,7 +139,7 @@ pub async fn login_route(
}
c => {
log::warn!("Failed login for ip {:?} / username {}: {:?}", remote_ip, login, c);
log::warn!("Failed login for ip {:?} / username {}: {:?}", remote_ip, login, c);
danger = "Login failed.".to_string();
bruteforce.send(bruteforce_actor::RecordFailedAttempt { ip: remote_ip.into() }).await.unwrap();
@ -153,7 +151,7 @@ pub async fn login_route(
if SessionIdentity(&id).need_new_password() {
return HttpResponse::Ok().content_type("text/html").body(
PasswordResetTemplate {
_parent: BaseLoginPage {
_p: BaseLoginPage {
page_title: "Password reset",
danger,
success,
@ -169,7 +167,7 @@ pub async fn login_route(
HttpResponse::Ok().content_type("text/html").body(
LoginTemplate {
_parent: BaseLoginPage {
_p: BaseLoginPage {
page_title: "Login",
danger,
success,

View File

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

View File

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

View File

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

View File

@ -1,6 +1,6 @@
{% extends "base_login_page.html" %}
{% 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>
<p>You need to configure a new password:</p>

View File

@ -5,27 +5,27 @@
<tbody>
<tr>
<th scope="row">User ID</th>
<td>{{ user_id }}</td>
<td>{{ u.uid }}</td>
</tr>
<tr>
<th scope="row">First name</th>
<td>{{ first_name }}</td>
<td>{{ u.first_name }}</td>
</tr>
<tr>
<th scope="row">Last name</th>
<td>{{ last_name }}</td>
<td>{{ u.last_name }}</td>
</tr>
<tr>
<th scope="row">Username</th>
<td>{{ username }}</td>
<td>{{ u.username }}</td>
</tr>
<tr>
<th scope="row">Email</th>
<td>{{ email }}</td>
<td>{{ u.email }}</td>
</tr>
<tr>
<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>
</tbody>
</table>

View File

@ -2,7 +2,7 @@
<html lang="en">
<head>
<meta charset="UTF-8">
<title>{{ page_title }} - {{ app_name }}</title>
<title>{{ _p.page_title }} - {{ _p.app_name }}</title>
<!-- Bootstrap core CSS -->
<link href="/assets/css/bootstrap.css" rel="stylesheet" crossorigin="anonymous"/>
@ -12,7 +12,7 @@
<body>
<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">
<span class="fs-4">{{ app_name }}</span>
<span class="fs-4">{{ _p.app_name }}</span>
</a>
<hr>
<ul class="nav nav-pills flex-column mb-auto">
@ -27,7 +27,7 @@
</a>
</li>
{% if is_admin %}
{% if _p.is_admin %}
<hr/>
<li>
<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"
data-bs-toggle="dropdown" aria-expanded="false">
<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>
<ul class="dropdown-menu text-small shadow" aria-labelledby="dropdownUser">
<li><a class="dropdown-item" href="/logout">Sign out</a></li>
@ -55,14 +55,14 @@
</div>
<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>
{% endif %}
{% if let Some(msg) = success_message %}
{% if let Some(msg) = _p.success_message %}
<div class="alert alert-success">{{ msg }}</div>
{% 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 %}
TO_REPLACE

View File

@ -101,7 +101,7 @@
</div>
</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>
<script>