Beispiel #1
0
  def join_player(self, user, password, invite = False):
    if user not in self.user_to_player:
      if self.is_password_protected and (password == None or len(password) <= 0 or lib.pwcrypt(password) != self.password):
        raise lib.play.WrongPasswordError()

      if len(self.players) >= self.limit:
        raise lib.play.AlreadyStartedError()

      player = self.player_class(self, user)

      self.players.push(player)

    else:
      player = self.user_to_player[user]

      if player.confirmed == True:
        raise lib.play.AlreadyJoinedError()

      player.confirmed = True

    if invite:
      player.confirmed = False

    else:
      hlib.events.trigger('game.PlayerJoined', self, game = self, user = player.user)

      # pylint: disable-msg=W0201
      self.last_pass = hruntime.time

      if len(self.confirmed_players) == self.limit:
        self.begin()

    return player
Beispiel #2
0
  def test_random(self):
    s = randstr()
    cs = hashlib.md5(s.encode('ascii', 'replace')).hexdigest()

    EQ('Hash {actual} does not match raw library value {expected}',
       cs,
       lib.pwcrypt(s))
Beispiel #3
0
  def loginas(self, username = None, password = None, loginas = None):
    if username not in hruntime.dbroot.users:
      raise hlib.error.InvalidAuthError(msg = 'Invalid username or password')

    u = hruntime.dbroot.users[username]

    if not u.is_admin and not u.is_autoplayer:
      raise hlib.error.AccessDeniedError(msg = 'You are not admin')

    if loginas not in hruntime.dbroot.users:
      raise hlib.error.NoSuchUserError(loginas)

    if u.password != lib.pwcrypt(password):
      raise hlib.error.InvalidAuthError(msg = 'Invalid username or password')

    a = hruntime.dbroot.users[loginas]

    hlib.auth.start_session(user = a, tainted = u)

    raise hlib.http.Redirect('/home/')
Beispiel #4
0
  def login(self, username = None, password = None):
    if username not in hruntime.dbroot.users:
      raise hlib.error.InvalidAuthError(msg = 'Invalid username or password')

    u = hruntime.dbroot.users[username]

    if u.password != lib.pwcrypt(password):
      raise hlib.error.InvalidAuthError(msg = 'Invalid username or password')

    if hruntime.dbroot.server.maintenance_mode == True and u.maintenance_access != True:
      if 'Referer' in hruntime.request.headers and hruntime.request.headers['Referer'].endswith('/login/'):
        raise hlib.http.Redirect('/maintenance/')

      raise hlib.error.AccessDeniedError(msg = 'Sorry, you are not allowed to log in')

    hlib.auth.start_session(user = u)

    hlib.events.trigger('system.UserLoggedIn', hruntime.dbroot.server, user = u)

    if u.is_on_vacation:
      raise hlib.http.Redirect('/vacation/')

    raise hlib.http.Redirect('/home/')
Beispiel #5
0
  def dbinit(self, root):
    from testconfig import config

    import lib
    import lib.datalayer

    root['root'] = lib.datalayer.Root()
    root = root['root']

    # Test user
    root.users[config['web']['username']] = lib.datalayer.User(config['web']['username'], lib.pwcrypt(config['web']['password']), config['web']['email'])

    # Additional users
    for i in range(0, 20):
      username = '******' % i
      root.users[username] = lib.datalayer.User(username, lib.pwcrypt(''), '*****@*****.**')

    # Trumpet
    import lib.trumpet
    trumpet = {'subject': '', 'text': ''}
    __setter = lambda cls: getattr(root.trumpet, cls.__name__).update(trumpet)
    __setter(lib.trumpet.PasswordRecoveryMail)
    __setter(lib.trumpet.Board)
    __setter(lib.trumpet.VacationTermination)