public async Task <ActionResult> RegisterFromInvite([Bind(Include = "Id,FirstName,LastName,UserName,Email,Password,ConfirmPassword,ProfileImage,HouseholdName")] RegisterViewModel model, HttpPostedFileBase image)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    FirstName = model.FirstName, LastName = model.LastName, UserName = model.UserName, Email = model.Email, ProfileImage = model.ProfileImage
                };
                var result = await UserManager.CreateAsync(user, model.Password);

                if (ProfileImageUploadValidator.IsWebFriendlyImage(image))
                {
                    var fileName = Path.GetFileName(image.FileName);
                    image.SaveAs(Path.Combine(Server.MapPath("~/Uploads/"), fileName));
                    user.ProfileImage = "/Uploads/" + fileName;
                }

                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>");

                    return(RedirectToAction("ProfileView", "Account"));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Esempio n. 2
0
        public ActionResult EditProfile(UserProfileViewModel profile, HttpPostedFileBase image)
        {
            if (ModelState.IsValid)
            {
                var user = db.Users.Find(profile.Id);
                db.Users.Attach(user);
                user.FirstName   = profile.FirstName;
                user.LastName    = profile.LastName;
                user.DisplayName = profile.DisplayName;
                user.Email       = profile.Email;
                user.UserName    = profile.Email;

                if (ProfileImageUploadValidator.IsWebFriendlyImage(image))
                {
                    var fileName = Path.GetFileName(image.FileName);
                    image.SaveAs(Path.Combine(Server.MapPath("~/Uploads/"), fileName));
                    user.ProfileImagePath = "/Uploads/" + fileName;
                }

                db.SaveChanges();
                return(RedirectToAction("UserIndex", "Manage"));
            }
            return(View());
        }