public ActionResult <string> Post([FromBody] LoginForm loginForm) { if (ModelState.IsValid) { var userRep = new UserReposotory(); loginForm.password = Privacy.GetHashedPassword(loginForm.password); if (!userRep.IsSet(loginForm)) { return(BadRequest("неверный логин или пароль")); } var user = userRep.GetUser(loginForm); var response = new { access_token = Privacy.GetToken(user), user_name = user.name }; return(new JsonResult(response)); } else { return(BadRequest()); } }
public ActionResult <string> Post([FromBody] User user) { if (ModelState.IsValid) { var userRep = new UserReposotory(); user.isAdmin = false; user.password = Privacy.GetHashedPassword(user.password); if (!userRep.IsSet(user.email)) { userRep.Add(user); } else { return(BadRequest("Такой пользователь сушествует")); } return(Ok()); } else { return(BadRequest()); } }