Example #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 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);
            }
        }
Example #3
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);
        }