public IActionResult Login([FromBody] LoginModel model) { HopperModel user = _user.GetUserByUserNameAndPassword(model); if (user == null) { return(Unauthorized("Invalid username and/or password.")); } var claims = new[] { new Claim(JwtRegisteredClaimNames.Sub, model.Username), new Claim(JwtRegisteredClaimNames.Jti, model.Password), new Claim(ClaimTypes.Role, "User") }; var signingKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes("MySuperSecuredKey")); JwtSecurityToken token = new JwtSecurityToken( issuer: "http://oec.com", audience: "http://oec.com", expires: DateTime.UtcNow.AddHours(10), claims: claims, signingCredentials: new SigningCredentials(signingKey, SecurityAlgorithms.HmacSha256) ); return(Ok(new { token = new JwtSecurityTokenHandler().WriteToken(token), expiration = token.ValidTo })); }
public ActionResult <HopperModel> GetById(int id) { try { HopperModel record = _user.GetById(id); return(Ok(record)); } catch (Exception ex) { return(StatusCode(500, ex.Message)); } }
public ActionResult <HopperModel> Update([FromBody] HopperModel model) { try { if (ModelState.IsValid) { HopperModel record = _user.Update(model); return(Ok(record)); } else { return(ValidationProblem()); } } catch (Exception ex) { return(StatusCode(500, ex.Message)); } }
public HopperModel Update(HopperModel model) { return(_mapper.Map <HopperModel>(_userRepository.Update(_mapper.Map <Hopper>(model)))); }