Example #1
0
        private void login()
        {
            String mailInput = this.tbEmail.Text.ToString();
            String pwdInput  = this.tbPass.Text.ToString();

            if (dbDataContext.Users.Where(x => x.Email == mailInput).Select(x => x.Email).Count() == 1)
            {
                string pwdHash = dbDataContext.Users.Where(x => x.Email == mailInput).Select(y => y.Password).First();
                if (pwdHash == PasswordUtil.PasswordHash(pwdInput))
                {
                    this.Hide();
                    MessageBox.Show("Zalogowano pomyślnie");
                    Program.loggedUser = dbDataContext.Users.Where(x => x.Email == mailInput).First();
                    BookListForm bookListForm = new BookListForm();
                    AdminPanel   admin        = new AdminPanel();

                    if (mailInput == "root")
                    {
                        admin.Show();
                    }
                    else
                    {
                        bookListForm.Show();
                    }
                }
                else
                {
                    MessageBox.Show("Podane hasło jest nieprawidłowe");
                }
            }
            else
            {
                if (mailInput != "root")
                {
                    MessageBox.Show("Brak użytkownika w systemie");
                }
                else
                {
                    // Dodawanie użytkownika 'root' jeśli nie ma go w bazie danych
                    Users root = new Users();
                    root.Name     = "Administrator";
                    root.Surname  = "Root";
                    root.Email    = "root";
                    root.Password = PasswordUtil.PasswordHash(pwdInput);
                    dbDataContext.Users.InsertOnSubmit(root);
                    dbDataContext.SubmitChanges();
                    MessageBox.Show("Konto administratora zostało zarejestrowane");
                }
            }
        }
Example #2
0
        private void lbUser_Click(object sender, EventArgs e)
        {
            BookListForm bookList = new BookListForm();

            bookList.Show();
        }