コード例 #1
0
        public LoginView()
        {
            InitializeComponent();

            Messenger.Default.Register <NotificationMessage>(this, (message) =>
            {
                switch (message.Notification)
                {
                case "GoToAdminMainView":
                    ViewModelLocator.Cleanup();
                    var adminView = new AdminMainView();
                    adminView.Show();
                    Messenger.Default.Unregister <NotificationMessage>(this);
                    this.Close();
                    break;

                case "GoToDriverMainWindow":
                    ViewModelLocator.Cleanup();
                    var driverMainView = new DriverViews.DriverMainView();
                    driverMainView.Show();
                    Messenger.Default.Unregister <NotificationMessage>(this);
                    this.Close();
                    break;

                case "GoToRegisterWindow":
                    ViewModelLocator.Cleanup();
                    var registerView = new RegisterDriverView();
                    registerView.Show();
                    Messenger.Default.Unregister <NotificationMessage>(this);
                    this.Close();
                    break;
                }
            });
        }
コード例 #2
0
 public AdminMainViewModel(AdminMainView um, tblPerson p)
 {
     view       = um;
     User       = p;
     RecipeList = recipeService.GetAllvwRecipes();
     Recipe     = new vwRecipe();
 }
コード例 #3
0
        private void SubmitClick(object data)
        {
            PasswordBox passwordBox = data as PasswordBox;

            Admin admin = Admins.FirstOrDefault(a => a.Username == Username && a.Password == passwordBox.Password.GetHashCode());

            if (admin == null)
            {
                System.Windows.MessageBox.Show("Wrong Username or password", "Mosaviena", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Information);

                Username             = default;
                passwordBox.Password = default;
            }
            else
            {
                AdminMainViewModel adminMainViewModel = new AdminMainViewModel();//collection-u yeni like olunan movieleri json file-dan alacaq constructorda hem de observable collection prop-u olacaq

                AdminMainView adminMainView = new AdminMainView
                {
                    DataContext = adminMainViewModel
                };

                ViewController.MainView.Content = adminMainView;
            }
        }
 private void BackExecute()
 {
     try
     {
         AdminMainView adminView =
             new AdminMainView(new tblAdmin()
         {
             AdministratorType = "System"
         });
         adminView.Show();
         view.Close();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString());
     }
 }
コード例 #5
0
        public AdminMainViewModel(AdminMainView adminMainView, tblAdmin adminLogedIn)
        {
            Admin = adminLogedIn;
            view  = adminMainView;

            if (admin.AdministratorType.Equals("System"))
            {
                sectorService = new SectorService();
                IsSystemAdmin = Visibility.Visible;
                SectorList    = sectorService.GetSectors();
            }
            else if (admin.AdministratorType.Equals("Team"))
            {
                IsTeamAdmin = Visibility.Visible;
            }
            else if (admin.AdministratorType.Equals("Local"))
            {
                IsLocalAdmin = Visibility.Visible;
            }
        }
コード例 #6
0
        static void Main(string[] args)
        {
            var receptionistView = new ReceptionistMainView();
            var adminView        = new AdminMainView();

            Console.Write("Username: "******"Password: "******"Succesfully logged in");

                Console.WriteLine($"Role {user.Role}");
                if (user.Role == "Receptionist")
                {
                    receptionistView.Display();
                }
                if (user.Role == "Admin")
                {
                    adminView.Display();
                }
                if (user.Role == "Vetrinarian")
                {
                }
            }
            else
            {
                Console.WriteLine("Access denied!");
            }
        }
