Ejemplo n.º 1
0
        public void should_decode_encoded_url_query_string()
        {
            var emailToken = new UserEmailToken
            {
                UserId = 35,
                Token  = StringUtility.Random(32)
            };
            var encoded = emailToken.EncodeAsUrlQueryString();


            var extracted = UserEmailToken.ExtractFromUrlQueryString(encoded);


            Assert.Equal(35, extracted.UserId);
            Assert.Equal(emailToken.Token, extracted.Token);
        }
Ejemplo n.º 2
0
        public void should_encode_as_url_query_string()
        {
            var emailToken = new UserEmailToken
            {
                UserId = 35,
                Token  = StringUtility.Random(32)
            };

            var encoded = emailToken.EncodeAsUrlQueryString();


            var queryString = Encoding.ASCII.GetString(Convert.FromBase64String(encoded));
            var query       = QueryHelpers.ParseQuery(queryString);

            Assert.Equal("35", query["userid"]);
            Assert.Equal(emailToken.Token, query["token"]);
        }
Ejemplo n.º 3
0
        public async Task SendEmailConfirmationMailAsync(User user, string urlProtocol)
        {
            if (user.EmailAddressConfirmed)
            {
                throw new UserEmailAlreadyConfirmedException(user.UserName);
            }

            var tokenString = await _userManager.GenerateEmailConfirmationTokenAsync(user);

            var tokenInEmail = new UserEmailToken {
                UserId = user.Id, Token = tokenString
            };

            // ReSharper disable Mvc.ActionNotResolved
            // ReSharper disable Mvc.ControllerNotResolved
            var callbackUrl = _urlHelper.Action(
                "ConfirmEmail",
                "User",
                new { token = tokenInEmail.EncodeAsUrlQueryString() },
                protocol: urlProtocol);

            var emailBody = _confirmationEmailBuilder.BuildEmailBody(user.DisplayName, callbackUrl);
            await _emailDeliveryMethod.SendEmailAsync(user.EmailAddress, "dotnet club 用户邮件地址确认", emailBody);
        }