Пример #1
0
        public async Task Delete(Guid userUuid)
        {
            DisabledUserDto disabledUser = await _context.DisabledUser
                                           .FirstOrDefaultAsync(du => du.UserUuid == userUuid);

            _context.DisabledUser.Remove(disabledUser);
            await _context.SaveChangesAsync();
        }
Пример #2
0
        /// <summary>
        /// Saves the user in the database
        /// </summary>
        /// <param name="user">The form data the user send</param>
        public async Task Register(User user)
        {
            if (!await UserModelValid(user) || user.Password.Length < 8)
            {
                throw new UnprocessableException();
            }

            bool usernameOrEmailInUse = await _userDal.Exists(user.Username, user.Email);

            if (usernameOrEmailInUse)
            {
                throw new DuplicateNameException();
            }

            bool databaseContainsUsers = await _userDal.Any();

            var userDto = _mapper.Map <UserDto>(user);

            userDto.AccountRole = databaseContainsUsers ? AccountRole.User : AccountRole.SiteAdmin;
            userDto.Uuid        = Guid.NewGuid();

            var disabledUserDto = new DisabledUserDto
            {
                Reason   = DisableReason.EmailVerificationRequired,
                UserUuid = userDto.Uuid,
                Uuid     = Guid.NewGuid()
            };

            var activationDto = new ActivationDto
            {
                Code     = Guid.NewGuid().ToString(),
                UserUuid = userDto.Uuid,
                Uuid     = Guid.NewGuid()
            };

            await _disabledUserDal.Add(disabledUserDto);

            await _activationDal.Add(activationDto);

            var userRabbitMq = _mapper.Map <UserRabbitMqSensitiveInformation>(user);

            userRabbitMq.Uuid        = userDto.Uuid;
            userRabbitMq.AccountRole = databaseContainsUsers ? AccountRole.User : AccountRole.SiteAdmin;

            _publisher.Publish(userRabbitMq, RabbitMqRouting.AddUser, RabbitMqExchange.AuthenticationExchange);

            await _userDal.Add(userDto);

            SendActivationEmail(userDto, activationDto);
        }
Пример #3
0
 private static bool DisabledUserModelValid(DisabledUserDto disabledUser)
 {
     return(disabledUser.Reason != DisableReason.Undefined &&
            disabledUser.UserUuid != Guid.Empty &&
            disabledUser.Uuid != Guid.Empty);
 }
Пример #4
0
        public async Task Add(DisabledUserDto disabledUser)
        {
            await _context.DisabledUser.AddAsync(disabledUser);

            await _context.SaveChangesAsync();
        }