···3030# Added by cargo
31313232/target
3333+# Added by me
3334/client/priv/static/lumina_client*.css
3435/client/priv/static/lumina_client*.mjs
3636+instance.sqlite
3737+.env
+64-10
server/src/client_communication.rs
···11-use crate::AppState;
21use crate::user::User;
22+use crate::{AppState, LuminaError};
33use cynthia_con::CynthiaColors;
44extern crate rocket;
55use rocket::State;
66+use tracing::info;
67use ws;
7889#[get("/connection")]
···1617 user: None,
1718 };
1819 while let Some(message) = stream.next().await {
1919- println!("Received message: {:?}", message);
2020 match message? {
2121 ws::Message::Text(msg) => {
2222 match msg.as_str() {
···3737 username,
3838 password,
3939 }) => {
4040+ println!(
4141+ "Register request: {} {}",
4242+ email.clone().color_orange(),
4343+ username.clone().color_bright_cyan()
4444+ );
4545+4046 // register the user
4147 {
4248 let appstate = state.0.clone();
4349 let db = &appstate.1.lock().await;
4444- match User::create_user(email, username, password, db).await
5050+ match User::create_user(email.clone(), username.clone(), password, db).await
4551 {
4652 Ok(user) => {
5353+ info!(
5454+ "User created: {}",
5555+ user.clone().username.color_bright_cyan()
5656+ );
4757 match User::create_session_token(user, db).await {
4858 Ok((token, user)) => {
4959 client_session_data.user =
···5767 )))
5868 .await;
5969 }
6060- Err(_e) => {
7070+ Err(e) => {
7171+ match e {
7272+ LuminaError::Postgres(e) =>
7373+ error!("Error creating session token: {:?}", e),
7474+7575+ LuminaError::SqlitePool(e) =>
7676+ warn!("Error creating session token: {:?}", e)
7777+ ,
7878+ _ => {}
7979+ }
8080+6181 // I would return a more specific error message
6282 // to the client here, but if the server knows the
6383 // error, the client should know the error twice as
···7292 }
7393 }
74947575- Err(_e) => {
9595+ Err(e) => {
9696+ match e {
9797+ LuminaError::RegisterUsernameInUse => {
9898+ warn!(
9999+ "{} User {} already exists",
100100+ "[RegistrationError]"
101101+ .color_bright_red(),
102102+ username.clone().color_bright_cyan()
103103+ );
104104+ }
105105+ LuminaError::RegisterEmailNotValid => {
106106+ warn!(
107107+ "{} Email {} is not valid",
108108+ "[RegistrationError]"
109109+ .color_bright_red(),
110110+ email.clone().color_bright_cyan()
111111+ );
112112+ }
113113+ LuminaError::RegisterUsernameInvalid(why) => {
114114+ warn!(
115115+ "{} Username {} is not valid: {}",
116116+ "[RegistrationError]"
117117+ .color_bright_red(),
118118+ username.clone().color_bright_cyan(),
119119+ why
120120+ );
121121+ }
122122+ LuminaError::RegisterPasswordNotValid(why) => {
123123+ warn!(
124124+ "{} Password is not valid: {}",
125125+ "[RegistrationError]".color_bright_red(),
126126+ why
127127+ );
128128+ }
129129+ _ => {}
130130+ }
131131+76132 // I would return a more specific error message
77133 // to the client here, but if the server knows the
78134 // error, the client should know the error twice as
···90146 }
91147 Ok(jsonmsg) => {
92148 let _ = stream.send(ws::Message::from("unknown")).await;
9393- eprintln!(
9494- "todo: {}",
9595- format!("Handle message: {:?}", jsonmsg).color_error_red()
9696- );
149149+ todo!("Handle message: {:?}", jsonmsg);
97150 }
9898- Err(_e) => {
151151+ Err(e) => {
152152+ error!("Error deserialising message: {:?}", e);
99153 let _ = stream.send(ws::Message::from("unknown")).await;
100154 }
101155 },