public void LoadImageFromFS() { OpenFileDialog open = new OpenFileDialog(); open.Filter = "JPG (*.jpg)|*.jpg|bmp (*.bmp)|*.bmp|Png (*.png)|*.png"; if (open.ShowDialog() == true) { string fileName = open.FileName; if (File.Exists(fileName)) { using (FileStream fs = new FileStream(fileName, FileMode.OpenOrCreate)) { byte[] image = new byte[fs.Length]; fs.Read(image, 0, image.Length); userRepository.update(user, new User(CurrentUser.User.FirstName, CurrentUser.User.SecondName, CurrentUser.User.Mail, CurrentUser.User.TelNumber, CurrentUser.User.About, image)); BitmapImage = LoadPhoto(user.id); } } } else { return; } }
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); } }
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); }