Example #1
0
        public MainPage(string Username, FileIO.AccessLevel accessLevel, MainWindow mw)
        {
            mainWindow = mw;
            Logging.Log("Initialize MainPage");
            InitializeComponent();
            if (accessLevel > FileIO.AccessLevel.Root)
            {
                lbiBackup.Visibility = Visibility.Hidden;
                lbiBackup.Height     = 0;
            }

            lbiLogOut.Selected += LbiLogOut_Selected;
            lbiBackup.Selected += LbiBackup_Selected;
            chipUser.Content    = Username;
            // display the main menu with the three main buttons
            MainMenuFrame.Content = new MainMenuPage(
                this.ContentFrame, this.ExtraOptionMenuFrame, this.mainDialogueHost, demographics, scheduling, billing, ErrorMessage);
            this.Background = new ImageBrush(new BitmapImage(new Uri("../../Images/Background3.jpg", UriKind.Relative)));
        }
Example #2
0
        private void SignIn_Click(object sender, RoutedEventArgs e)
        {
            Logging.Log("User attempting to log in");

            // check if the user has tried to log in more than 3 times and is on cooldown
            if (loginAttempts >= maxLoginAttempts && !CanSignIn())
            {
                loginErrorMessage.Text = "Too many attempts in the past minute!";
                return;
            }
            // check if the cooldown has expired and the user should be able to try to log in again
            else if (loginAttempts >= maxLoginAttempts && CanSignIn())
            {
                loginErrorMessage.Text = "";
                loginAttempts          = 0;
            }
            FileIO.AccessLevel ac = FileIO.CheckUser(userName.Text, userPassword.Password.ToString());
            if (ac != FileIO.AccessLevel.InvalidCredentials)
            {
                isValidPass = true;
                mainWindow  = Application.Current.Windows.OfType <MainWindow>().FirstOrDefault();
                if (mainWindow != null)
                {
                    Logging.Log("User logged in");
                    // display the main page on the main window
                    mainWindow.ContentFrame.Content = new MainPage(userName.Text, ac, mainWindow);

                    // close the log in window
                    this.Close();
                }

                loginErrorMessage.Text = "Error encountered while logging you in. Please try again!";
                Logging.Log("Error encountered when logging in");
            }
            else
            {
                loginErrorMessage.Text = "Username/Password invalid. Try again!";
                Logging.Log("Username/Password invalid");
                loginAttempts++;
                loginStopwatch.Restart();
            }
        }