For now? I'm experimenting on an old concept.
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat: make possible to log in to dev accounts now

+72 -21
+72 -21
server/src/main.rs
··· 30 30 use crate::errors::LuminaError; 31 31 use cynthia_con::{CynthiaColors, CynthiaStyles}; 32 32 use dotenv::dotenv; 33 + use rocket::futures::TryFutureExt; 33 34 34 35 fn config_get() -> Result<ServerConfig, LuminaError> { 35 36 let addr = { ··· 160 161 .unwrap_or_default(); 161 162 if global.1 == 0 { 162 163 println!( 163 - "Debug mode: Inserting Hello World post by local user with zero UUID if not exists." 164 + "Debug mode: Inserting Hello World post and two test users if not exists." 164 165 ); 165 166 166 167 let generated_uuid = Uuid::new_v4(); 167 - let generated_uuid_str = generated_uuid.to_string(); 168 168 let hello_content = "Hello world"; 169 - let author_id = "00000000-0000-0000-0000-000000000000"; 169 + 170 170 match db.recreate().await.unwrap() { 171 171 DbConn::PgsqlConnection((client, _), _) => { 172 172 // Insert Hello World post and timeline entry if not exists 173 + let user_1_: Result<user::User, LuminaError> = 174 + match user::User::create_user( 175 + String::from("test@lumina123.co"), 176 + String::from("testuser1"), 177 + String::from("MyTestPassw9292!"), 178 + &db, 179 + ) 180 + .await 181 + { 182 + Ok(a) => Ok(a), 183 + // But if a user exists, we just pass the user. 184 + Err(LuminaError::RegisterUsernameInUse) 185 + | Err(LuminaError::RegisterEmailInUse) => { 186 + user::User::get_user_by_identifier( 187 + String::from("testuser1"), 188 + &db, 189 + ) 190 + .await 191 + } 192 + Err(e) => Err(e), 193 + }; 173 194 174 - let _ = client 175 - .execute( 176 - "INSERT INTO users (id, email, username, password) VALUES ($1, $2, $3, $4) ON CONFLICT (id) DO NOTHING", 177 - &[&author_id, &"local@localhost", &"localuser", &"debugpassword"], 178 - ) 179 - .await; 180 - let _ = client 181 - .execute( 182 - "INSERT INTO post_text (id, author_id, content, created_at) VALUES ($1, $2, $3, CURRENT_TIMESTAMP) ON CONFLICT (id) DO NOTHING", 183 - &[&generated_uuid, &author_id, &hello_content], 184 - ) 185 - .await; 186 - let add_clone = ev_log.clone().await; 187 - timeline::add_to_timeline( 188 - add_clone, 195 + let user_2_ = match user::User::create_user( 196 + String::from("test@lumina234.co"), 197 + String::from("testuser2"), 198 + String::from("MyTestPassw9292!"), 189 199 &db, 190 - "00000000-0000-0000-0000-000000000000", 191 - &generated_uuid_str.as_str(), 192 200 ) 193 201 .await 194 - .unwrap_or(()); 202 + { 203 + Ok(a) => Ok(a), 204 + // But if a user exists, we just pass the user. 205 + Err(LuminaError::RegisterUsernameInUse) 206 + | Err(LuminaError::RegisterEmailInUse) => { 207 + user::User::get_user_by_identifier( 208 + String::from("testuser2"), 209 + &db, 210 + ) 211 + .await 212 + } 213 + Err(e) => Err(e), 214 + }; 215 + 216 + match (user_1_, user_2_) { 217 + (Ok(user_1), Ok(user_2)) => { 218 + println!( 219 + "Created two users with password 'MyTestPassw9292!' and usernames 'testuser1' and 'testuser2'." 220 + ); 221 + let _ = client 222 + .execute( 223 + "INSERT INTO post_text (id, author_id, content, created_at) VALUES ($1, $2, $3, CURRENT_TIMESTAMP) ON CONFLICT (id) DO NOTHING", 224 + &[&generated_uuid, &user_1.id, &hello_content], 225 + ) 226 + .await; 227 + let add_clone = ev_log.clone().await; 228 + timeline::add_to_timeline( 229 + add_clone, 230 + &db, 231 + "00000000-0000-0000-0000-000000000000", 232 + &generated_uuid.to_string().as_str(), 233 + ) 234 + .await 235 + .unwrap_or(()); 236 + () 237 + } 238 + z => { 239 + println!( 240 + "Ran into some issues: user 1: {:?}, user 2: {:?} ", 241 + z.0, z.1 242 + ); 243 + () 244 + } 245 + } 195 246 } 196 247 } 197 248 }