示例#1
0
 public bool registration(string password1, string password2)
 {
     Password1 = password1;
     Password2 = password2;
     if (!String.IsNullOrEmpty(FirstName) && !String.IsNullOrEmpty(SecondName) && !String.IsNullOrEmpty(Mail) && !String.IsNullOrEmpty(Password1) && !String.IsNullOrEmpty(Password2))
     {
         if (Password1.Equals(Password2))
         {
             User tmp = userRepository.getByMail(Mail);
             if (tmp == null)
             {
                 userRepository.add(new User(FirstName, SecondName, Mail, Password1));
                 Info = "Зареган!";
                 return(true);
             }
             else
             {
                 Info = "Пользователь с таким Mail уже есть";
                 return(false);
             }
         }
         else
         {
             Info = "Пароли должны совпадать";
             return(false);
         }
     }
     else
     {
         Info = "Проверьте данные!";
         return(false);
     }
 }
 public bool compareDataOfUser(string password)
 {
     if (!String.IsNullOrEmpty(Login) && !String.IsNullOrEmpty(password))
     {
         User tmp = eFUserRepository.getByMail(Login);
         if (tmp != null)
         {
             if (User.getHash(password).Equals(tmp.password))
             {
                 CurrentUser.User = tmp;
                 App.mainWindow   = new MainWindow();
                 App.mainWindow.Show();
                 return(true);
             }
             else
             {
                 Info = "Проверьте введённые данные";
                 return(false);
             }
         }
         else
         {
             Info = "Проверьте введённые данные";
             return(false);
         }
     }
     else
     {
         Info = "Не всё ввели";
         return(false);
     }
 }
示例#3
0
        public void changeDataOfUser()
        {
            User tmp = new User(FirstName, SecondName, Mail, TelNumber, About, CurrentUser.User.image, user.privilege);

            userRepository.update(user, tmp);
            CurrentUser.User = userRepository.getByMail(Mail);

            AlertWindow alertWindow = new AlertWindow($"Изменения сохранены\nДля входа используйте новый Mail - {Mail}");

            alertWindow.ShowDialog();
        }
        public async Task <bool> auth(string password)
        {
            try
            {
                InstaLogin instaLogin = new InstaLogin(Login, password);
                Status = "Подождите несколько секунд";
                User user = await instaLogin.Get();

                if (user != null)
                {
                    if (userRepository.getByMail(user.mail) != null)
                    {
                        userRepository.update(userRepository.getByMail(user.mail), user);
                        CurrentUser.User = userRepository.getByMail(user.mail);
                        App.authWindow.Close();
                        App.mainWindow = new MainWindow();
                        App.mainWindow.Show();
                    }
                    else
                    {
                        userRepository.add(user);
                        CurrentUser.User = userRepository.getByMail(user.mail);
                        App.authWindow.Close();
                        App.mainWindow = new MainWindow();
                        App.mainWindow.Show();
                    }
                    return(true);
                }
                else
                {
                    throw new Exception();
                }
            }
            catch (Exception)
            {
                Status = "Неверно указан логин или пароль";
                return(false);
            }
        }
示例#5
0
        public bool auth(string password)
        {
            try
            {
                Status = "Подождите нексолько секунд";
                Vk vk = new Vk(Login, password, Code);
                VkNet.Model.User user = vk.getUser();

                string firstName = "";
                string lastName  = "";
                string telNumber = "";
                string about     = "";
                byte[] image;
                string i = "";

                if (userRepository.getByMail(Login) != null)
                {
                    firstName = user.FirstName;
                    lastName  = user.LastName;
                    telNumber = user.MobilePhone;;
                    about     = $"Страна: {user.Country.Title}\n" + $"Город: {user.City.Title}";

                    using (WebClient client = new WebClient())
                    {
                        client.DownloadFile(new Uri(user.Photo200Orig.AbsoluteUri), User.filename);
                    }
                    using (System.IO.FileStream fs = new System.IO.FileStream(User.filename, System.IO.FileMode.OpenOrCreate))
                    {
                        image = new byte[fs.Length];
                        fs.Read(image, 0, image.Length);
                    }
                    CurrentUser.User = userRepository.getByMail(Login);
                    User tmp = new User(firstName, lastName, Login, telNumber, telNumber, about, image, CurrentUser.User.Privilege);
                    userRepository.update(CurrentUser.User, tmp);

                    App.authWindow.Close();
                    App.mainWindow = new MainWindow();
                    App.mainWindow.Show();
                    image = null;
                    return(true);
                }
                else
                {
                    firstName = user.FirstName;
                    lastName  = user.LastName;
                    telNumber = "";
                    about     = $"Страна: {user.Country.Title}\n" + $"Город: {user.City.Title}";
                    using (WebClient client = new WebClient())
                    {
                        client.DownloadFile(new Uri(user.Photo200Orig.AbsoluteUri), User.filename);
                    }
                    using (System.IO.FileStream fs = new System.IO.FileStream(User.filename, System.IO.FileMode.Open))
                    {
                        image = new byte[fs.Length];
                        fs.Read(image, 0, image.Length);
                    }

                    userRepository.add(new Model.User(firstName, lastName, Login, telNumber, about, image));
                    CurrentUser.User = userRepository.getByMail(Login);

                    App.authWindow.Close();
                    App.mainWindow = new MainWindow();
                    App.mainWindow.Show();
                    image = null;
                    return(true);
                }
            }
            catch (VkNet.Exception.UserAuthorizationFailException)
            {
                Status = "Введите код подверждения и повторите вход";
            }
            catch (VkNet.Exception.VkApiException)
            {
                Status = "Неверно указан логин или пароль";
            }
            catch (Exception)
            {
                Status = "Ошибка";
            }
            return(false);
        }