public IActionResult Login(LoginRequest request) { //TODO Here we should check the credentials! Here we are just taking the first user. var user = _context.User.FirstOrDefault(e => e.Name == "Ruslan"); if (user == null) { return(NotFound()); } var userclaim = new[] { new Claim(ClaimTypes.Name, user.Name), new Claim(ClaimTypes.Role, "user"), //Add additional data here }; var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes("I_AM_SECRET_KEY")); var creds = new SigningCredentials(key, SecurityAlgorithms.HmacSha256); var token = new JwtSecurityToken( issuer: "https://localhost:5001", audience: "https://localhost:5001", claims: userclaim, expires: DateTime.Now.AddMinutes(1), signingCredentials: creds ); user.RefreshToken = Guid.NewGuid().ToString(); user.RefreshTokenExpirationDate = DateTime.Now.AddDays(1); _context.SaveChanges(); return(Ok(new { token = new JwtSecurityTokenHandler().WriteToken(token), refreshToken = user.RefreshToken })); }
public IActionResult AddMeal(Meal meal) { _context.Meal.Add(meal); _context.SaveChanges(); return(Ok(meal)); }
public IActionResult AddDeliveryman(Deliveryman deliveryman) { _context.Deliveryman.Add(deliveryman); _context.SaveChanges(); return(Ok(deliveryman)); }
public IActionResult AddUser(User user) { _context.User.Add(user); _context.SaveChanges(); return(Ok(user)); }
public IActionResult AddDelivery(Delivery delivery) { _context.Delivery.Add(delivery); _context.SaveChanges(); return(Ok(delivery)); }