Example #1
0
        public async Task <Guid> RegisterAsync(
            string country,
            string surname,
            string name,
            string login,
            string email,
            string phone,
            string password,
            string ipAddress,
            string userAgent,
            CancellationToken ct)
        {
            var profile = new Profile
            {
                Surname = surname,
                Name    = name
            };

            profile.Id = await _profilesService.CreateAsync(profile, ct);

            var passwordHash = PasswordUtils.ToPasswordHash(password);

            await _registrationIdentityService.CreateLoginIdentityAsync(profile.Id, login, passwordHash, ct);

            await _registrationIdentityService.CreateEmailIdentityAsync(profile.Id, email, passwordHash, ct);

            await _registrationIdentityService.CreatePhoneIdentityAsync(profile.Id, phone, passwordHash, ct);

            await _emailConfirmationService.SendMessageAsync(email, ipAddress, userAgent, ct);

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

            return(tokenId);
        }
        public async Task <PostChangeEmailResponse> ChangeAsync(
            string oldEmail,
            string newEmail,
            string password,
            string ipAddress,
            string userAgent,
            CancellationToken ct)
        {
            var identityTypes = new[] { IdentityType.EmailAndPassword };
            var identity      = await _identitiesService.GetByKeyAndTypesAsync(oldEmail, identityTypes, ct);

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

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

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

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

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

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

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

            await _emailConfirmationService.SendMessageAsync(newEmail, ipAddress, userAgent, ct);

            return(new PostChangeEmailResponse(false));
        }