Beispiel #1
0
        public async Task <SetNewPasswordResponse> SetNewPasswordAsync(
            Guid tokenId,
            string code,
            string newPassword,
            CancellationToken ct)
        {
            var token = await _identityTokensService.GetAsync(tokenId, ct);

            var isValidToken = IsValidToken(token, code);

            if (!isValidToken)
            {
                return(new SetNewPasswordResponse(true));
            }

            var identity = await _identitiesService.GetAsync(token.IdentityId, ct);

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

            await _identitiesService.ChangePasswordByProfileIdAsync(identity.ProfileId, newPassword, ct);

            return(new SetNewPasswordResponse(false));
        }
Beispiel #2
0
        public async Task <PostChangePasswordResponse> ChangeAsync(
            string country,
            string key,
            string oldPassword,
            string newPassword,
            CancellationToken ct)
        {
            var identityTypes     = IdentityTypeExtensions.TypesWithPassword;
            var phoneIdentityType = new[] { IdentityType.PhoneAndPassword };

            var identity = await _identitiesService.GetVerifiedByKeyAndTypesAsync(key, identityTypes, ct) ??
                           await _identitiesService.GetVerifiedByKeyAndTypesAsync(key.GetPhoneWithoutPrefixes(country),
                                                                                  phoneIdentityType, ct);

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

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

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

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

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

            await _identitiesService.ChangePasswordByProfileIdAsync(profile.Id, newPassword, ct);

            return(new PostChangePasswordResponse(false));
        }