public ActionResult SignIn([FromBody] SignInViewModel model) { if (ModelState.IsValid) { if (_userBll.CheckUserUniqueness(model.Email)) { return(BadRequest(new { message = "Пользователя с таким адресом не существует" })); } if (!_userBll.VerifyUser(model.Email, model.Password)) { return(BadRequest(new { message = "Неверный пароль" })); } var user = _userBll.GetUserByEmail(model.Email); if (user.IsBlocked) { return(BadRequest(new { message = "Ваш аккаунт заблокирован" })); } if (!user.IsConfirmedEmail) { return(BadRequest(new { message = "Почта не подтверждена" })); } var encodedJwt = new JwtSecurityTokenHandler().WriteToken(GetJwtToken(user)); var response = new { accessToken = encodedJwt, email = user.Email, }; return(Ok(new ObjectResult(response))); } return(BadRequest()); }
public ActionResult <User> AuthenticateUser([FromBody] User user) { try { var userData = _userBll.GetUserByEmail(user.Email, user.Password); if (userData == null) { return(BadRequest()); } else { var createdUser = _automapper.UserDtoToUser(userData); return(CreatedAtAction(nameof(AuthenticateUser), new { email = user.Email }, createdUser)); } } catch (Exception e) { _logger.Error("Exception Thrown", e); throw; } }
public object POST(AuthenticateUser Request) { string email = Request.Email; string password = Request.Password; try { var userData = _userBll.GetUserByEmail(email, password); if (userData == null) { return(null); } else { return(userData); } } catch (Exception e) { // _logger.Error("Exception Thrown", e); return("Error"); } }