public bool Authorize(string email, string password) { if (string.IsNullOrWhiteSpace(email)) { MessageBox.Show("User email cannot be empty"); return(false); } if (string.IsNullOrWhiteSpace(password)) { MessageBox.Show("User password cannot be empty"); return(false); } password = PasswordHelpers.GetHash(password); var user = context.Users.FirstOrDefault(u => u.Email == email && u.Password == password); if (user != null) { AuthorizedUser = user; if (AuthorizedUser.Favourites == null) { AuthorizedUser.Favourites = new List <Favourite>(); } return(true); } else { return(false); } }
public bool RegisterUser(string name, string lastname, string email, string password) { if (string.IsNullOrWhiteSpace(name)) { MessageBox.Show("User name cannot be empty"); return(false); } if (string.IsNullOrWhiteSpace(lastname)) { MessageBox.Show("User lastname cannot be empty"); return(false); } if (string.IsNullOrWhiteSpace(email)) { MessageBox.Show("User email cannot be empty"); return(false); } if (string.IsNullOrWhiteSpace(PasswordHelpers.GetHash(password))) { MessageBox.Show("User password cannot be empty"); return(false); } if (context.Users.FirstOrDefault(u => u.Email == email) == null) { var user = new User() { Name = name, LastName = lastname, Email = email, Password = PasswordHelpers.GetHash(password), Favourites = new List <Favourite>() }; Users.Add(user); context.Users.Add(user); context.SaveChanges(); _repo = GetJsRepository(); _repo.Users.Add(user); _repo.Save(); return(true); } else { return(false); } }
private void ButtonRegister_Click(object sender, RoutedEventArgs e) { var user = new User { Name = textBoxName.Text, Email = textBoxEmail.Text, Login = textBoxLogin.Text, Password = PasswordHelpers.GetHash(passwordBox.Password) }; try { _repo.RegisterUser(user); RegistrationFinished?.Invoke(); Close(); } catch { MessageBox.Show("An error occured trying to save new user"); } }
public bool Authorize(string login, string password) { var user = _generalData.Users.FirstOrDefault(u => u.Login == login && u.Password == PasswordHelpers.GetHash(password)); if (user != null) { user.Favourites = LoadUserFavourites(user.Id); _authorizedUser = user; return(true); } return(false); }