public ActionResult InvitationRegister(string email, Guid code) { if (email == null || code == null) { return(View("Error")); } var invitation = db.Invitations.Where(i => i.RecipientEmail == email && i.Valid == true).FirstOrDefault(); if (invitation == null) { return(View("Error")); } if (code == invitation.Code) { var model = new InviteRegisterViewModel { HouseholdId = invitation.HouseholdId, Email = invitation.RecipientEmail }; return(View(model)); } else { return(View("Error")); } //return View((code == invitation.Code) ? "InviteRegister" : "Error"); }
public async Task <ActionResult> RegisterInvite(InviteRegisterViewModel model) { if (ModelState.IsValid) { var user = new ApplicationUser { UserName = model.Email, Email = model.Email, FirstName = model.FirstName, LastName = model.LastName, AvatarPath = "Content/Images/blank-avatar.png", HouseholdId = model.HouseholdId, EmailConfirmed = true }; var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { UserManager.AddToRole(user.Id, "Member"); await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false); var invitation = db.Invitations.Where(i => i.RecipientEmail == user.Email && i.Valid == true).FirstOrDefault(); invitation.Valid = false; db.SaveChanges(); return(RedirectToAction("Main", "Dashboard")); } AddErrors(result); } // If we got this far, something failed, redisplay form return(View(model)); }
public async Task <ActionResult> InviteRegister(InviteRegisterViewModel model, int householdId) { if (ModelState.IsValid) { var user = new ApplicationUser { UserName = model.Email, Email = model.Email, FirstName = model.FirstName, LastName = model.LastName, DisplayName = model.FirstName + " " + model.LastName }; var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false); // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771 // Send an email with this link // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id); // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme); // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>"); // Call the helper to assign var user to the household. var db = new ApplicationDbContext(); HouseholdUsersHelper helper = new HouseholdUsersHelper(db); helper.AddUserToHousehold(householdId, user.Id); return(RedirectToAction("Index", "Home")); } AddErrors(result); } // If we got this far, something failed, redisplay form return(View(model)); }
// // GET: /Account/InviteRegister public ActionResult InviteRegister(Guid code, string email) { var myInviteRegGM = new InviteRegisterViewModel { Code = code, Email = email }; return(View()); }
public async Task <ActionResult> InviteRegister(InviteRegisterViewModel model, HttpPostedFileBase avatar) { if (ModelState.IsValid) { var invite = db.Invitations.FirstOrDefault(i => i.Code == model.Code && i.ReciepientEmail == model.Email); if (invite == null) { //add gritter that inv is no good RedirectToAction("Register", "Account"); } var isUsed = invite.used; if (!isUsed) { var user = new ApplicationUser { UserName = model.Email, Email = model.Email, FirstName = model.FirstName, LastName = model.LastName, HouseholdId = db.Invitations.FirstOrDefault(i => i.Code == model.Code).HouseholdId }; if (avatar != null) { //start processing my image if (ImageUploadValidator.IsWebFriendlyImage(avatar)) { var fileName = Path.GetFileName(avatar.FileName).Replace(' ', '_'); avatar.SaveAs(Path.Combine(Server.MapPath("~/Avatar/"), fileName)); user.AvatarUrl = "/Avatar/" + fileName; } } else { user.AvatarUrl = "/Avatar/Default-avatar.jpg"; } var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { invite.used = true; db.SaveChanges(); roleHelper.AddUserToRole(user.Id, "member"); await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false); // For more information on how to enable account confirmation and password reset please visit https://go.microsoft.com/fwlink/?LinkID=320771 // Send an email with this link string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id); var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme); await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>"); return(RedirectToAction("Dashboard", "Households")); } AddErrors(result); } else { //greatter telling them invite has been used RedirectToAction("Register", "Account"); } } // If we got this far, something failed, redisplay form return(View(model)); }