public ActionResult AccountInfo() { var userId = UserMgr.GetUserId(HttpContext.User); var user = UserMgr.FindByIdAsync(userId).Result; return(View(user)); }
public async Task <IActionResult> ConfirmEmail(string userId, string token) { if (userId == null || token == null) { return(RedirectToAction("Index", "Home")); } var user = await UserMgr.FindByIdAsync(userId); if (user == null) { ViewBag.ErrorMessage = $"O Id de usuário {userId} é inválido"; return(View("Error")); } var result = await UserMgr.ConfirmEmailAsync(user, token); if (result.Succeeded) { ViewBag.Message = "Email confirmado com sucesso!"; return(View("Messages")); } ViewBag.ErrorMessage = "Email não pôde ser confirmado :("; return(View("Error")); }
public async Task <ActionResult> AccountInfo(User userUpdate) { //Get logged in user var userId = UserMgr.GetUserId(HttpContext.User); var currentUser = UserMgr.FindByIdAsync(userId).Result; //Ensure unique email string updateEmail = userUpdate.Email; if (UserMgr.FindByEmailAsync(updateEmail).Result == null || UserMgr.FindByEmailAsync(updateEmail).Result == currentUser) { currentUser.Email = userUpdate.Email; } else { return(View()); } //Password if (userUpdate.Password == null) { currentUser.Password = currentUser.Password; } else { currentUser.Password = userUpdate.Password; await UserMgr.RemovePasswordAsync(currentUser); await UserMgr.AddPasswordAsync(currentUser, userUpdate.Password); } //Name currentUser.FirstName = userUpdate.FirstName; currentUser.LastName = userUpdate.LastName; IdentityResult x = await UserMgr.UpdateAsync(currentUser); if (x.Succeeded) { return(RedirectToAction("Dashboard", "Application")); } else { ViewBag.ErrorMessage = "Error"; return(View(userUpdate)); } }