public async Task CreateAndGetVCode()
        {
            string key  = RandomExtensions.NextString(10);
            var    code = await verificationCodesService.CreateVerificationCodeAsync(DateTime.UtcNow.ToUnixTime(), key);

            var expectedCode = await verificationCodesService.GetUserVerificationCodeAsync(key);

            Assert.Equal(code, expectedCode.VCode);
        }
Exemplo n.º 2
0
        public async Task PhoneVCodeCreateToken()
        {
            var user  = fillTestDbHelper.Users.FirstOrDefault();
            var vcode = await verificationCodesService.CreateVerificationCodeAsync(DateTime.UtcNow.ToUnixTime(), user.Id.ToString(), user.Id);

            await Assert.ThrowsAsync <WrongVerificationCodeException>(async() => await tokensService.PhoneVCodeCreateTokenPairAsync(user.Phones.FirstOrDefault().PhoneNumber, -1000, null));

            Assert.NotNull(await tokensService.PhoneVCodeCreateTokenPairAsync(user.Phones.FirstOrDefault().PhoneNumber, vcode, null));
            await Assert.ThrowsAsync <UserNotFoundException>(async() => await tokensService.PhoneVCodeCreateTokenPairAsync("+19996660000", 0, null));
        }
Exemplo n.º 3
0
        public async Task <short> CreateVCodeAsync(string targetEmail, long?userId = null)
        {
            try
            {
                using (MessengerDbContext context = contextFactory.Create())
                {
                    var userEmail = await context.Emails.Include(email => email.User)
                                    .FirstOrDefaultAsync(email => email.EmailAddress == targetEmail).ConfigureAwait(false);

                    short verificationCode =
                        await verificationCodesService.CreateVerificationCodeAsync(DateTime.UtcNow.ToUnixTime(), targetEmail, userEmail?.UserId ?? userId).ConfigureAwait(false);

                    return(verificationCode);
                }
            }
            catch (Exception ex)
            {
                throw new CreateVerificationCodeException("Could not create verification code.", ex);
            }
        }