be more explicit
This commit is contained in:
parent
1daec80430
commit
b924819211
2 changed files with 49 additions and 44 deletions
52
src/main.rs
52
src/main.rs
|
@ -1,21 +1,23 @@
|
|||
use std::{
|
||||
fmt::{Debug, Display},
|
||||
net::SocketAddr,
|
||||
};
|
||||
use std::net::SocketAddr;
|
||||
|
||||
use axum::{routing::get, Router};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use tower_http::services::ServeDir;
|
||||
use tower_sessions::{MemoryStore, SessionManagerLayer};
|
||||
|
||||
// "extern crate" is this olde-timey way to bring macros into the current live
|
||||
// namespace; I'm not sure why it's needed here; we're using this to allow to do
|
||||
// like such as #[derive(Error)] before a struct or enum.
|
||||
#[macro_use]
|
||||
extern crate justerror;
|
||||
|
||||
mod handlers;
|
||||
use handlers::*;
|
||||
use handlers::{get_signup, post_signup, signup_success};
|
||||
|
||||
mod templates;
|
||||
|
||||
mod user;
|
||||
use user::User;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
let session_store = MemoryStore::default();
|
||||
|
@ -36,41 +38,3 @@ async fn main() {
|
|||
.await
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, Serialize, Deserialize, Default)]
|
||||
pub struct User {
|
||||
pub username: String,
|
||||
pub displayname: Option<String>,
|
||||
pub email: String,
|
||||
pub password: String,
|
||||
pub pw_verify: String,
|
||||
}
|
||||
|
||||
impl Debug for User {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
let pw_check = if self.password == self.pw_verify {
|
||||
"password matched"
|
||||
} else {
|
||||
"PASSWORD MISMATCH"
|
||||
};
|
||||
f.debug_struct("User")
|
||||
.field("username", &self.username)
|
||||
.field("displayname", &self.displayname)
|
||||
.field("email", &self.email)
|
||||
.field("pw-check", &pw_check)
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for User {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
let uname = &self.username;
|
||||
let dname = if let Some(ref n) = self.displayname {
|
||||
n
|
||||
} else {
|
||||
""
|
||||
};
|
||||
let email = &self.email;
|
||||
write!(f, "Username: {uname}\nDisplayname: {dname}\nEmail: {email}")
|
||||
}
|
||||
}
|
||||
|
|
41
src/user.rs
Normal file
41
src/user.rs
Normal file
|
@ -0,0 +1,41 @@
|
|||
use std::fmt::{Debug, Display};
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, Serialize, Deserialize, Default)]
|
||||
pub struct User {
|
||||
pub username: String,
|
||||
pub displayname: Option<String>,
|
||||
pub email: String,
|
||||
pub password: String,
|
||||
pub pw_verify: String,
|
||||
}
|
||||
|
||||
impl Debug for User {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
let pw_check = if self.password == self.pw_verify {
|
||||
"password matched"
|
||||
} else {
|
||||
"PASSWORD MISMATCH"
|
||||
};
|
||||
f.debug_struct("User")
|
||||
.field("username", &self.username)
|
||||
.field("displayname", &self.displayname)
|
||||
.field("email", &self.email)
|
||||
.field("pw-check", &pw_check)
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for User {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
let uname = &self.username;
|
||||
let dname = if let Some(ref n) = self.displayname {
|
||||
n
|
||||
} else {
|
||||
""
|
||||
};
|
||||
let email = &self.email;
|
||||
write!(f, "Username: {uname}\nDisplayname: {dname}\nEmail: {email}")
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue