示例#1
0
        protected virtual void SetAccountEmail(Guid accountID, ref IEnumerable <Claim> claims)
        {
            var email = claims.GetValue(Constants.ClaimTypes.Email);

            if (email != null)
            {
                var acct = userAccountService.GetByID(accountID);
                if (acct.Email == null)
                {
                    try
                    {
                        var email_verified = claims.GetValue(Constants.ClaimTypes.EmailVerified);
                        if (email_verified != null && email_verified == "true")
                        {
                            userAccountService.SetConfirmedEmail(acct.ID, email);
                        }
                        else
                        {
                            userAccountService.ChangeEmailRequest(acct.ID, email);
                        }

                        var emailClaims = new string[] { Constants.ClaimTypes.Email, Constants.ClaimTypes.EmailVerified };
                        claims = claims.Where(x => !emailClaims.Contains(x.Type));
                    }
                    catch (ValidationException)
                    {
                        // presumably the email is already associated with another account
                        // so eat the validation exception and let the claim pass thru
                    }
                }
            }
        }
示例#2
0
        public ActionResult Index(ChangeEmailRequestInputModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View("Index", model));
            }

            try
            {
                _userAccountService.ChangeEmailRequest(User.GetId(), model.NewEmail);

                return(_userAccountService.Configuration.RequireAccountVerification
                    ? View("ChangeRequestSuccess", model.NewEmail)
                    : View("Success"));
            }
            catch (AuthenticationException)
            {
                return(new HttpUnauthorizedResult());
            }
            catch (ValidationException ex)
            {
                ModelState.AddModelError("", ex.Message);
            }

            return(View("Index", model));
        }
示例#3
0
        public IActionResult ChangeEmail([EmailAddress] string email)
        {
            if (!ModelState.IsValid)
            {
                return(CorrectErrors(BuildUserProfileModel(email), "email"));
            }

            try
            {
                _userAccountService.ChangeEmailRequest(User.GetId(), email);

                if (_userAccountService.Configuration.RequireAccountVerification)
                {
                    return(View("EmailConfirmationSent", email));
                }
                else
                {
                    return(RedirectToAction("Success", "ChangeEmail", null));
                }
            }
            catch (AuthenticationException)
            {
                return(new HttpUnauthorizedResult());
            }
            catch (ValidationException ex)
            {
                ModelState.AddModelError("Email", ex.Message);
            }

            return(CorrectErrors(BuildUserProfileModel(email), "email"));
        }
        public IActionResult ChangeEmail(string userId, string email)
        {
            Guid userGuid;

            if (!Guid.TryParse(userId, out userGuid))
            {
                return(HttpBadRequest("Failed to parse userId."));
            }
            _userAccountService.ChangeEmailRequest(userGuid, email);
            return(RedirectToAction("Edit", new { userId = userId, changed = true }));
        }
示例#5
0
        public void CancelNewAccount_KeyUsedForAnotherPurpose_ReturnsFalse()
        {
            var acct = subject.CreateAccount("test", "pass", "*****@*****.**");

            subject.VerifyAccount(acct.VerificationKey);
            subject.ChangeEmailRequest(acct.ID, "*****@*****.**");

            Assert.IsFalse(subject.CancelNewAccount(repository.Get(acct.ID).VerificationKey));
        }