Skip to content

Commit

Permalink
Remove old code
Browse files Browse the repository at this point in the history
  • Loading branch information
RiadGahlouz committed Jan 23, 2024
1 parent fb21e0e commit 44b0ccf
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,16 @@ public ActionResult ValidateNewUsername(string newUsername, bool checkOwnedPacka
return Json(HttpStatusCode.BadRequest, "Username cannot be null or empty.", JsonRequestBehavior.AllowGet);
}

var result = CheckUserExist(newUsername);
var oldAccount = _userService.FindByUsername(oldUsername);
if (oldAccount == null)
{
return Json(HttpStatusCode.NotFound, "Old username account was not found.", JsonRequestBehavior.AllowGet);
}

var result = ValidateUsernameChange(oldAccount, newUsername);

if (checkOwnedPackages)
{
var oldAccount = _userService.FindByUsername(oldUsername);
if(oldAccount == null)
{
return Json(HttpStatusCode.NotFound, "Old username account was not found.", JsonRequestBehavior.AllowGet);
}

var ownedPackages = _packageService.FindPackagesByOwner(oldAccount, includeUnlisted: true)
.Where(p => p.PackageStatusKey != PackageStatus.Deleted)
.Select(p => p.PackageRegistration.Id);
Expand Down Expand Up @@ -163,14 +163,6 @@ public async Task<ActionResult> ChangeUsername(string oldUsername, string newUse
return Json(HttpStatusCode.OK, "Account renamed successfully!", JsonRequestBehavior.AllowGet);
}

private ValidateUsernameResult CheckUserExist(string username) {
return new ValidateUsernameResult()
{
IsFormatValid = UsernameValidationRegex.IsMatch(username),
IsAvailable = _userService.FindByUsername(username, includeDeleted: true) == null
};
}

private ValidateUsernameResult ValidateUsernameChange(User requestor, string username)
{
var foundUser = _userService.FindByUsername(username, includeDeleted: true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@

<i>Validate if the new username is available and has a valid format.</i><br />

<input type="text" placeholder="Old Username" autocomplete="off" autofocus style="width: 200px;" rows="1" data-bind="value: oldUsername" />
<input type="text" placeholder="New username" autocomplete="off" autofocus style="width: 200px;" rows="1" data-bind="value: newUsername" />
<input type="text" placeholder="Old Username" autocomplete="off" autofocus style="width: 200px;" rows="1" data-bind="visible: checkOwnedPackages, value: oldUsername" />
<input type="checkbox" id="checkNonDeletedOwnedPackages" data-bind="checked: checkOwnedPackages" />
<label for="checkNonDeletedOwnedPackages">Check Non-Deleted Owned Packages</label>
<button type="submit" data-bind="click: validateNewUsername">Validate</button>
Expand Down

0 comments on commit 44b0ccf

Please sign in to comment.