Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
GitHub committed Mar 28, 2023
1 parent 5107687 commit 7b83de1
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/controller/user.rs
Expand Up @@ -2,8 +2,8 @@

use super::{
db_utils::{
generate_nanoid_ttl, get_count, get_count_by_prefix, get_range, set_one, set_one_with_key,
IterType,
generate_nanoid_ttl, get_count, get_count_by_prefix, get_range, ivec_to_u32, set_one,
set_one_with_key, IterType,
},
fmt::ts_to_date,
get_ids_by_prefix, get_one, incr_id, into_response,
Expand Down Expand Up @@ -705,6 +705,12 @@ pub(crate) async fn user_setting_post(
}

let tree = db.open_tree("usernames")?;
if let Some(v) = tree.get(&input.username)? {
if ivec_to_u32(&v) != claim.uid {
return Err(AppError::NameExists);
}
}

if user.username != input.username {
tree.remove(&user.username)?;
tree.insert(&input.username, u32_to_ivec(user.uid))?;
Expand Down

0 comments on commit 7b83de1

Please sign in to comment.