public async Task <ActionResult> AcceptLoginInvitation(AcceptLoginInvitationViewModel invitationVM, string returnUrl) { var user = db.Users.Where(u => u.Email == invitationVM.Email).FirstOrDefault(); if (!ModelState.IsValid) { return(View(invitationVM)); } var result = await SignInManager.PasswordSignInAsync(invitationVM.Email, invitationVM.Password, invitationVM.RememberMe, shouldLockout : false); switch (result) { case SignInStatus.Success: InvitationHelper.MarkAsInvalid(invitationVM.Id); rHelp.RemoveUserFromRole(user.Id, "Guest"); rHelp.AddUserToRole(user.Id, "Member"); user.HouseholdId = invitationVM.HouseholdId; db.SaveChanges(); return(RedirectToAction("Hooray", "Account")); case SignInStatus.LockedOut: return(View("Lockout")); case SignInStatus.RequiresVerification: return(RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = invitationVM.RememberMe })); case SignInStatus.Failure: default: ModelState.AddModelError("", "Invalid login attempt."); return(View(invitationVM)); } }
public ActionResult AcceptLoginInvitation(string recipientEmail, string code, string returnUrl) { ViewBag.ReturnUrl = returnUrl; var realGuid = Guid.Parse(code); var invitation = db.Invitations.FirstOrDefault(i => i.RecipientEmail == recipientEmail && i.Code == realGuid); if (invitation == null) { return(View("Error", invitation)); } var expirationDate = invitation.Created.AddDays(invitation.TTL); if (invitation.IsValid && DateTime.Now < expirationDate) { var householdName = db.Households.Find(invitation.HouseholdId).Name; ViewBag.Greeting = $"Welcome to {householdName}!"; var invitationVM = new AcceptLoginInvitationViewModel { Id = invitation.Id, Email = recipientEmail, Code = realGuid, HouseholdId = invitation.HouseholdId }; return(View(invitationVM)); } return(View("AcceptError", invitation)); }