Exemple #1
0
        /// <inheritdoc/>
        public async Task <IAuthenticationResponse> UnlockAccountAsync(UnlockAccountOptions unlockAccountOptions, CancellationToken cancellationToken = default)
        {
            var unlockAccountRequest = new UnlockAccountRequest()
            {
                FactorType = unlockAccountOptions.FactorType,
                RelayState = unlockAccountOptions.RelayState,
                Username   = unlockAccountOptions.Username,
            };

            var request = new HttpRequest
            {
                Uri     = $"/api/v1/authn/recovery/unlock",
                Payload = unlockAccountRequest,
            };

            if (!string.IsNullOrEmpty(unlockAccountOptions.UserAgent))
            {
                request.Headers["User-Agent"] = unlockAccountOptions.UserAgent;
            }

            if (!string.IsNullOrEmpty(unlockAccountOptions.XForwardedFor))
            {
                request.Headers["X-Forwarded-For"] = unlockAccountOptions.XForwardedFor;
            }

            return(await PostAsync <AuthenticationResponse>(request, cancellationToken).ConfigureAwait(false));
        }
Exemple #2
0
        public void Validate_GivenAllPropertiesAreValid_ExpectValidationSuccess()
        {
            var request = new UnlockAccountRequest
            {
                UserId = TestVariables.UserId,
            };
            var validator = new UnlockAccountRequest.Validator();
            var result    = validator.Validate(request);

            Assert.True(result.IsValid);
        }
Exemple #3
0
        public void Validate_GivenNameIsEmpty_ExpectValidationFailure()
        {
            var request = new UnlockAccountRequest
            {
                UserId = Guid.Empty,
            };
            var validator = new UnlockAccountRequest.Validator();
            var result    = validator.Validate(request);

            Assert.False(result.IsValid);
            Assert.Contains(
                result.Errors,
                failure => failure.PropertyName == "UserId");
        }
        /// <inheritdoc/>
        public async Task <IAuthenticationResponse> UnlockAccountAsync(UnlockAccountOptions unlockAccountOptions, CancellationToken cancellationToken = default(CancellationToken))
        {
            var unlockAccountRequest = new UnlockAccountRequest()
            {
                FactorType = unlockAccountOptions.FactorType,
                RelayState = unlockAccountOptions.RelayState,
                Username   = unlockAccountOptions.Username,
            };

            return(await PostAsync <AuthenticationResponse>(
                       new HttpRequest
            {
                Uri = $"/api/v1/authn/recovery/unlock",
                Payload = unlockAccountRequest,
            }, cancellationToken).ConfigureAwait(false));
        }
        public async Task <IActionResult> UnlockAccount([FromBody] UnlockAccountRequest request)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.Json(new UnlockAccountResponse(false)));
            }

            var maybe = this._currentAuthenticatedUserProvider.CurrentAuthenticatedUser;

            if (maybe.HasNoValue)
            {
                return(this.Json(new UnlockAccountResponse(false)));
            }

            if (maybe.Value.UserId == request.UserId)
            {
                return(this.Json(new UnlockAccountResponse(false)));
            }

            var result = await this._mediator.Send(new UnlockAccountCommand(request.UserId));

            return(this.Json(new UnlockAccountResponse(result.IsSuccess)));
        }