public bool Login(User details) { var allUsers = GetAll(); var success = allUsers.Any(x => x.Email == details.Email && StringCipherHelper.Decrypt(x.Password, "_UsrMgt") == details.Password); return(success); }
/// <summary> /// Gets the specified identifier. /// </summary> /// <param name="id">The identifier.</param> /// <returns></returns> public User GetById(long id) { var user = _userContext.Users.FirstOrDefault(x => x.Id == id); var password = user.Password; if (password != null) { user.Password = StringCipherHelper.Decrypt(password, "_UsrMgt"); } return(user); }
public IActionResult Update(long id, [FromBody] UserUpdateRequest user) { try { if (user == null) { return(BadRequest("Invalid data. Please check your input and try again.")); } User userToUpdate = _dataRepository.GetById(id); if (userToUpdate == null) { return(NotFound("User not found.")); } if (user.Password == userToUpdate.Password) { var newDetails = new User() { Name = user.Name, Surnames = user.Surnames, Email = user.Email, Password = StringCipherHelper.Encrypt(user.NewPassword, "_UsrMgt"), Country = user.Country, Phone = user.Phone, PostCode = user.PostCode }; _dataRepository.Update(userToUpdate, newDetails); return(NoContent()); } else { return(BadRequest("Invalid password")); } } catch (Exception) { return(BadRequest("An error occured while attempting to update the user. Please try again")); } }
public IActionResult Register([FromBody] User user) { if (user == null) { return(BadRequest("Invalid data. Please check your input and try again.")); } var password = user.Password; if (password == null) { return(BadRequest("Invalid password. Please try again.")); } else { user.Password = StringCipherHelper.Encrypt(password, "_UsrMgt"); } var success = _dataRepository.Add(user); if (!success) { return(BadRequest("An error occured. Please try again.")); } return(CreatedAtRoute( "get", new { Id = user.Id }, new { user.Id, user.Name, user.Country, user.Surnames, user.Phone, user.Email, Password = StringCipherHelper.Decrypt(user.Password, "_UsrMgt"), user.PostCode })); }