public async Task <IActionResult> GetToken([FromBody] LoginViewModel model) { if (ModelState.IsValid) { var result = await _signInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, lockoutOnFailure : false); if (result.Succeeded) { _logger.LogInformation(1, "User logged in."); //return RedirectToLocal(returnUrl); DateTime?expires = DateTime.UtcNow.AddMinutes(60); var userId = _userManager.Users.Single(x => x.Email == model.Email).Id; var token = _tokenManager.TokenGenerator(userId, model.Email, expires); //return new { authenticated = true, entityId = 1, token = token, tokenExpires = expires }; return(Ok(new { authenticated = true, entityId = 1, token = token, tokenExpires = expires })); } //if (result.RequiresTwoFactor) //{ // return RedirectToAction(nameof(SendCode), new { ReturnUrl = returnUrl, RememberMe = model.RememberMe }); //} //if (result.IsLockedOut) //{ // _logger.LogWarning(2, "User account locked out."); // return View("Lockout"); //} else { //ModelState.AddModelError(string.Empty, "Invalid login attempt."); return(HttpBadRequest("Invalid login attempt.")); } } return(HttpBadRequest("Invalid Model State.")); }
public IActionResult Notepad() { ViewData["AuthToken"] = _tokenOptions.TokenGenerator(User.GetUserId(), User.Identity.Name, DateTime.Now.AddMinutes(60)); return(View()); }