public async Task <IActionResult> LogIn(LoginViewModel model) { var apiResponse = await _apiService.LogIn(model); if (!apiResponse.Success) { ModelState.AddModelError("Error", apiResponse.Messages.First()); return(View(new LoginViewModel())); } ClaimsPrincipal claimsPrincipal; AuthenticationProperties authProperties; var isSuccess = _jwtHelper.ValidateToken(apiResponse.AccessToken, out claimsPrincipal, out authProperties); if (!isSuccess) { ModelState.AddModelError("Error", "Json Web Token is invalid."); return(View(new LoginViewModel())); } await _logInHandler.LogInUser(claimsPrincipal, authProperties); _encryptionService.AddOrUpdateEncryptionKey(claimsPrincipal.Identity.Name, model.Password); OnPasswordSave(claimsPrincipal.Identity.Name, model.Password); return(RedirectToAction(controllerName: "Wallet", actionName: "Index")); }
public async Task <IActionResult> UpdatePreferences(string switch2F, string switchPnot, string sliderVerTime) { var apiResponse = await _apiService.UpdateUserPreferences(switch2F, switchPnot, sliderVerTime); if (apiResponse.Success) { ClaimsPrincipal claimsPrincipal; AuthenticationProperties authProperties; _jwtHelper.ValidateToken(apiResponse.AccessToken, out claimsPrincipal, out authProperties); await _logInHandler.LogInUser(claimsPrincipal, authProperties); ViewBag.Message = apiResponse.Messages.First(); return(PartialView("~/Views/Shared/_NotificationAlert.cshtml")); } else { ViewBag.Message = apiResponse.Messages.First(); return(PartialView("~/Views/Shared/_NotificationAlert.cshtml")); } }