Example #1
0
        public async Task CreateEmailIdentityAsync(
            Guid profileId,
            string email,
            string passwordHash,
            CancellationToken ct)
        {
            var emailIdentity = new Identities.Models.Identity
            {
                ProfileId    = profileId,
                Type         = IdentityType.EmailAndPassword,
                Key          = email,
                PasswordHash = passwordHash,
                IsVerified   = _webHostEnvironment.IsDevelopment()
            };

            await _identitiesService.CreateAsync(emailIdentity, ct);
        }
Example #2
0
        public async Task CreatePhoneIdentityAsync(
            Guid profileId,
            string phone,
            string passwordHash,
            CancellationToken ct)
        {
            var phoneIdentity = new Identities.Models.Identity
            {
                ProfileId    = profileId,
                Type         = IdentityType.PhoneAndPassword,
                Key          = phone,
                PasswordHash = passwordHash,
                IsVerified   = false
            };

            await _identitiesService.CreateAsync(phoneIdentity, ct);
        }
Example #3
0
        public async Task CreateLoginIdentityAsync(
            Guid profileId,
            string login,
            string passwordHash,
            CancellationToken ct)
        {
            var loginIdentity = new Identities.Models.Identity
            {
                ProfileId    = profileId,
                Type         = IdentityType.LoginAndPassword,
                Key          = login,
                PasswordHash = passwordHash,
                IsVerified   = true
            };

            await _identitiesService.CreateAsync(loginIdentity, ct);
        }
        public async Task <PostChangePhoneResponse> ChangeAsync(
            string country,
            string oldPhone,
            string newPhone,
            string password,
            string ipAddress,
            string userAgent,
            CancellationToken ct)
        {
            var identityTypes = new[] { IdentityType.PhoneAndPassword };
            var identity      = await _identitiesService.GetByKeyAndTypesAsync(oldPhone, identityTypes, ct);

            if (identity == null)
            {
                return(new PostChangePhoneResponse(true));
            }

            var profile = await _profilesService.GetAsync(identity.ProfileId, ct);

            if (profile == null)
            {
                return(new PostChangePhoneResponse(true));
            }

            var isPasswordCorrect = _identitiesService.IsPasswordCorrect(identity, password);

            if (!isPasswordCorrect)
            {
                return(new PostChangePhoneResponse(true));
            }

            var newIdentity = new Identities.Models.Identity
            {
                Key = newPhone
            };

            await _identitiesService.UpdateAsync(identity, newIdentity, ct);

            var tokenId = await _phoneConfirmationService.SendMessageAsync(country, newPhone, ipAddress, userAgent, ct);

            return(new PostChangePhoneResponse(tokenId));
        }