<commit_before>__author__ = '<NAME>'

import caleydo_server.plugin as p
import sys

class User(object):
  def __init__(self, id):
    self.id = id
    self.name = 'anonymous'
    self.roles = ['anonymous']

  def get_id(self):
    try:
        return unicode(self.id)  # python 2
    except NameError:
        return str(self.id)  # python 3

  @property
  def is_authenticated(self):
    return False

  @property
  def is_active(self):
    return False

  @property
  def is_anonymous(self):
    return self.name == 'anonymous'

  def has_role(self, role):
    return role in self.roles

  def __eq__(self, other):
    '''
    Checks the equality of two `UserMixin` objects using `get_id`.
    '''
    if isinstance(other, User):
      return self.get_id() == other.get_id()
    return NotImplemented

  def __ne__(self, other):
    '''
    Checks the inequality of two `UserMixin` objects using `get_id`.
    '''
    equal = self.__eq__(other)
    if equal is NotImplemented:
      return NotImplemented
    return not equal

  if sys.version_info[0] != 2:  # pragma: no cover
    # Python 3 implicitly set __hash__ to None if we override __eq__
    # We set it back to its default implementation
    __hash__ = object.__hash__

class SecurityManager(object):
  """
  a basic security manager
  """
  def __init__(self):
    pass

  def login_required(self, f):
    return f

  def login(self, username, extra_fields = {}):
    """logs the given user in
    :returns the logged in user object or None if login failed
    """
    return User('')

  def logout(self):
    """
    logs the current logged in user out
    """
    pass

  @property
  def current_user(self):
    """
    :returns the current logged in user
    """
    return User('')

  def is_authenticated(self):
    """whether the current user is authenticated
    """
    return self.current_user.is_authenticated

  def has_role(self, role):
    """whether the current use has the role
    """
    return self.current_user.has_role(role)

  def init_app(self, app):
    pass

  def add_login_routes(self, app):
    pass

class DummyManager(SecurityManager):
  """
  a dummy implementation of the security manager where everyone is authenticated
  """

  def is_authenticated(self):
    return True

  def has_role(self, role):
    return True

_manager = None
def manager():
  """
  :return: the security manager
  """
  global _manager
  if _manager is None:
    _manager = p.lookup('security_manager')
    if _manager is None:
      _manager = DummyManager()
  return _manager

def login_required(f):
  """
  Decorator for views that require login.
  """
  return manager().login_required(f)

def init_app(app):
  """
  initializes this app by for login mechanism
  :param app:
  :return:
  """
  manager().init_app(app)

def add_login_routes(app):
  """
  initializes this flask for providing access to /login and /logout
  :param app:<commit_msg>shortcut to current logged in username<commit_after>__author__ = '<NAME>'

import caleydo_server.plugin as p
import sys

class User(object):
  def __init__(self, id):
    self.id = id
    self.name = 'anonymous'
    self.roles = ['anonymous']

  def get_id(self):
    try:
        return unicode(self.id)  # python 2
    except NameError:
        return str(self.id)  # python 3

  @property
  def is_authenticated(self):
    return False

  @property
  def is_active(self):
    return False

  @property
  def is_anonymous(self):
    return self.name == 'anonymous'

  def has_role(self, role):
    return role in self.roles

  def __eq__(self, other):
    '''
    Checks the equality of two `UserMixin` objects using `get_id`.
    '''
    if isinstance(other, User):
      return self.get_id() == other.get_id()
    return NotImplemented

  def __ne__(self, other):
    '''
    Checks the inequality of two `UserMixin` objects using `get_id`.
    '''
    equal = self.__eq__(other)
    if equal is NotImplemented:
      return NotImplemented
    return not equal

  if sys.version_info[0] != 2:  # pragma: no cover
    # Python 3 implicitly set __hash__ to None if we override __eq__
    # We set it back to its default implementation
    __hash__ = object.__hash__

class SecurityManager(object):
  """
  a basic security manager
  """
  def __init__(self):
    pass

  def login_required(self, f):
    return f

  def login(self, username, extra_fields = {}):
    """logs the given user in
    :returns the logged in user object or None if login failed
    """
    return User('')

  def logout(self):
    """
    logs the current logged in user out
    """
    pass

  @property
  def current_user(self):
    """
    :returns the current logged in user
    """
    return User('')

  def is_authenticated(self):
    """whether the current user is authenticated
    """
    return self.current_user.is_authenticated

  def has_role(self, role):
    """whether the current use has the role
    """
    return self.current_user.has_role(role)

  def init_app(self, app):
    pass

  def add_login_routes(self, app):
    pass

class DummyManager(SecurityManager):
  """
  a dummy implementation of the security manager where everyone is authenticated
  """

  def is_authenticated(self):
    return True

  def has_role(self, role):
    return True

_manager = None
def manager():
  """
  :return: the security manager
  """
  global _manager
  if _manager is None:
    _manager = p.lookup('security_manager')
    if _manager is None:
      _manager = DummyManager()
  return _manager

def current_username():
  u = manager().current_user
  return u.user if hasattr(u, 'name') else 'Anonymous'

def login_required(f):
  """
  Decorator for views that require login.
  """
  return manager().login_required(f)

def init_app(app):
  """
  initializes this app by for login mechanism
  :param app:
  :return:
  """
  manager().init_app(app)

def add_login_routes(app):
  """
  initializes this flask for providing access to /login and /logout
  :param app:
{'fraction_non_alphanumeric': 0.101606963508537, 'fraction_numerical': 0.0016739203213927017, 'mean_word_length': 3.0952707333790266, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3651579', 'n_tokens_mistral': 1911, 'n_tokens_neox': 1845, 'n_words': 605}