Skip to content

Commit

Permalink
First draft of redirecting server-side
Browse files Browse the repository at this point in the history
WIP. Not yet tested, probably not yet functional.
  • Loading branch information
rmunn committed Sep 25, 2024
1 parent ca53296 commit 5b820df
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions backend/LexBoxApi/Controllers/UserController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,38 @@ await HttpContext.SignInAsync(user.GetPrincipal("Registration"),
return Ok(user);
}

[HttpGet("inviteLinkRedirect")]
[RequireAudience(LexboxAudience.RegisterAccount, true)]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
public async Task<ActionResult<LexAuthUser>> InviteLinkRedirect(LoggedInContext loggedInContext, LexBoxDbContext dbContext)
{
var user = loggedInContext.User;
if (user.Email is null)
{
return Redirect("/login");
}
var queryString = QueryString.Create("email", user.Email);
var returnTo = new UriBuilder { Path = "/acceptInvitation", Query = queryString.Value }.Uri.PathAndQuery;
var dbUser = await dbContext.Users
.Where(u => u.Email == user.Email)
.Include(u => u.Projects)
.Include(u => u.Organizations)
.FirstOrDefaultAsync();
if (dbUser is null)
{
return Redirect(returnTo);
}
else
{
UpdateUserMemberships(user, dbUser);
await dbContext.SaveChangesAsync();
await HttpContext.SignInAsync(user.GetPrincipal("Registration"),
new AuthenticationProperties { IsPersistent = true });
return Ok(user);
}
}

[HttpPost("acceptInvitation")]
[RequireAudience(LexboxAudience.RegisterAccount, true)]
[ProducesResponseType(StatusCodes.Status200OK)]
Expand Down

0 comments on commit 5b820df

Please sign in to comment.