Exemple #1
0
        private async void LoginExecute(object passwordBox)
        {
            IsEnabled      = false;
            Message        = string.Empty;
            IsErrorMessage = false;
            Message        = "Validating Credentials";

            var passwordControl = (passwordBox as PasswordBox);

            if (passwordControl != null)
            {
                var password         = passwordControl.Password;
                var validationResult = await _authenticationService.Validate(UserName, password);

                if (validationResult)
                {
                    if (_chatHelper.Connection.State != ConnectionState.Connected)
                    {
                        await _chatHelper.EstablishConnectionAsync();
                    }

                    Message = "Signing In";
                    await _chatHelper.LoginAsync(UserName);

                    if (_chatHelper.IsLoggedIn)
                    {
                        var window     = new FriendList(_userService, UserName);
                        var mainWindow = Application.Current.Windows[0];
                        if (mainWindow != null)
                        {
                            mainWindow.Close();
                        }
                        window.Show();
                    }
                    else
                    {
                        IsErrorMessage = true;
                        Message        = "Unable to Connect...";
                        IsEnabled      = true;
                    }
                }
                else
                {
                    IsErrorMessage = true;
                    Message        = "Invalid Credentials";
                    IsEnabled      = true;
                }
            }
        }