# Path: ddserver/utils/deps.py
# def require(**requirements):
#   ''' Decorator to inject requirements into a function.
# 
#       The decorated function is called with a named argument for each
#       specified requirement containing the exported instances.
#   '''
# 
#   exports = {name : Export.load(requirement)
#              for name, requirement
#              in requirements.iteritems()}
# 
#   def wrapper(func):
#     def wrapped(*args, **kwargs):
#       # Update the keyword arguments with the required instances
#       kwargs.update({name : export.instance
#                      for name, export
#                      in exports.iteritems()
#                      if name not in kwargs})
# 
#       return func(*args,
#                   **kwargs)
# 
#     wrapped.__name__ = func.__name__
# 
#     return wrapped
#   return wrapper
# 
# Path: ddserver/interface/user.py
# class UserManager(object):
#   def __getitem__(self,
#                   key,
#                   db):
#   def login(self,
#             session,
#             messages,
#             username,
#             password):
#   def logout(self,
#              session,
#              messages):
#   def generate_authcode(self, username, db):
#   def authorized(self, session):
# def authorized(admin = False):
#   def wrapper(func):
#     def wrapped(users,
#                 messages,
#                 *args,
#                 **kwargs):
# def authorized_by_code():
#   def wrapper(func):
#     def wrapped(users,
#                 messages,
#                 *args,
#                 **kwargs):
# def template_auth(templates):
#   def __(users):


import bottle
from ddserver.web import route
from ddserver.utils.deps import require
from ddserver.interface.user import authorized_admin
from ddserver.interface import validation
from ddserver.interface.validation import validate
         templates = 'ddserver.interface.template:TemplateManager')
def get_users(user,
              db,
              templates,
              mode = 'all'):
  ''' Display a list of users that are waiting for account activation. '''

  if mode == 'admins':
      where = 'WHERE `admin` = 1'

  elif mode == 'inactive':
      where = 'WHERE `active` = NULL'

  else:
      where = 'WHERE 1 = 1'

  with db.cursor() as cur:
    cur.execute('''
        SELECT *
        FROM `users`
    ''' + where)
    users = cur.fetchall()

  return templates['users.html'](users = users,
                                 mode = mode)



@route('/admin/users/add', method = 'GET')
@authorized_admin()

# Path: ddserver/utils/deps.py
# def require(**requirements):
#   ''' Decorator to inject requirements into a function.
# 
#       The decorated function is called with a named argument for each
#       specified requirement containing the exported instances.
#   '''
# 
#   exports = {name : Export.load(requirement)
#              for name, requirement
#              in requirements.iteritems()}
# 
#   def wrapper(func):
#     def wrapped(*args, **kwargs):
#       # Update the keyword arguments with the required instances
#       kwargs.update({name : export.instance
#                      for name, export
#                      in exports.iteritems()
#                      if name not in kwargs})
# 
#       return func(*args,
#                   **kwargs)
# 
#     wrapped.__name__ = func.__name__
# 
#     return wrapped
#   return wrapper
# 
# Path: ddserver/interface/user.py
# class UserManager(object):
#   def __getitem__(self,
#                   key,
#                   db):
#   def login(self,
#             session,
#             messages,
#             username,
#             password):
#   def logout(self,
#              session,
#              messages):
#   def generate_authcode(self, username, db):
#   def authorized(self, session):
# def authorized(admin = False):
#   def wrapper(func):
#     def wrapped(users,
#                 messages,
#                 *args,
#                 **kwargs):
# def authorized_by_code():
#   def wrapper(func):
#     def wrapped(users,
#                 messages,
#                 *args,
#                 **kwargs):
# def template_auth(templates):
#   def __(users):


# Path: ddserver/interface/pages/admin/users.py
import bottle
from ddserver.web import route
from ddserver.utils.deps import require
from ddserver.interface.user import authorized_admin
from ddserver.interface import validation
from ddserver.interface.validation import validate

         templates = 'ddserver.interface.template:TemplateManager')
def get_users(user,
              db,
              templates,
              mode = 'all'):
  ''' Display a list of users that are waiting for account activation. '''

  if mode == 'admins':
      where = 'WHERE `admin` = 1'

  elif mode == 'inactive':
      where = 'WHERE `active` = NULL'

  else:
      where = 'WHERE 1 = 1'

  with db.cursor() as cur:
    cur.execute('''
        SELECT *
        FROM `users`
    ''' + where)
    users = cur.fetchall()

  return templates['users.html'](users = users,
                                 mode = mode)



@route('/admin/users/add', method = 'GET')
@authorized_admin()

@require(templates = 'ddserver.interface.template:TemplateManager')