Esempio n. 1
0
        public async Task <Response <SignUpStepDTO> > SignUpConfirm(Guid userId, string code)
        {
            var step = await _repository.GetRegistrationStepByUserId(userId);

            var stepValidate = ValidateStep(step, RegistrationStep.EmailConfirmed);

            if (!stepValidate.IsSuccess)
            {
                return(stepValidate);
            }

            var request = await _confirmEmailService.GetRequest(userId, code);

            if (!request.IsSuccess)
            {
                var errorResponse = (ErrorResponse <UserConfirmEmailRequestDTO>)request;

                return(new ErrorResponse <SignUpStepDTO>
                {
                    Message = errorResponse.Message,
                    Code = errorResponse.Code,
                    Errors = errorResponse.Errors,
                    HttpStatusCode = errorResponse.HttpStatusCode
                });
            }

            if (request.Data == null || request.Data?.IsDeleted == true)
            {
                return(new ForbiddenErrorResponse <SignUpStepDTO>(new []
                {
                    new Error
                    {
                        Code = ErrorCodes.Security.ConfirmationCodeInvalid,
                        Message = ErrorMessages.Security.ConfirmationCodeInvalid
                    }
                }));
            }

            // TODO: Check lifetime of request if needed

            await _confirmEmailService.ActivateAllRequests(userId);

            step = await _repository.SetRegistrationStep(userId, RegistrationStep.EmailConfirmed);

            return(new Response <SignUpStepDTO>
            {
                Data = new SignUpStepDTO
                {
                    RegistrationStep = _mapper.Map <UserRegistrationStepModel, UserRegistrationStepDTO>(step)
                }
            });
        }
Esempio n. 2
0
        public async Task <Response <SignUpStepDTO> > GetRegistrationStep(Guid userId)
        {
            var entity = await _repository.GetRegistrationStepByUserId(userId);

            if (entity == null)
            {
                return(new BusinessConflictErrorResponse <SignUpStepDTO>(new []
                {
                    new Error
                    {
                        Code = ErrorCodes.Business.UserDoesNotExists,
                        Message = ErrorMessages.Business.UserDoesNotExists,
                        Field = ErrorFields.User.Token
                    }
                }));
            }

            var result = _mapper.Map <UserRegistrationStepModel, SignUpStepDTO>(entity);

            return(new Response <SignUpStepDTO>
            {
                Data = result
            });
        }