示例#1
0
        public ActionResult ChangeEmail(AccountChangeEmailModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            model.NewEmail = model.NewEmail.Trim();

            var user = GetUser(model.Id, true);

            var foundUser = _repository.Find <UserProfile>().GetBy(model.NewEmail);

            if (foundUser != null && foundUser.Id != user.Id)
            {
                ModelState.AddModelError("NewEmail", "Invalid or taken email address.");
                return(View(model));
            }

            if (foundUser == null)
            {
                user.UpdateEmail(model.NewEmail);
                _repository.Save(user);
            }

            return(RedirectTo <AccountController>(c => c.Show(model.Id, user.UrlName)));
        }
示例#2
0
        public ActionResult ChangeEmailAddress(AccountChangeEmailModel model)
        {
            var exists = _auth0Helper.SearchAuth0UserByEmail(model.EmailAddress)?.Any(x => x.UserId.StartsWith("auth0") && x.UserId != CurrentUser.UserId);

            if (exists.GetValueOrDefault())
            {
                ModelState.AddModelError("", "E-mail address already exists");
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _auth0Helper.ChangeEmail(CurrentUser.UserId, model.EmailAddress);
                    this.AuthenticationManager.SignOut();

                    SnuffoSettings.ShowMessage(TempData, "E-mail Address Updated", "Your E-mail address has been updated. Please login again.", AlertMessageType.Success);
                    return(Redirect($"/{CurrentUser.LanguageCode}/account/login-register/"));
                }
                catch (Exception e)
                {
                    HandleAuth0Exception(e);
                }
            }
            return(CurrentUmbracoPage());
        }
示例#3
0
        public ActionResult ChangeEmail(int id)
        {
            var user = GetUser(id, true);

            var model = new AccountChangeEmailModel
            {
                Id           = id,
                CurrentEmail = user.Email,
                NewEmail     = user.Email,
            };

            return(View(model));
        }
示例#4
0
 public async Task ChangeEmailAsync([FromBody] AccountChangeEmailModel model)
 {
     var id = int.Parse(HttpContext.User.FindFirst(c => c.Type == ClaimTypes.Sid).Value);
     await _authService.ChangeEmailAsync(id, model.Email);
 }