示例#1
0
        public Task <bool> Handle(AuthorizeNewAccountRequest request, CancellationToken cancellationToken)
        {
            using (_threadContextSessionProvider.CreateSessionScope())
            {
                var user = _botUserRepository.ListBySpecification(new UndeletedEntities <BotUser>())
                           .FirstOrDefault(x =>
                                           !string.IsNullOrEmpty(x.PasswordHash) &&
                                           BCrypt.Net.BCrypt.Verify(request.Password, x.PasswordHash));
                if (user == null)
                {
                    return(Task.FromResult(false));
                }

                if (user.Id == request.CurrentUserId)
                {
                    return(Task.FromResult(true));
                }
                var currentUser = _botUserRepository.Get(request.CurrentUserId);
                foreach (var currentUserUserAccount in currentUser.UserAccounts)
                {
                    currentUserUserAccount.User = user;
                    user.UserAccounts.Add(currentUserUserAccount);
                }

                _botUserRepository.Save(user);
                currentUser.UserAccounts.Clear();
                _botUserRepository.Save(currentUser);
                _botUserRepository.Delete(currentUser);
            }
            return(Task.FromResult(true));
        }
示例#2
0
        public Task <Unit> Handle(RegisterRequest request, CancellationToken cancellationToken)
        {
            using (_threadContextSessionProvider.CreateSessionScope())
            {
                var users = _botUserRepository.ListBySpecification(new UndeletedEntities <BotUser>()).ToList();
                if (users.Count() > MaxUsersCount)
                {
                    throw new ArgumentOutOfRangeException("—оздано максимальное количество пользователей");
                }

                var user = GetUserByCommunicator(request.Communicator, users);

                if (user == null)
                {
                    user = new BotUser()
                    {
                        Id           = Guid.NewGuid(),
                        FirstName    = request.FirstName,
                        LastName     = request.LastName,
                        Role         = EUserRole.User,
                        UserAccounts = new List <BaseAccount>(),
                        PasswordHash = BCrypt.Net.BCrypt.HashPassword(request.Password)
                    };
                    user.UserAccounts.Add(GetAccount(request.Communicator, user));

                    _logger.Info("User added");
                }
                else
                {
                    user.FirstName = request.FirstName;
                    user.LastName  = request.LastName;
                    if (user.Role == EUserRole.UnregisteredUser)
                    {
                        user.Role = EUserRole.User;
                    }
                    user.PasswordHash = BCrypt.Net.BCrypt.HashPassword(request.Password);
                    _logger.Info("User updated");
                }

                _botUserRepository.Save(user);
            }
            return(Unit.Task);
        }
 public Task <Unit> Handle(BindUserToPlayerRequest request, CancellationToken cancellationToken)
 {
     using (_threadContextSessionProvider.CreateSessionScope())
     {
         var user = _botUserRepository.Get(request.UserId);
         user.Role = EUserRole.Player;
         _botUserRepository.Save(user);
         _playerRepository.Save(new Player()
         {
             Id   = Guid.NewGuid(),
             User = user,
             ParticipationRatio = request.ParticipationRatio,
             IsActive           = request.IsActive,
             SkillValue         = request.SkillValue
         });
         _logger.Info($"[{user.Id}]: Player added");
     }
     return(Unit.Task);
 }
        public Task <BotUser> Handle(AuthorizeRequest request, CancellationToken cancellationToken)
        {
            using (_threadContextSessionProvider.CreateSessionScope())
            {
                var users = _botUserRepository.ListBySpecification(new UndeletedEntities <BotUser>());
                var user  = GetUserByCommunicator(request.Communicator,
                                                  _botUserRepository.ListBySpecification(new UndeletedEntities <BotUser>()));

                if (user == null)
                {
                    user = new BotUser()
                    {
                        Id   = Guid.NewGuid(),
                        Role = EUserRole.UnregisteredUser
                    };
                    user.UserAccounts.Add(GetAccount(request.Communicator, user));

                    _logger.Info("User added");
                    _botUserRepository.Save(user);
                }

                return(Task.FromResult(user));
            }
        }