Exemple #1
0
        private async Task ConfirmCommand(object password)
        {
            // Check that both passwordboxes are filled
            if ((password as IHavePassword).SecurePassword == null || (password as INewPassword).SecondPassword == null ||
                (password as IHavePassword).SecurePassword.Length < 4 || (password as INewPassword).SecondPassword.Length < 4)
            {
                IsNotFilledCorrectly = true;
                return;
            }

            if (await LoginHelpers.UpdatePassword(IoC.CreateInstance <ApplicationViewModel>().CurrentUser.personalNumber,
                                                  (password as IHavePassword).SecurePassword, (password as INewPassword).SecondPassword))
            {
                IoC.CreateInstance <ApplicationViewModel>().CloseSubPopUp();
                IoC.CreateInstance <ApplicationViewModel>().OpenSubPopUp(PopUpContents.Success);
                await Task.Delay(700);

                IoC.CreateInstance <ApplicationViewModel>().CloseSubPopUp();
                IsNotFilledCorrectly = false;
            }
            else
            {
                IsNotFilledCorrectly = true;
                return;
            }
        }
Exemple #2
0
        /// <summary>
        /// Logging in the user if credentials are correct
        /// </summary>
        /// <returns></returns>
        public async Task LoginAsUserCommandAsync(object password)
        {
            // Hide the textbox in the control
            ShowLoginFailedText = false;

            // Checking if the login is already running, used to avoid overload
            if (UserLoginIsRunning)
            {
                return;
            }

            // Indicate that the login is running
            UserLoginIsRunning = true;

            // The actual login trial
            try
            {
                // Temporarily used waiter to simulate animation
                await Task.Delay(500);

                // Check for inputs
                if (PNumber == null || (password as IHavePassword).SecurePassword == null)
                {
                    return;
                }

                // Get a user object from the database
                var loggedInUser = (await LoginHelpers.AttemptLogin(PNumber, (password as IHavePassword).SecurePassword));

                // If no user is returned...
                if (loggedInUser == null)
                {
                    // Show the textbox in the control
                    ShowLoginFailedText = true;
                    return;
                }

                var NewUser = loggedInUser.ToModel <IUser, UserViewModel>();

                // Set the logged in user
                IoC.CreateInstance <ApplicationViewModel>().CurrentUser = NewUser;
                IoC.CreateInstance <ApplicationViewModel>().SetCurrentUserRole();

                await CheckNotifications();

                // If the login is made from the start screen we go to the book page
                if (IoC.CreateInstance <ApplicationViewModel>().CurrentPage == ApplicationPages.MainPage)
                {
                    IoC.CreateInstance <ApplicationViewModel>().GoToPage(ApplicationPages.BookPage);
                }

                // Closes the popup if we're not in firstload-mode
                if (!IoC.CreateInstance <ApplicationViewModel>().IsLoading&& IoC.CreateInstance <ApplicationViewModel>().CurrentPage != ApplicationPages.MainPage)
                {
                    IoC.CreateInstance <ApplicationViewModel>().ClosePopUp();
                }

                IoC.CreateInstance <MyProfileControlViewModel>().GetMyLoansAndReservations();

                // Reset input properties
                ViewModelHelpers.ResetInputProperties <UserLoginControlViewModel>(nameof(PNumber));
            }

            finally
            {
                // When the login is done, no matter if it succeeds or not, the flag will be set to false
                UserLoginIsRunning = false;
            }
        }