Esempio n. 1
0
        public async Task <Guid> SendMessageAsync(
            string country,
            string phone,
            string ipAddress,
            string userAgent,
            CancellationToken ct)
        {
            var now           = DateTime.UtcNow;
            var code          = new Random().Next(0, 9999).ToString("0000");
            var identityTypes = new[] { IdentityType.PhoneAndPassword };
            var identity      = await _identitiesService.GetByKeyAndTypesAsync(phone, identityTypes, ct);

            var token = new IdentityToken
            {
                IdentityId         = identity.Id,
                Type               = IdentityTokenType.PhoneValidation,
                Value              = code,
                CreateDateTime     = now,
                ExpirationDateTime = now.AddMinutes(10),
                IpAddress          = ipAddress,
                UserAgent          = userAgent
            };

            var id = await _identityTokensService.CreateAsync(token, ct);

            var phoneWithPrefix = country.GetInternationalPhonePrefix() + phone;

            await SendCodeAsync(phoneWithPrefix, code);

            return(id);
        }
Esempio n. 2
0
        public async Task <Guid> SendMessageAsync(string key, string ipAddress, string userAgent, CancellationToken ct)
        {
            var now           = DateTime.UtcNow;
            var code          = Generator.GenerateAlphaNumericString(256);
            var identityTypes = IdentityTypeExtensions.TypesWithPassword;
            var identity      = await _identitiesService.GetByKeyAndTypesAsync(key, identityTypes, ct);

            var emailIdentity = await _identitiesService.GetByProfileIdAndTypeAsync(identity.ProfileId,
                                                                                    IdentityType.EmailAndPassword, ct);

            var token = new IdentityToken
            {
                IdentityId         = emailIdentity.Id,
                Type               = IdentityTokenType.PasswordReset,
                Value              = code,
                CreateDateTime     = now,
                ExpirationDateTime = now.AddDays(1),
                IpAddress          = ipAddress,
                UserAgent          = userAgent
            };

            var id = await _identityTokensService.CreateAsync(token, ct);

            await SendCodeAsync(emailIdentity.Key, id, code);

            return(id);
        }
Esempio n. 3
0
        public async Task <Guid> SendMessageAsync(string email, string ipAddress, string userAgent, CancellationToken ct)
        {
            var now           = DateTime.UtcNow;
            var code          = Generator.GenerateAlphaNumericString(256);
            var identityTypes = new[] { IdentityType.EmailAndPassword };
            var identity      = await _identitiesService.GetByKeyAndTypesAsync(email, identityTypes, ct);

            var token = new IdentityToken
            {
                IdentityId         = identity.Id,
                Type               = IdentityTokenType.EmailValidation,
                Value              = code,
                CreateDateTime     = now,
                ExpirationDateTime = now.AddDays(1),
                IpAddress          = ipAddress,
                UserAgent          = userAgent
            };

            var id = await _identityTokensService.CreateAsync(token, ct);

            await SendCodeAsync(email, id, code);

            return(id);
        }