/// <summary> Begins the login process. </summary> private void StartLogin() { var username = TextBox.Text; var password = PasswordBox.Password; if (string.IsNullOrWhiteSpace(username)) { Utilities.ShowValidationErrorDialog("You must enter a username."); return; } if (string.IsNullOrWhiteSpace(password)) { Utilities.ShowValidationErrorDialog("You must enter a password."); return; } PasswordBox.Clear(); try { HandshakeToken = clients.Auth.BeginLogin(new LoginCredentials { Username = username, Password = password }); } catch (FaultException fe) { Utilities.Log($"FaultException from BeginLogin: {fe}"); Utilities.ShowErrorDialog($"Login failed because \"{fe.Message}\". Please check your credentials and try again.", "Login failed"); } }
/// <summary> Creates the login dialog. </summary> public LoginDialog() { InitializeComponent(); clients = new Clients(); HandshakeToken = null; }
/// <summary> Completes a login process. </summary> private void ConfirmLogin() { var oneTimeUseCode = PasswordBox.Password; if (string.IsNullOrWhiteSpace(oneTimeUseCode)) { Utilities.ShowValidationErrorDialog("You must enter the authentication code."); return; } PasswordBox.Clear(); AuthToken authToken; try { authToken = clients.Auth.FinishLogin(handshake, new SecondFactor { OneTimeUseCode = oneTimeUseCode }); } catch (FaultException fe) { Utilities.Log($"Error on ConfirmLogin: {fe}"); Utilities.ShowErrorDialog($"Login failed because \"{fe.Message}\". Please check your credentials and try again.", "Login failed"); return; } HandshakeToken = null; RunUserSession(authToken); PasswordBox.Focus(); // focus back on the password, because the username will remain populated }
public void GiveHandshake(Socket socket, Action handShakenCallback) { if (socket == null || !socket.Connected || handShakenCallback == null) { return; } var resourceName = uri.AbsolutePath; // TODO check ... PathAndQuery var host = uri.WebSocketAuthority(); var handshake = new ClientHandshake(resourceName, host, origin) { ExtraFields = extraFields }; var token = new HandshakeToken { Socket = socket, Callback = handShakenCallback, Handshake = handshake }; var handshakeBuffer = handshake.ToByteArray(); var args = new SocketAsyncEventArgs(); args.SetBuffer(handshakeBuffer, 0, handshakeBuffer.Length); args.UserToken = token; args.RemoteEndPoint = socket.RemoteEndPoint; args.Completed += OnGivingHandshakeCompleted; socket.SendAsync(args); }
/// <summary> Cancels an incomplete login process. </summary> private void CancelLogin() { clients.Auth.CancelLogin(handshake); // Cancelling the login process should be rare; // track it in case there's some usability problem. ClientAppInsights.TelemetryClient.TrackEvent("Login cancelled"); HandshakeToken = null; PasswordBox.Clear(); }