private void Registration_Click(object sender, RoutedEventArgs e)
        {
            string first_name  = First_NameBox.Text;
            string middle_name = Middle_NameBox.Text;
            string last_name   = Last_NameBox.Text;

            string login = LoginBox.Text.ToLower();

            string password      = PasswordBox.Password;
            string password_copy = PasswordBox_copy.Password;

            if (password.Length != 0 && password != password_copy)
            {
                MessageBox.Show("Введённые пароли не совпадают!", "Ошибка!", MessageBoxButton.YesNo, MessageBoxImage.Error);
                return;
            }

            user.FirstName  = first_name;
            user.MiddleName = middle_name;
            user.LastName   = last_name;

            user.Login = login;
            if (password.Length != 0 && password_copy.Length != 0 && password == password_copy)
            {
                user.Password = PasswordInteraction.GetPasswordHash(password);
            }

            unitOfWork.Users.Update(user);
            unitOfWork.Db.SaveChanges();

            mainWindow.Navigation.Navigate(new TeacherPage(mainWindow, teacher));
        }
示例#2
0
        private void Login_Click(object sender, RoutedEventArgs e)
        {
            string login    = loginBox.Text.ToLower();
            string password = passwordBox.Password;

            string hashedPassword = PasswordInteraction.GetPasswordHash(password);

            User user = mainWindow.unitOfWork.Users.GetUserByLoginAndPassword(login, hashedPassword);

            if (user == null)
            {
                MessageBox.Show("Неверный логин или пароль!", "Ошибка!", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            MessageBox.Show("Вы успешно авторизовались!", "Информация");

            mainWindow.user = user;

            if (TeachersInteraction.IsTeacher(user))
            {
                mainWindow.Navigation.Navigate(new TeacherPage(mainWindow, TeachersInteraction.GetTeacherModel(user)));
            }
            else if (AdminsInteraction.IsAdmin(user))
            {
                mainWindow.Navigation.Navigate(new AdminPage(mainWindow));
            }
            else
            {
                mainWindow.Navigation.Navigate(new UserPage(mainWindow, user));
            }
        }
示例#3
0
        private void Registration_Click(object sender, RoutedEventArgs e)
        {
            string login = LoginBox.Text.ToLower();

            string password = PasswordBox.Password;

            string first_name  = First_NameBox.Text;
            string middle_name = Middle_NameBox.Text;
            string last_name   = Last_NameBox.Text;

            string phone = PhoneBox.Text;

            int    the_class = Int32.Parse(The_class_name.SelectedItem.ToString());
            string letter    = The_class_letter.SelectedValue.ToString();

            if (Position_name.SelectedIndex == -1)
            {
                MessageBox.Show("Выберите роль!");
                return;
            }

            if (login.Length == 0 || password.Length == 0 || first_name.Length == 0 || middle_name.Length == 0 || last_name.Length == 0)
            {
                MessageBox.Show("Пожалуйста, заполните все поля!", "Ошибка");
                return;
            }

            User user = new User
            {
                FirstName  = first_name,
                MiddleName = middle_name,
                LastName   = last_name,

                Login    = login,
                Password = PasswordInteraction.GetPasswordHash(password),

                Phone = phone,

                TheClassesId = unitOfWork.TheClasses.GetTheClassByNumber(the_class, letter)
            };


            if (UsersInteraction.RegisterRequestStatus(user) == false)
            {
                MessageBox.Show("Пользователь с таким логином уже зарегистрирован!", "Error");
                return;
            }

            if (Position_name.SelectedValue.ToString() == "Учитель")
            {
                int subject_id = Specialisation.SelectedIndex + 1;
                TeachersInteraction.Insert_Teacher(user, subject_id);
            }

            MessageBox.Show("Вы успешно зарегистрировались!", "Info");

            user = unitOfWork.Users.GetUserByName(first_name, last_name, middle_name);

            mainWindow.user = user;

            if (TeachersInteraction.IsTeacher(user))
            {
                mainWindow.Navigation.Navigate(new TeacherPage(mainWindow, TeachersInteraction.GetTeacherModel(user)));
            }
            else
            {
                mainWindow.Navigation.Navigate(new UserPage(mainWindow, user));
            }
        }