Ejemplo n.º 1
0
        public void ConfirmButton()
        {
            _logger.Info($"Button for confirming inputed data pressed.");

            if (UserNameText.Length > 0 && PasswordText.Length > 0)
            {
                _logger.Info($"User name lenght OK and password lengts OK");

                LoginAuthenticator       authenticator = new LoginAuthenticator(UserNameText, PasswordText, _reamProvider);
                AuthenticationResultEnum result        = authenticator.Authenticate();

                _logger.Info($"Authentication of inputed data rresult: {result.ToString()}.");

                GenerateLoginErrorString(result);

                if (result == AuthenticationResultEnum.LoginSuccessfull)
                {
                    _logger.Info($"Login successfull.");

                    GetLoggedUserData(authenticator);
                    TryClose();
                }
                else
                {
                    _logger.Info($"Login failed.");

                    UserNameText = "";
                    PasswordText = "";
                }
            }
        }
Ejemplo n.º 2
0
        private void GetLoggedUserData(LoginAuthenticator authenticator)
        {
            _logger.Info($"Getting data of siccessfully loged user started.");

            _userData       = authenticator.GetUserData();
            Tosend.UserData = LoggedUserData;
            _eventAggregator.BeginPublishOnUIThread(Tosend);
        }
Ejemplo n.º 3
0
        /*********************************************************************/
        /*               Check if the user is still logged in                */
        /*********************************************************************/
        public void CheckUser()
        {
            EnableLoginButton = false;

            var userName = LoginAuthenticator.GetLogin("USERNAME");

            if (userName != null)
            {
                _locator.User = userName;
                NavigateToMainPage();
                EnableLoginButton = true;
            }
            else
            {
                _locator.Navigator.NavigateTo(App.PageKeys.LoginPageKey);
                EnableLoginButton = true;
            }
        }
Ejemplo n.º 4
0
        public async Task AttemptLoginAsync()
        {
            EnableLoginButton = false;
            Dialog            = _locator.Dialog;
            Dialog.StartProgressDialog("The Nest", "Logging in...", false);

            try
            {
                if (CurrentUser.Id == "123")
                {
                    LoginAuthenticator.SaveLogin("USERNAME", "118965");

                    _locator.User = "******";

                    Dialog.ChangeDialogText("The Nest", "Loading...");

                    await _locator.Main.InitializeNewUserAsync();

                    Debug.WriteLine($"\n\n\n\nCredentials:{LoginAuthenticator.GetLogin("USERNAME")}");

                    EnableLoginButton = true;

                    Dialog.DismissProgressDialog();
                }
                else
                {
                    try
                    {
                        _azureTokenTable = App.Client.GetTable <AzureToken>();

                        var userTable = await _azureTokenTable
                                        .Where(user => user.Id == CurrentUser.Id).ToListAsync();

                        if (userTable != null)
                        {
                            Remote = userTable[0];
                            if (Authenticator.VerifyPassword(CurrentUser.Password,
                                                             Remote.HashedPassword, Remote.Salt))
                            {
                                LoginAuthenticator.SaveLogin("USERNAME", Remote.Id);
                                _locator.User = CurrentUser.Id;

                                Dialog.ChangeDialogText("The Nest", "Loading...");

                                await _locator.Main.InitializeNewUserAsync();

                                Dialog.DismissProgressDialog();
                                Debug.WriteLine($"\n\nCredentials:" +
                                                $"{LoginAuthenticator.GetLogin("USERNAME")}");
                            }
                            else
                            {
                                Debug.WriteLine("\n\n\n\nWrong Credentials");
                                Dialog.DismissProgressDialog();
                                await Dialog.StartDialogAsync("Error:",
                                                              "\nIncorrect username or password.\n", true, 0);
                            }
                        }
                        else
                        {
                            Dialog.DismissProgressDialog();
                            await Dialog.StartDialogAsync("Error:",
                                                          "\nIncorrect username or password.\n", true, 0);
                        }
                    }

                    catch (System.Net.WebException internetConnectionEx)
                    {
                        Debug.WriteLine($"\n\n\n{internetConnectionEx.Message}");
                        Dialog.DismissProgressDialog();
                        await Dialog.StartToastAsync("Please check your Internet connection.",
                                                     Android.Widget.ToastLength.Long, 150);
                    }

                    catch (ArgumentOutOfRangeException IncorrectCredentials)
                    {
                        Debug.WriteLine($"\n\n\n{IncorrectCredentials.Message}");
                        Dialog.DismissProgressDialog();
                        await Dialog.StartDialogAsync("Error:",
                                                      "Incorrect username or password.\n", true, 0);
                    }

                    catch (Exception UnkownError)
                    {
                        Debug.WriteLine($"\n\n\n{UnkownError.Message}");
                        Dialog.DismissProgressDialog();
                        await Dialog.StartDialogAsync(null,
                                                      "An error occured while logging in.\nPlease try again.", true, 0);
                    }
                    EnableLoginButton = true;
                }
            }
            catch (ArgumentNullException EmptyCredential)
            {
                Debug.WriteLine($"\n\n\n{EmptyCredential.Message}");
                Dialog.DismissProgressDialog();
                await Dialog.StartDialogAsync("Error:",
                                              "Please input both username and password.", true, 0);

                EnableLoginButton = true;
            }
        }