public async Task <LoginResult> Login(string user, string password, string hubName, CancellationToken cancellationToken) { try { if (ModelState.IsValid) { var applicationUser = await _operations.RepositoryManager.GetUserFromLoginAsync(user, cancellationToken); if (applicationUser == null) { _logger.LogWarning("Invalid remote login attempt using Email: " + User); throw new ReaderControllerException( "Login failed due to invalid user/password or an an invalid account."); } var result = await _signInManager.PasswordSignInAsync(applicationUser, password, false, lockoutOnFailure : false); if (result.Succeeded) { if (string.IsNullOrEmpty(hubName)) { return(new LoginResult() { Success = true }); } else { var hub = await IsAuthorizedHub(hubName, applicationUser, cancellationToken); var remoteAgent = await _remoteAgents.GetHubReaderRemoteAgent(hub.HubKey, _operations.RepositoryManager, cancellationToken); return(new LoginResult() { Success = true, ActiveAgent = remoteAgent }); } } throw new ReaderControllerException( "Login failed due to invalid user/password or an an invalid account."); } // If we got this far, something failed, redisplay form throw new ReaderControllerException("Login failed due to an issue with the login parameters.."); } catch (ReaderControllerException) { throw; } catch (Exception ex) { // Don't display the exception message, as it may give something away regarding the login. throw new ReaderControllerException($"Login failed due to unexpected error. {ex.Message}", ex); } }
public async Task <DexihActiveAgent> GetActiveAgent([FromBody] HubKeyOnly hubKey, CancellationToken cancellationToken) { var remoteAgent = await _remoteAgents.GetHubReaderRemoteAgent(hubKey.HubKey, _operations.RepositoryManager, cancellationToken); return(remoteAgent); }