Skip to content

Commit

Permalink
🔧 Changed displayname requirements
Browse files Browse the repository at this point in the history
  • Loading branch information
anditv21 committed Jul 20, 2023
1 parent 81a7fcd commit 54ac259
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
16 changes: 13 additions & 3 deletions src/app/models/UsersModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -747,8 +747,8 @@ protected function set_new_display_name($display_name, $username)
// Check if 30 days have passed since the last username change
$this->prepare("SELECT `username_change` FROM `users` WHERE `username` = ?");
$this->statement->execute([$username]);
$result = $this->statement->fetch();
$result = $this->statement->fetch();

if ($result && $result->username_change) {
$last_username_change = strtotime($result->username_change);
$thirty_days_ago = strtotime("-30 days");
Expand All @@ -758,13 +758,23 @@ protected function set_new_display_name($display_name, $username)
return false;
}
}


// Validate display name on length (4-14 characters)
if (empty($display_name)) {
return false;
} elseif (strlen($display_name) < 4 || strlen($display_name) > 14) {
return false;
}

// Update the display name and set the username_change date
$this->prepare("UPDATE `users` SET `displayname` = ?, `username_change` = DATE_ADD(NOW(), INTERVAL 30 DAY) WHERE `username` = ?");
$this->statement->execute([$display_name, $username]);

return true;
}



protected function get_current_name_cooldown($username)
{
$this->prepare("SELECT `username_change` FROM `users` WHERE `username` = ?");
Expand Down
4 changes: 2 additions & 2 deletions src/user/profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@

<?php if ($days_left > 0) : ?>
<div class="form-group">
<input disabled="disabled" autocomplete="off" class="form-control form-control-sm" placeholder="Display name" name="display_name" required>
<input disabled="disabled" autocomplete="off" class="form-control form-control-sm" minlength="4" maxlength="14" placeholder="Display name" name="display_name" required>
</div>

<button class="btn btn-outline-primary btn-block" disabled="disabled">
Expand All @@ -263,7 +263,7 @@
<?php
else : ?>
<div class="form-group">
<input autocomplete="off" class="form-control form-control-sm" placeholder="Display name" name="display_name" required>
<input autocomplete="off" class="form-control form-control-sm" minlength="4" maxlength="14" placeholder="Display name" name="display_name" required>
</div>

<button class="btn btn-outline-primary btn-block" onclick="return confirm('WARNING: You can change your display name only once every 30 days. Are you sure you want to continue?');" name="change_display_name" type="submit" value="submit">
Expand Down

0 comments on commit 54ac259

Please sign in to comment.