public async Task <ActionResult <User> > Put([FromServices] DataContext context, [FromBody] User model) { if (ModelState.IsValid) { //model.Password = model.Password.GetHashCode().ToString(); model.Password = Cripto.md5(model.Password); context.Users.Update(model); await context.SaveChangesAsync(); return(model); } else { return(BadRequest(ModelState)); } }
public async Task <IActionResult> loginAsync([FromServices] DataContext _ctx, [FromServices] TokenService _tokenService, [FromBody] UserAuthViewModel user) { var cred = await _ctx.Users.AsNoTracking() .FirstOrDefaultAsync(x => x.Email == user.Email && x.Password == Cripto.md5(user.Password)); if (cred == null) { return(NotFound(new { message = "Invalid email or password" })); } var token = _tokenService.GenerateToken(cred); return(StatusCode(200, new { token })); }