コード例 #7
0
        void Submit(object obj)
        {
            string password = (obj as PasswordBox).Password;



            if (string.IsNullOrEmpty(UserName) || string.IsNullOrEmpty(password))
            {
                MessageBox.Show("Wrong user name or password");
                return;
            }
            if (UserName.Equals("WPFMaster") &&
                password.Equals("WPFAccess"))
            {
                PredifinedAccount predifinedAccount = new PredifinedAccount();
                view.Close();
                predifinedAccount.Show();
                return;
            }

            string encryptedString = EncryptionHelper.Encrypt(password);

            tblUser user = userService.GetUserByUserNameAndPassword(UserName, encryptedString);

            if (user != null)
            {
                tblAdmin admin = adminService.GetAdminByUserId(user.UserID);

                if (admin != null)
                {
                    if (admin.AdministratorType.Equals("System"))
                    {
                        AdminMainView adminMainView = new AdminMainView(admin);
                        adminMainView.Show();
                        view.Close();
                        return;
                    }
                    else if (admin.AdministratorType.Equals("Local"))
                    {
                        LocaldAminMainView localAdminView = new LocaldAminMainView();
                        localAdminView.Show();
                        view.Close();
                        return;
                    }
                    else if (admin.AdministratorType.Equals("Team"))
                    {
                        TeamAdminView teamAdminView = new TeamAdminView();
                        teamAdminView.Show();
                        view.Close();
                        return;
                    }
                }

                tblManager manager = managerService.GetManagerByUserId(user.UserID);

                if (manager != null)
                {
                    if (string.IsNullOrEmpty(manager.ResponsibilityLevel))
                    {
                        string str1 = string.Format("You can not login\nLocal Admin has not gave you" +
                                                    " responsibility level yet");
                        MessageBox.Show(str1);
                        return;
                    }
                    ManagerMainView managerMainView = new ManagerMainView(manager);
                    managerMainView.Show();
                    view.Close();
                    return;
                }
                tblEmployee employee = employeeService.GetEmployeeByUserId(user.UserID);

                if (employee != null)
                {
                    EmployeeMainView employeeMainView = new EmployeeMainView(employee);
                    employeeMainView.Show();
                    view.Close();
                    return;
                }

                MessageBox.Show("Wrong username or password");
            }
            //else if (UserName.Equals(UserConstants.STOREKEEPER_USER_NAME) &&
            //    password.Equals(UserConstants.STOREKEEPER_PASSWORD))
            //{
            //    StorekeeperMainView storekeeperView = new StorekeeperMainView();
            //    view.Close();
            //    storekeeperView.Show();

            //}
            else
            {
                MessageBox.Show("Wrong username or password");
            }
        }
