示例#1
0
        public async Task <ActionResult> EditProfile()
        {
            string id      = ClaimsManager.GetClaims(User.Identity).id;
            var    manager = AuthManager.GetUserManager();

            AppUserModel appUser = await manager.FindByIdAsync(id);

            RegisterModel registerModel = AutoMapperConfig.mapperConfig.Map <RegisterModel>(appUser);

            return(View(registerModel));
        }
示例#2
0
        public async Task <ActionResult> EditProfile(RegisterModel model, HttpPostedFileBase avatarFile)
        {
            string newHash;
            string id = ClaimsManager.GetClaims(User.Identity).id;

            var manager = AuthManager.GetUserManager();

            AppUserModel updatedUser = await manager.FindByIdAsync(id);

            //you can't use AutoMapper here because it will set non model properties of Identity User to null
            updatedUser.addressLine1   = model.addressLine1;
            updatedUser.addressLine2   = model.addressLine2;
            updatedUser.addressLine3   = model.addressLine3;
            updatedUser.companyName    = model.companyName;
            updatedUser.companyWebsite = model.companyWebsite;
            updatedUser.contactNumber  = model.contactNumber;
            updatedUser.country        = Request["ddlCountry"].ToString();
            updatedUser.firstName      = model.firstName;
            updatedUser.lastName       = model.lastName;
            updatedUser.middleName     = model.middleName;
            updatedUser.password       = model.password;
            updatedUser.postCode       = model.postCode;

            newHash = manager.PasswordHasher.HashPassword(updatedUser.password);

            updatedUser.PasswordHash = newHash;

            var updation = await manager.UpdateAsync(updatedUser);

            if (updation.Succeeded)
            {
                if (avatarFile != null)
                {
                    string[] files = Directory.GetFiles(Server.MapPath("/Resc/images/users/"), id + ".*");
                    foreach (string file in files)
                    {
                        System.IO.File.Delete(file);
                    }
                    string ext     = Path.GetExtension(avatarFile.FileName);
                    string fileUrl = String.Concat(Server.MapPath("/Resc/images/users/"), id, ext);
                    avatarFile.SaveAs(fileUrl);
                }

                return(RedirectToAction("Dashboard"));
            }

            TempData["hasUpdationError"] = "true";

            return(View());
        }
示例#3
0
        public async Task <ActionResult> UpdateEmail(FormCollection form)
        {
            model = ClaimsManager.GetClaims(User.Identity);

            string newEmail = form.Get("txtEmail");
            string password = form.Get("txtPassword");

            string id = ClaimsManager.GetClaims(User.Identity).id;

            var manager = AuthManager.GetUserManager();

            AppUserModel appUser = await manager.FindByIdAsync(id);

            appUser.emailAddress   = appUser.Email = newEmail;
            appUser.EmailConfirmed = false;

            if (password.Equals(appUser.password))
            {
                var updateProcess = await manager.UpdateAsync(appUser);

                if (updateProcess.Succeeded)
                {
                    string code = await manager.GenerateEmailConfirmationTokenAsync(appUser.Id);

                    var callbackUrl = Url.Action("EmailConfirm", "Auth", new { userId = appUser.Id, code = code }, protocol: Request.Url.Scheme);

                    await manager.SendEmailAsync(appUser.Id, "Vizfully-Account Confirmation", AppConsts.EmailTexts.GetEmailUpdateText(appUser.firstName, callbackUrl));

                    ViewBag.UpdateSuccess = "An email with activation link has been sent to the new email address.";


                    var ctx         = Request.GetOwinContext();
                    var authManager = ctx.Authentication;
                    authManager.SignOut(DefaultAuthenticationTypes.ExternalCookie);
                    authManager.SignOut("ApplicationCookie");
                    return(View(model));
                }

                ViewBag.UpdateError = "Unable to update email. Something went wrong.";

                return(View(model));
            }

            ViewBag.UpdateError = "Invalid password.";

            return(View(model));
        }
示例#4
0
        public ActionResult Dashboard()
        {
            model = ClaimsManager.GetClaims(User.Identity);

            return(View(model));
        }
示例#5
0
        public ActionResult UpdateEmail()
        {
            model = ClaimsManager.GetClaims(User.Identity);

            return(View(model));
        }