예제 #1
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;
            }
        }
예제 #2
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;
            }
        }