Skip to content

Commit

Permalink
Fix location dependency on auth checks
Browse files Browse the repository at this point in the history
  • Loading branch information
SSchulze1989 committed May 22, 2024
1 parent d5bebf4 commit cb44fab
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/iRLeagueApiCore.Server/Controllers/AuthenticateController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using Microsoft.IdentityModel.Tokens;
using System.Globalization;
using System.IdentityModel.Tokens.Jwt;
using System.Security.Claims;
using System.Text;
using System.Text.Json;

namespace iRLeagueApiCore.Server.Controllers;

Expand Down Expand Up @@ -170,10 +170,10 @@ public async Task<IActionResult> Register([FromBody] RegisterModel model, [FromQ
linkTemplate = $$"""{{baseUri}}/users/{userId}/confirm/{token}""";
}
var request = new RegisterUserRequest(model, linkTemplate);
var status = await mediator.Send(request);
if (status.result.Succeeded)
var (user, result) = await mediator.Send(request);
if (result.Succeeded)
{
return CreatedAtAction(nameof(UsersController.GetUser), "Users", new { id = status.user.UserId }, status.user);
return CreatedAtAction(nameof(UsersController.GetUser), "Users", new { id = user.UserId }, user);
}
return StatusCode(StatusCodes.Status500InternalServerError, new Response { Status = "Error", Message = "User creation failed! Please check user details and try again." });
}
Expand Down Expand Up @@ -216,13 +216,13 @@ public async Task<ActionResult> ResetPasswordWithToken([FromRoute] string userId
foreach(var login in logins)
{
var (id, exp) = DecodeLoginKey(login.ProviderKey);
if (exp <= DateTime.Now)
if (exp <= DateTime.UtcNow)
{
await userManager.RemoveLoginAsync(user, "iRLeagueApiCore", login.ProviderKey);
}
}

var expiration = DateTime.Now.AddMonths(3);
var expiration = DateTime.UtcNow.AddMonths(3);
var loginKey = GenerateLoginkey(expiration);
var loginInfo = new UserLoginInfo("iRLeagueApiCore", loginKey, "iRLeagueApiCore");
var result = await userManager.AddLoginAsync(user, loginInfo);
Expand Down Expand Up @@ -264,7 +264,7 @@ private static string GenerateLoginkey(DateTime expiration)

var parts = keyString.Split('&');
var id = parts.ElementAtOrDefault(0) ?? throw new InvalidOperationException();
if (DateTime.TryParse(parts.ElementAtOrDefault(1), out DateTime expiration) == false)
if (DateTime.TryParse(parts.ElementAtOrDefault(1), CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal, out DateTime expiration) == false)
{
throw new InvalidOperationException();
}
Expand Down

0 comments on commit cb44fab

Please sign in to comment.