Implement URL slugs (#931)

* Implement URL slugs for Users and Slots

* Fix extra spaces in slot slugs
This commit is contained in:
Josh 2023-10-29 15:30:43 -05:00 committed by GitHub
parent aea66b4a74
commit 1eb3bfa2ec
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 55 additions and 8 deletions

View file

@ -1,6 +1,7 @@
#nullable enable
using LBPUnion.ProjectLighthouse.Configuration;
using LBPUnion.ProjectLighthouse.Database;
using LBPUnion.ProjectLighthouse.Servers.Website.Extensions;
using LBPUnion.ProjectLighthouse.Servers.Website.Pages.Layouts;
using LBPUnion.ProjectLighthouse.Types.Entities.Interaction;
using LBPUnion.ProjectLighthouse.Types.Entities.Level;
@ -38,11 +39,17 @@ public class UserPage : BaseLayout
public UserPage(DatabaseContext database) : base(database)
{ }
public async Task<IActionResult> OnGet([FromRoute] int userId)
public async Task<IActionResult> OnGet([FromRoute] int userId, string? slug)
{
this.ProfileUser = await this.Database.Users.FirstOrDefaultAsync(u => u.UserId == userId);
if (this.ProfileUser == null) return this.NotFound();
string userSlug = this.ProfileUser.GenerateSlug();
if (slug == null || userSlug != slug)
{
return this.Redirect($"~/user/{userId}/{userSlug}");
}
bool isAuthenticated = this.User != null;
bool isOwner = this.ProfileUser == this.User || this.User != null && this.User.IsModerator;