Ejemplo n.º 1
0
        public AuthenticationResponse Authenticate(ISession session, AuthenticationRequest request)
        {
            var response = request.CreateResponse<AuthenticationResponse>();
            if (_settings.IsServerBusy)
            {
                response.Result = AuthenticationResponseType.ServerIsBusy;
                return response;
            }
            
            response.Result = AuthenticationResponseType.Success;

            using (var uow = UnitOfWorkFactory.Create())
            {
                var user = uow.UsersRepository.FirstMatching(UserSpecification.NameAndPassword(request.Name, request.Password));
                if (user == null)
                {
                    response.Result = AuthenticationResponseType.InvalidNameOrPassword;
                }
                else
                {
                    if (user.IsBanned)
                    {
                        response.Result = AuthenticationResponseType.Banned;
                    }
                    else if (user.Huid != request.Huid)
                    {
                        user.ChangeHuid(request.Huid);
                    }
                }
                
                uow.Commit();
                
                if (response.Result == AuthenticationResponseType.Success)
                {
                    //yes, it's ugly and looks like we have leaking abstraction (we do actually) but IMO it's the most harmless way to load linked data
                    user.Friends.Count();
                    user.PersonalBlackList.Count();
                    session.SetUser(user);
                    response.User = user.ProjectedAs<UserDto>();
                }
            }
            return response;
        }
		public Task<AuthenticationResponse> Authenticate(AuthenticationRequest request)
		{
			return ConnectionManager.SendRequestAndWaitResponse<AuthenticationResponse>(request);
		}