Exemple #1
0
        private void btnLogIn_Click(object sender, RoutedEventArgs e)
        {
            User user = new User(txtUsername.Text, txtPassword.Password);

            if (Query.SignInUser(user))
            {
                this.Visibility = Visibility.Hidden;
                MainWindow mainWindow = StartWindow.GetMainWindow(this);
                mainWindow.User = user;
                mainWindow.movies.InsertAddButton();

                this.txtUsername.Text = string.Empty;
                this.txtPassword.Password = string.Empty;

                if (mainWindow.User.IsAdmin)
                {
                    mainWindow.adminWindow.Visibility = Visibility.Visible;
                }
                else
                {
                    mainWindow.movies.Visibility = Visibility.Visible;
                }
            }
        }
Exemple #2
0
        public static List<User> GetUsers()
        {
            List<User> users = new List<User>();

            Query.queryToExecute = string.Format("SELECT * FROM users;");
            MySqlDataReader reader = Query.queryExecutor.ExecuteQuery(Query.queryToExecute);

            if (reader.HasRows)
            {
                while (reader.Read())
                {
                    User user = new User();

                    user.Id = reader.GetInt32(0);
                    user.Username = reader.GetString(1);
                    user.Email = reader.GetString(3);
                    user.IsAdmin = reader.GetBoolean(4);

                    users.Add(user);
                }
            }

            reader.Close();
            return users;
        }
Exemple #3
0
        private static bool IsUserExist(User user)
        {
            bool result = false;

            queryToExecute = string.Format(
                "SELECT * FROM users WHERE user_name=\"{0}\" AND password=\"{1}\";",
                user.Username, user.Password);
            MySqlDataReader reader = queryExecutor.ExecuteQuery(queryToExecute);

            if (reader.HasRows)
            {
                result = true;

                while (reader.Read())
                {
                    user.Id = reader.GetInt32(0);
                    user.Email = reader.GetString(3);
                    user.IsAdmin = reader.GetBoolean(4);
                }
            }

            reader.Close();
            return result;
        }
Exemple #4
0
        public static bool SignInUser(User user)
        {
            bool result = false;

            if (InputValidation.IsValidSignInInput(user.Username, user.Password))
            {
                if (IsUserExist(user))
                {
                    result = true;
                }
                else
                {
                    MessageBox.Show("Ivalid username or password!", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }

            return result;
        }