public ActionResult LogIn(LoginModel loginModel) { if (!ModelState.IsValid) { return(View()); } var isValid = _usersService.AuthenticateUser(loginModel); if (isValid) { var identity = new ClaimsIdentity(new[] { new Claim(ClaimTypes.NameIdentifier, loginModel.Username), new Claim(ClaimTypes.Name, loginModel.Username), }, DefaultAuthenticationTypes.ApplicationCookie); Request.GetOwinContext().Authentication.SignIn(new AuthenticationProperties() { IsPersistent = false }, identity); return(Redirect(GetRedirectUrl(loginModel.ReturnUrl))); } ModelState.AddModelError("", "Invalid credentials"); return(View()); }
public async Task <ActionResult <AuthenticateUserResponse> > Authenticate ( [FromServices] IUsersService usersService, [FromBody] AuthenticateUserRequest request ) { return(await usersService.AuthenticateUser(request)); }
public ActionResult <UserModel> Login([FromBody] LoginModel model) { var user = _users.AuthenticateUser(model.Email, model.Password); if (user == null) { return(BadRequest("Invalid user and / or password")); } else { var userId = user.Id.ToString(); var token = _auth.GenerateJwt(user.Id); var nowDateString = DateTime.UtcNow.ToString(); user = _users.Update(userId, token: token, lastLoginOnUtc: nowDateString, lastUpdatedOnUtc: nowDateString); return(Ok(user)); } }
RedisUser?AuthenticateUser(Credentials login) { return(_userService.AuthenticateUser(login)); }