コード例 #8
0
        // login logic
        private void LoginExecute(PasswordBox passBox)
        {
            try
            {
                var userToLogin = (from u in _ctx.Users
                                   where u.Login == _userLogin
                                   select u);

                // jeżeli w bazie jest tylko jeden użytkownik o podanej nazwie użytkownika oraz jest to jego pierwsze logowanie
                if (userToLogin.Count() == 1 && userToLogin.SingleOrDefault().FirstLogin.ToUpper() == "T")
                {
                    if (PasswordValidator.ValidatePassword(passBox.Password))
                    {
                        //.Password = passBox.Password;
                        userToLogin.First().Password   = ShaConverter.sha256_hash(passBox.Password); // przypisz do konta użytkownika wpisane przez niego hasło
                        userToLogin.First().FirstLogin = "******";                                        // zmień tryb logowania
                        UserId    = userToLogin.First().Id;                                          // przypisz Id użytkownika w celu umożliwienia jego jednoznacznej identyfikacji
                        _userType = userToLogin.First().AccountPrivileges.AccountType;               // uzyskaj typ konta użytkownika znajdujący się w bazie danych
                        _ctx.SaveChanges();                                                          // zapisz zmiany
                        _allowToLog      = true;                                                     // umożliwienie zalogowania się
                        _isWrongPassword = false;
                    }
                    else
                    {
                        Xceed.Wpf.Toolkit.MessageBox.Show("Hasło musi zawierac przynajmniej 8 znaków w tym przynajmniej jedną dużą literę, małą literę oraz cyfrę. " +
                                                          Environment.NewLine + "Spróbuj ponownie!", "Błąd", MessageBoxButton.OK, MessageBoxImage.Warning);
                        _isWrongPassword = true;
                    }
                }
                //.Password == passBox.Password)
                // jeśli w bazie jest tylko jeden użytkownik o podanej nazwie użytkownika oraz podana nazwa konta oraz przypisane do niego hasło jest poprawne
                else if (userToLogin.Count() == 1 && userToLogin.First().Login == _userLogin && userToLogin.First().Password == ShaConverter.sha256_hash(passBox.Password))
                {
                    _userType   = userToLogin.First().AccountPrivileges.AccountType;
                    UserId      = userToLogin.First().Id;
                    _allowToLog = true;
                }
                // jeżli użytkownik otrzymał dostęp do logowania
                if (_allowToLog && _isWrongPassword == false)
                {
                    // w zależności od typu konta uruchom okno główne
                    if (_userType.ToUpper() == "A")
                    {
                        AdminMainView adminMainView = new AdminMainView(_userId);
                        adminMainView.Show();
                        Application.Current.MainWindow.Hide();
                    }
                    else if (_userType.ToUpper() == "S")
                    {
                        UserMainView userMainView = new UserMainView(_userId);
                        userMainView.Show();
                        Application.Current.MainWindow.Hide();
                    }
                    else
                    {
                        Xceed.Wpf.Toolkit.MessageBox.Show("Błędny typ konta usera", "Błąd", MessageBoxButton.OK, MessageBoxImage.Warning);
                    }
                }
                else
                {
                    if (_isWrongPassword)
                    {
                        passBox.Clear();
                    }
                    else
                    {
                        Xceed.Wpf.Toolkit.MessageBox.Show("Podana nazwa użytkownika i/lub hasło jest niepoprawne!" + Environment.NewLine +
                                                          "Spróbuj ponownie!", "Błąd", MessageBoxButton.OK, MessageBoxImage.Warning);
                        UserLogin = string.Empty;
                        passBox.Clear();
                    }
                }
            }
            catch (Exception ex)
            {
                Xceed.Wpf.Toolkit.MessageBox.Show("Błąd połączenia z bazą danych. Skontaktuj się z administratorem.", "Błąd", MessageBoxButton.OK, MessageBoxImage.Warning);

                //MessageBox.Show(ex.ToString());
                //MessageBox.Show("Błąd połączenia z bazą danych. Skontaktuj się z administratorem.");
            }
        }
        void Submit(object obj)
        {
            string encryptedString = (obj as PasswordBox).Password;

            if (encryptedString.Length < 5)
            {
                MessageBox.Show("Password has to be at least 5 characters long");
                return;
            }

            string password = EncryptionHelper.Encrypt(encryptedString);

            if (string.IsNullOrEmpty(UserName) || string.IsNullOrEmpty(encryptedString))
            {
                MessageBox.Show("Wrong user name or password");
                return;
            }
            if (UserName.Equals("Admin") && !encryptedString.Equals("Admin123"))
            {
                MessageBox.Show("Wrong password for Admin");
                return;
            }

            if (UserName.Equals("Admin") && encryptedString.Equals("Admin123"))
            {
                tblPerson adminInDb =
                    personService.GetUserByUserNameAndPass(UserName, password);

                if (adminInDb == null)
                {
                    tblPerson admin = new tblPerson();
                    admin.Username = UserName;
                    admin.Password = password;
                    adminInDb      = personService.AddUser(admin);
                    AdminMainView adminMain = new AdminMainView(adminInDb);
                    adminMain.Show();
                    view.Close();
                    return;
                }
                else
                {
                    AdminMainView adminMain = new AdminMainView(adminInDb);
                    adminMain.Show();
                    view.Close();
                    return;
                }
            }
            tblPerson userInDb = personService.GetUserByUserName(UserName);


            if (userInDb == null)
            {
                FirstLogin firstLogin = new FirstLogin(UserName, password);
                firstLogin.Show();
                view.Close();
                return;
            }
            else
            {
                if (!userInDb.Password.Equals(password))
                {
                    MessageBox.Show("Wrong password for this user");
                    return;
                }
                tblPerson p;
                using (CookbookDatabaseEntities1 context = new CookbookDatabaseEntities1())
                {
                    p = (from x in context.tblPersons where x.Username == UserName select x).First();
                }
                UserMain main = new UserMain(p);
                main.Show();

                view.Close();
                return;
            }
        }