what2watch/src/templates.rs

83 lines
2.2 KiB
Rust
Raw Normal View History

use askama::Template;
use optional_optional_user::OptionalOptionalUser;
2023-05-28 19:20:55 +00:00
use serde::{Deserialize, Serialize};
use crate::User;
#[derive(Debug, Default, Template, Deserialize, Serialize, PartialEq, Eq, OptionalOptionalUser)]
2023-05-17 20:40:06 +00:00
#[template(path = "signup.html")]
pub struct CreateUser {
pub username: String,
pub displayname: Option<String>,
pub email: Option<String>,
pub password: String,
pub pw_verify: String,
}
2023-05-28 19:20:55 +00:00
#[derive(
Debug, Clone, Template, Default, Deserialize, Serialize, PartialEq, Eq, OptionalOptionalUser,
)]
2023-06-03 22:45:19 +00:00
#[template(path = "signup_success.html")]
pub struct CreateUserSuccess(pub User);
2023-06-03 22:45:19 +00:00
2023-06-02 21:15:13 +00:00
#[derive(Debug, Default, Template, Deserialize, Serialize, PartialEq, Eq)]
2023-05-28 19:20:55 +00:00
#[template(path = "login_post.html")]
pub struct LoginPost {
pub username: String,
pub password: String,
}
#[derive(Debug, Default, Template, Deserialize, Serialize, PartialEq, Eq, OptionalOptionalUser)]
2023-05-28 19:20:55 +00:00
#[template(path = "login_get.html")]
pub struct LoginGet {
pub username: String,
pub password: String,
}
#[derive(Debug, Default, Template, Deserialize, Serialize, PartialEq, Eq, OptionalOptionalUser)]
#[template(path = "logout_get.html")]
pub struct LogoutGet;
#[derive(Debug, Default, Template, Deserialize, Serialize, PartialEq, Eq, OptionalOptionalUser)]
#[template(path = "logout_post.html")]
pub struct LogoutPost;
#[derive(Debug, Default, Template, Deserialize, Serialize, PartialEq, Eq, OptionalOptionalUser)]
#[template(path = "index.html")]
pub struct MainPage {
pub user: Option<User>,
}
#[cfg(test)]
mod test {
use super::*;
#[test]
fn main_page_has_optional_user() {
assert!(MainPage::default().has_optional_user());
}
#[test]
fn signup_success_has_no_optional_user() {
assert!(!CreateUserSuccess::default().has_optional_user());
2023-06-13 19:34:54 +00:00
}
#[test]
fn user_is_not_optional() {
#[derive(Default, OptionalOptionalUser)]
struct TestThing {
user: User,
}
assert!(!TestThing::default().has_optional_user());
}
#[test]
fn user_is_not_user() {
#[derive(Default, OptionalOptionalUser)]
struct TestThing {
user: Option<bool>,
}
assert!(!TestThing::default().has_optional_user());
}
2023-06-13 19:34:54 +00:00
}