Ejemplo n.º 1
0
        public async Task <UserDtoWithoutPassword> ActivateUser(UserDtoActivation activationUserDetails)
        {
            var user = await _userRepository.FindByFirstAsync(u => u.Id == activationUserDetails.Id);

            if (user == null)
            {
                throw new ResourceNotFoundException("Activation user not found!");
            }

            if (user.ActivationCode != activationUserDetails.Code)
            {
                throw new BadRequestException("Wrong activation code!");
            }

            if (user.IsActive)
            {
                throw new BadRequestException("User already activated");
            }

            user.IsActive = true;

            var resultUser = _userRepository.Edit(user);
            await _userRepository.SaveAsync();

            await this._blogRepository.CreateBlogForUser(resultUser);

            var userWithoutPassword = _mapper.Map <User, UserDtoWithoutPassword> (resultUser);

            return(userWithoutPassword);
        }
Ejemplo n.º 2
0
        public async Task <UserDtoWithoutPassword> ActivateUser(UserDtoActivation activationUserDetails)
        {
            var user = await _userRepository.GetOneByAsync(u => u.Id == activationUserDetails.Id);

            if (user == null)
            {
                throw new UserNotFoundException("Activation user not found!");
            }

            if (user.ActivationCode != activationUserDetails.Code)
            {
                throw new BadRequestException("Wrong activation code!");
            }

            user.IsActive = true;

            var resultUser = _userRepository.Update(user);
            await _userRepository.SaveAsync();

            var userWithoutPassword = _mapper.Map <User, UserDtoWithoutPassword> (resultUser);

            return(userWithoutPassword);
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Activate([FromBody] UserDtoActivation activationUserDetails)
        {
            await _userService.ActivateUser(activationUserDetails);

            return(Ok());
        }