Skip to content

Commit

Permalink
fix: username
Browse files Browse the repository at this point in the history
  • Loading branch information
DonWick32 committed Feb 22, 2024
1 parent 5160d98 commit 7a1a005
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 14 deletions.
13 changes: 1 addition & 12 deletions src/api/defense/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ use crate::{api::util::GameHistoryResponse, error::DieselError};
use anyhow::{Ok, Result};
use diesel::dsl::exists;
use diesel::{prelude::*, select};
use rand::distributions::Alphanumeric;
use rand::Rng;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
Expand Down Expand Up @@ -939,17 +938,7 @@ pub fn add_user_default_base(
conn.transaction(|conn| {
use crate::schema::{artifact, available_blocks, map_layout, map_spaces, user};

let random_string: String = rand::thread_rng()
.sample_iter(&Alphanumeric)
.take(4)
.map(char::from)
.collect();

let username = &format!(
"{}_{}",
user_email.split('@').next().unwrap(),
random_string
);
let username = user_email.split('@').next().unwrap();
let new_user = NewUser {
name: user_name,
email: user_email,
Expand Down
4 changes: 2 additions & 2 deletions src/api/user/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ async fn update_user(
let user_id = user.0;
let username = user_details.username.clone();
if username.is_some()
&& (username.as_ref().unwrap().len() < 5 || username.as_ref().unwrap().len() > 30)
&& (username.as_ref().unwrap().len() < 5 || username.as_ref().unwrap().len() > 15)
{
return Err(ErrorBadRequest(
"Username should contain atleast 5 characters and atmost 30 characters",
"Username should contain atleast 5 characters and atmost 15 characters",
));
}
if let Some(username) = username {
Expand Down

0 comments on commit 7a1a005

Please sign in to comment.