Exemplo n.º 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));
        }
 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);
 }