Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -108,38 +108,26 @@ public static IEndpointRouteBuilder MapAdditionalIdentityEndpoints(this IEndpoin
if (context.User.Identity?.Name != null)
currentUser = await userManager.FindByNameAsync(context.User.Identity.Name);

if (currentUser != null)
{
if (logoutHandler != null)
{
string ipAddress = GetClientIpAddress(context);
await logoutHandler(currentUser.UserName!, ipAddress);
}
await signInManager.SignOutAsync();
}

// Find user by hashed external auth ID
var users = userManager.Users.Where(u => TokenHasher.VerifyToken(externalAuthId, u.ExternalAuthId)).ToList();
if (!users.Any() || users.Count > 1)
return TypedResults.LocalRedirect(string.IsNullOrEmpty(returnUrl) ? "/" : !returnUrl.StartsWith("/") ? "/" + returnUrl : returnUrl.StartsWith("//") ? "/" + returnUrl.TrimStart('/') : returnUrl);

var user = users.First();

if (currentUser != null)
{
// User is already logged in
if (TokenHasher.VerifyToken(externalAuthId, currentUser.ExternalAuthId))
{
// Same user - log out
if (logoutHandler != null)
{
string ipAddress = GetClientIpAddress(context);
await logoutHandler(currentUser.UserName!, ipAddress);
}
await signInManager.SignOutAsync();
if (currentUser != null) // User is already logged in
if (TokenHasher.VerifyToken(externalAuthId, currentUser.ExternalAuthId)) // Same user - only log out
return TypedResults.LocalRedirect(string.IsNullOrEmpty(returnUrl) ? "/" : !returnUrl.StartsWith("/") ? "/" + returnUrl : returnUrl.StartsWith("//") ? "/" + returnUrl.TrimStart('/') : returnUrl);
}
else
{
// Different user - log out current and log in new
if (logoutHandler != null)
{
string ipAddress = GetClientIpAddress(context);
await logoutHandler(currentUser.UserName!, ipAddress);
}
await signInManager.SignOutAsync();
}
}

// Sign in the user
await signInManager.SignInAsync(user, isPersistent: false);
Expand Down
10 changes: 9 additions & 1 deletion src/Security/src/AXOpen.Security/Services/SerialService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,15 @@ public async Task<bool> OpenPortAsync(int baudRate, bool onlyPreviouslyAuthorize

if(_module == null)
_module = await _jsRuntime.InvokeAsync<IJSObjectReference>("import", "./_content/AXOpen.Security.Blazor/js/SerialCommunication.js");
int operationStatus = await _module.InvokeAsync<int>("openPortAsync", _selfRef, onlyPreviouslyAuthorizedPort, baudRate, 512, dataBits, flowControlString, parityString, stopBits);

int operationStatus = 0;
try
{
operationStatus = await _module.InvokeAsync<int>("openPortAsync", _selfRef, onlyPreviouslyAuthorizedPort, baudRate, 512, dataBits, flowControlString, parityString, stopBits);
}
catch (Exception ex)
{
}

switch (operationStatus)
{
Expand Down
Loading