Esempio n. 1
0
class TestSQLTABLE(unittest.TestCase):
    def setUp(self):
        request = Request(env={})
        request.application = "a"
        request.controller = "c"
        request.function = "f"
        request.folder = "applications/admin"
        response = Response()
        session = Session()
        T = translator("", "en")
        session.connect(request, response)
        from gluon.globals import current

        current.request = request
        current.response = response
        current.session = session
        current.T = T
        self.db = DAL(DEFAULT_URI, check_reserved=["all"])
        self.auth = Auth(self.db)
        self.auth.define_tables(username=True, signature=False)
        self.db.define_table("t0", Field("tt"), self.auth.signature)
        self.auth.enable_record_versioning(self.db)
        # Create a user
        self.db.auth_user.insert(
            first_name="Bart",
            last_name="Simpson",
            username="******",
            email="*****@*****.**",
            password="******",
            registration_key=None,
            registration_id=None,
        )

        self.db.commit()
Esempio n. 2
0
class TestSQLTABLE(unittest.TestCase):
    def setUp(self):
        request = Request(env={})
        request.application = 'a'
        request.controller = 'c'
        request.function = 'f'
        request.folder = 'applications/admin'
        response = Response()
        session = Session()
        T = translator('', 'en')
        session.connect(request, response)
        from gluon.globals import current
        current.request = request
        current.response = response
        current.session = session
        current.T = T
        self.db = DAL(DEFAULT_URI, check_reserved=['all'])
        self.auth = Auth(self.db)
        self.auth.define_tables(username=True, signature=False)
        self.db.define_table('t0', Field('tt'), self.auth.signature)
        self.auth.enable_record_versioning(self.db)
        # Create a user
        self.db.auth_user.insert(first_name='Bart',
                                 last_name='Simpson',
                                 username='******',
                                 email='*****@*****.**',
                                 password='******',
                                 registration_key=None,
                                 registration_id=None)

        self.db.commit()
Esempio n. 3
0
    def _auth(self):
        """Create a auth instance. """

        auth = Auth(self.environment, self.db)  # authentication/authorization
        auth.settings.hmac_key = self.local_settings.hmac_key
        auth.define_tables()                    # creates all needed tables
        if self.settings_loader:
            self.settings_loader.import_settings(group='auth',
                    storage=auth.settings)
        auth.settings.mailer = self.mail
        auth.settings.verify_email_onaccept = self.verify_email_onaccept
        host = ''
        request = self.environment['request']
        if 'wsgi' in request.keys():
            if 'environ' in request['wsgi'].keys():
                host = request['wsgi']['environ']['HTTP_HOST']
        elif 'env' in request.keys():
            host = request.env.http_post
        else:
            LOG.warn("No host for verify_email and reset_password links")
        auth.messages.verify_email = 'Click on the link http://' + host \
            + '/' + request.application \
            + '/default/user/verify_email/%(key)s to verify your email'
        auth.messages.reset_password = '******' + host \
            + '/' + request.application \
            + '/default/user/reset_password/%(key)s to reset your password'
        auth.signature = self.db.Table(self.db, 'auth_signature',
                              Field('created_on', 'datetime',
                                    default=request.now,
                                    writable=False, readable=False),
                              Field('updated_on', 'datetime',
                                    default=request.now, update=request.now,
                                    writable=False, readable=False))
        return auth
Esempio n. 4
0
    def init_auth(self):
        """ Auth """

        request = current.request
        settings = self.app_settings

        auth = Auth(self.db)
        self.auth = auth
        auth.settings.hmac_key = settings.security_key  # before define_tables()

        #If I use janrain to login, disable register.
        if settings.register_method in ['Disabled', 'Janrain']:
            # disable register
            auth.settings.actions_disabled.append('register')

        # If I use Recaptcha to register.
        if settings.register_method in ['Recaptcha']:
            auth.settings.captcha = Recaptcha(request,
                                                settings.recaptcha_public_key,
                                                settings.recaptcha_private_key)

        self.auth_def()  # the auth definition

        # creates all needed tables
        auth.define_tables(username=True, migrate=settings.migrate)
        auth.settings.mailer = self.mail  # for user email verification

        if settings.register_method in ['None', 'Recaptcha', 'Approval']:
            auth.settings.registration_requires_verification = False
        else:
            auth.settings.registration_requires_verification = True

        if settings.register_method in ['Approval']:
            auth.settings.registration_requires_approval = True
        else:
            auth.settings.registration_requires_approval = False

        auth.settings.reset_password_requires_verification = True

        if settings.register_method in ['Janrain']:
            base_http = 'http://' + str(request.env.http_host)
            auth.settings.actions_disabled = ['register',
                                              'change_password',
                                              'request_reset_password']
            auth.settings.login_form = RPXAccount(request,
                                            api_key=settings.janrain_api_key,
                                            domain=settings.janrain_domain,
                                            url=base_http + \
                                            '/%s/default/user/login' % \
                                            request.application)

        auth.messages.verify_email = settings.verify_email
        auth.messages.reset_password = settings.reset_password

        return auth
Esempio n. 5
0
class AdminUiConnect(object):
  
  def __init__(self, ui):
    self.ui = ui
  
  def auth_ini(self, controller,use_username=True,reset_password=False,register=False):
    self.auth = Auth(self.ui.db, controller=controller, function="login")
    self.auth.settings.extra_fields[self.auth.settings.table_user_name]= [
      Field('agree','boolean', default=True,
        label='I agree to the Terms and Conditions',
        requires=IS_NOT_EMPTY(error_message='You must agree this!'))
    ]
    self.auth.define_tables(username=use_username, migrate=False, fake_migrate=False)
    self.auth.settings.remember_me_form = False
    self.auth.settings.reset_password_requires_verification = True
    if not reset_password:
      self.auth.settings.actions_disabled.append('request_reset_password')
    if not register:
      self.auth.settings.actions_disabled.append('register')
    self.auth.settings.register_next = URL('index',**{'user_signature': True})
    self.auth.settings.change_password_next = URL('index',**{'user_signature': True})
    self.auth.settings.formstyle = 'table3cols'
    self.auth.settings.allow_basic_login=True
    self.auth.settings.login_onaccept.append(self.login_onaccept)
    return self.auth
  
  def check_alias(self,alias):
    import re
    return re.sub(r'[^a-zA-Z0-9_]','', alias)
  
  def delete_data(self, table, ref_id=None, log_enabled=True):
    try:
      if self.ui.db[table].has_key("deleted"):
        self.ui.db(self.ui.db[table]["id"]==ref_id).update(**{"deleted":True})
      else:
        self.ui.db(self.ui.db[table].id==ref_id).delete()
      if log_enabled and self.ui.db.has_key("auth_event"):
        values={"time_stamp":self.ui.request.now, "client_ip":self.ui.request.client,
                "user_id":self.ui.session.auth.user.id, "origin":self.auth.settings.controller, 
                "description":"User "+str(self.ui.session.auth.user.id)+" deleted ("+str(table)+")"}
        self.ui.db.auth_event.insert(**values)
      self.ui.db.commit()
      return True
    except Exception, err:
      self.error_message = str(err)
      return False
Esempio n. 6
0
 def setUp(self):
     from gluon.globals import Request, Response, Session, current
     from gluon.html import A, DIV, FORM, MENU, TABLE, TR, INPUT, URL, XML
     from gluon.html import ASSIGNJS
     from gluon.validators import IS_NOT_EMPTY
     from gluon.compileapp import LOAD
     from gluon.http import HTTP, redirect
     from gluon.tools import Auth
     from gluon.sql import SQLDB
     from gluon.sqlhtml import SQLTABLE, SQLFORM
     self.original_check_credentials = fileutils.check_credentials
     fileutils.check_credentials = fake_check_credentials
     request = Request(env={})
     request.application = 'welcome'
     request.controller = 'appadmin'
     request.function = self._testMethodName.split('_')[1]
     request.folder = 'applications/welcome'
     request.env.http_host = '127.0.0.1:8000'
     request.env.remote_addr = '127.0.0.1'
     response = Response()
     session = Session()
     T = TranslatorFactory('', 'en')
     session.connect(request, response)
     current.request = request
     current.response = response
     current.session = session
     current.T = T
     db = DAL(DEFAULT_URI, check_reserved=['all'])
     auth = Auth(db)
     auth.define_tables(username=True, signature=False)
     db.define_table('t0', Field('tt'), auth.signature)
     # Create a user
     db.auth_user.insert(first_name='Bart',
                         last_name='Simpson',
                         username='******',
                         email='*****@*****.**',
                         password='******',
                         registration_key=None,
                         registration_id=None)
     self.env = locals()
Esempio n. 7
0
class TestSQLTABLE(unittest.TestCase):
    def setUp(self):
        request = Request(env={})
        request.application = 'a'
        request.controller = 'c'
        request.function = 'f'
        request.folder = 'applications/admin'
        response = Response()
        session = Session()
        T = translator('', 'en')
        session.connect(request, response)
        from gluon.globals import current
        current.request = request
        current.response = response
        current.session = session
        current.T = T
        self.db = DAL(DEFAULT_URI, check_reserved=['all'])
        self.auth = Auth(self.db)
        self.auth.define_tables(username=True, signature=False)
        self.db.define_table('t0', Field('tt'), self.auth.signature)
        self.auth.enable_record_versioning(self.db)
        # Create a user
        self.db.auth_user.insert(first_name='Bart',
                                 last_name='Simpson',
                                 username='******',
                                 email='*****@*****.**',
                                 password='******',
                                 registration_key=None,
                                 registration_id=None)

        self.db.commit()

    def test_SQLTABLE(self):
        rows = self.db(self.db.auth_user.id > 0).select(self.db.auth_user.ALL)
        sqltable = SQLTABLE(rows)
        self.assertEqual(sqltable.xml(), b'<table><thead><tr><th>auth_user.id</th><th>auth_user.first_name</th><th>auth_user.last_name</th><th>auth_user.email</th><th>auth_user.username</th><th>auth_user.password</th><th>auth_user.registration_key</th><th>auth_user.reset_password_key</th><th>auth_user.registration_id</th></tr></thead><tbody><tr class="w2p_odd odd"><td>1</td><td>Bart</td><td>Simpson</td><td>[email protected]</td><td>user1</td><td>password_123</td><td>None</td><td></td><td>None</td></tr></tbody></table>')
Esempio n. 8
0
# (more options discussed in gluon/tools.py)
# -------------------------------------------------------------------------

from gluon.tools import Auth, Service, PluginManager

# host names must be a list of allowed host names (glob syntax allowed)
auth = Auth(db, host_names=myconf.get('host.names'))
service = Service()
plugins = PluginManager()

# -------------------------------------------------------------------------
# create all tables needed by auth if not custom tables
# -------------------------------------------------------------------------
auth.settings.table_user_name = 'usuario'

auth.define_tables(username = True, signature = False, migrate='db.usuario')

db.usuario.username.length = 8
db.usuario.password.requires = CRYPT()
db.usuario.username.requires = IS_MATCH('^[0-9]*$|^admin$', error_message='Numero de Cedula Invalido.')
db.usuario.first_name.requires = IS_MATCH('^[a-zA-ZñÑáéíóúÁÉÍÓÚ]([a-zA-ZñÑáéíóúÁÉÍÓÚ\s]+[\s-]?[a-zA-ZñÑáéíóúÁÉÍÓÚ\s][a-zA-ZñÑáéíóúÁÉÍÓÚ\s]+)*$', error_message='Nombre No Valido. Debe ser no vacío y contener sólo letras, guiones o espacios.')
db.usuario.last_name.requires = IS_MATCH('^[a-zA-ZñÑáéíóúÁÉÍÓÚ]([a-zA-ZñÑáéíóúÁÉÍÓÚ\s]+[\s-]?[a-zA-ZñÑáéíóúÁÉÍÓÚ\s][a-zA-ZñÑáéíóúÁÉÍÓÚ\s]+)*$', error_message='Apellido No Valido. Debe ser no vacío y contener sólo letras, guiones o espacios.')

auth.settings.create_user_groups = None

# -------------------------------------------------------------------------
# configure email
# -------------------------------------------------------------------------
mail = auth.settings.mailer
mail.settings.server = 'logging' if request.is_local else myconf.get('smtp.server')
mail.settings.sender = '*****@*****.**'
Esempio n. 9
0
service = Service()
crud = Crud(db)
plugins = PluginManager()

#Add some fields in auth_user table to have a complete user profile.
auth.settings.extra_fields['auth_user']= [
    Field('nickname', 'string', writable = True, readable = True),
    Field('address', 'text', writable = True, readable = True),
    Field('city', 'string', writable = True, readable = True),
    Field('zip', 'string', writable = True, readable = True),
    Field('phone', 'string', writable = True, readable = True),
    Field('birthday', 'date', IS_DATE(format=('%d-%m-%Y')), writable = True, readable = True),
    Field('picture', 'upload', default='', writable = True, readable = True)]

## create all tables needed by auth if not custom tables
auth.define_tables(username=False, signature=False, migrate=False)

#The user is not automaticaly logged in without mail registration
#The mail is always sended and if the user perform a logoff without registration
#it can't logge in the application
##auth.settings.registration_requires_verification = True
#auth.settings.login_after_registration = True
#auth.settings.create_user_groups = False

#Request a password with a minimal length
auth.settings.password_min_length = 6

#Redirect the logged user to the profile page
# in layout.html view, modify the line:
# <ul id="navbar" class="nav pull-right">{{='auth' in globals() and auth.navbar(mode="dropdown") or ''}}</ul>
# to
Esempio n. 10
0
class TestSQLFORM(unittest.TestCase):

    def setUp(self):
        request = Request(env={})
        request.application = 'a'
        request.controller = 'c'
        request.function = 'f'
        request.folder = 'applications/admin'
        response = Response()
        session = Session()
        T = translator('', 'en')
        session.connect(request, response)
        from gluon.globals import current
        current.request = request
        current.response = response
        current.session = session
        current.T = T
        self.db = DAL(DEFAULT_URI, check_reserved=['all'])
        self.auth = Auth(self.db)
        self.auth.define_tables(username=True, signature=False)
        self.db.define_table('t0', Field('tt', default='web2py'), self.auth.signature)
        self.auth.enable_record_versioning(self.db)
        # Create a user
        self.db.auth_user.insert(first_name='Bart',
                                 last_name='Simpson',
                                 username='******',
                                 email='*****@*****.**',
                                 password='******',
                                 registration_key=None,
                                 registration_id=None)

        self.db.commit()

    
    def test_SQLFORM(self):
        form = SQLFORM(self.db.auth_user)
        self.assertEqual(form.xml()[:5], b'<form')

    def test_represent_SQLFORM(self):
        id = self.db.t0.insert()
        self.db.t0.tt.represent = lambda value: value.capitalize()
        self.db.t0.tt.writable = False
        self.db.t0.tt.readable = True
        form = SQLFORM(self.db.t0, id)
        self.assertTrue(b'Web2py' in form.xml())
        self.db.t0.tt.represent = lambda value, row: value.capitalize()
        form = SQLFORM(self.db.t0, id)
        self.assertTrue(b'Web2py' in form.xml())

    # def test_assert_status(self):
    #     pass

    #  def test_createform(self):
    #     pass

    #  def test_accepts(self):
    #     pass

    #  def test_dictform(self):
    #     pass

    #  def test_smartdictform(self):
    #     pass

    def test_factory(self):
        factory_form = SQLFORM.factory(Field('field_one', 'string', IS_NOT_EMPTY()),
                                       Field('field_two', 'string'))
        self.assertEqual(factory_form.xml()[:5], b'<form')

    def test_factory_applies_default_validators(self):
        from gluon import current

        factory_form = SQLFORM.factory(
            Field('a_date', type='date'),
        )
        # Fake user input
        current.request.post_vars.update({
            '_formname': 'no_table/create',
            'a_date': '2018-09-14',
            '_formkey': '123',

        })
        # Fake the formkey
        current.session['_formkey[no_table/create]'] = ['123']

        self.assertTrue(factory_form.process().accepted)
        self.assertIsInstance(factory_form.vars.a_date, datetime.date)

    #  def test_build_query(self):
    #     pass

    #  def test_search_menu(self):
    #     pass
   
    def test_grid(self):
        grid_form = SQLFORM.grid(self.db.auth_user)
        self.assertEqual(grid_form.xml()[:4], b'<div')

    def test_smartgrid(self):
        smartgrid_form = SQLFORM.smartgrid(self.db.auth_user)
        self.assertEqual(smartgrid_form.xml()[:4], b'<div')
Esempio n. 11
0
#########################################################################

from gluon.tools import Mail, Auth, Crud, Service, PluginManager, prettydate
mail = Mail()                                  # mailer
auth = Auth(db)                                # authentication/authorization

crud = Crud(db)                                # for CRUD helpers using auth
service = Service()                            # for json, xml, jsonrpc, xmlrpc, amfrpc
plugins = PluginManager()                      # for configuring plugins

mail.settings.server = 'logging' or 'smtp.gmail.com:587'  # your SMTP server
mail.settings.sender = '*****@*****.**'         # your email
mail.settings.login = '******'      # your credentials or None

auth.settings.hmac_key = '<your secret key>'   # before define_tables()
auth.define_tables(username=True)                           # creates all needed tables
auth.settings.mailer = mail                    # for user email verification
auth.settings.registration_requires_verification = False
auth.settings.registration_requires_approval = False
auth.messages.verify_email = 'Click on the link http://'+request.env.http_host+URL('default','user',args=['verify_email'])+'/%(key)s to verify your email'
auth.settings.reset_password_requires_verification = True
auth.messages.reset_password = '******'+request.env.http_host+URL('default','user',args=['reset_password'])+'/%(key)s to reset your password'

#########################################################################
## If you need to use OpenID, Facebook, MySpace, Twitter, Linkedin, etc.
## register with janrain.com, uncomment and customize following
# from gluon.contrib.login_methods.rpx_account import RPXAccount
# auth.settings.actions_disabled = \
#    ['register','change_password','request_reset_password']
# auth.settings.login_form = RPXAccount(request, api_key='...',domain='...',
#    url = "http://localhost:8000/%s/default/user/login" % request.application)
Esempio n. 12
0
db = DAL('sqlite://storage.sqlite')

## by default give a view/generic.extension to all actions from localhost
## none otherwise. a pattern can be 'controller/function.extension'
response.generic_patterns = ['*'] if request.is_local else []
## (optional) optimize handling of static files
# response.optimize_css = 'concat,minify,inline'
# response.optimize_js = 'concat,minify,inline'

#########################################################################
## Here is sample code if you need for
## - email capabilities
## - authentication (registration, login, logout, ... )
## - authorization (role based authorization)
## - services (xml, csv, json, xmlrpc, jsonrpc, amf, rss)
## - old style crud actions
## (more options discussed in gluon/tools.py)
#########################################################################

from pydb import montag_auth
from gluon.tools import Auth, Crud, Service, PluginManager

web2py_auth = Auth(db, hmac_key=Auth.get_or_create_key())
web2py_auth.define_tables()
web2py_auth.settings.actions_disabled.append('register')
web2py_auth.settings.actions_disabled.append('request_reset_password')
web2py_auth.settings.reset_password_requires_verification = True

auth = montag_auth.MontagAuth(web2py_auth, request)

crud, service, plugins = Crud(db), Service(), PluginManager()
Esempio n. 13
0
# TABLE cliente_sistema - OK
db.define_table('cliente_sistema',
                Field('cliente_id', 'reference cliente', required=True, requires=IS_NOT_EMPTY('Campo obrigatório!'), notnull=True, label='Cliente'),
                Field('sistema_id', 'reference sistema', required=True, requires=IS_NOT_EMPTY('Campo obrigatório!'), notnull=True, label='Sistema'),
                Field('is_ativo', required=True, notnull=True, requires=[IS_IN_SET(['sim', 'não']), IS_NOT_EMPTY('Campo obrigatório!')], widget=SQLFORM.widgets.radio.widget, label='Sistema ativo?'), primarykey= ['cliente_id', 'sistema_id'])

# Componente Auth
from gluon.tools import Auth
auth = Auth(db)

auth.settings.extra_fields['auth_user']= [
  Field('is_admin', required=True, notnull=True, requires=[IS_IN_SET(['sim', 'não']), IS_NOT_EMPTY('Campo obrigatório!')], widget=SQLFORM.widgets.radio.widget, label='É administrador?'),
  Field('is_atendente', required=True, notnull=True, requires=[IS_IN_SET(['sim', 'não']), IS_NOT_EMPTY('Campo obrigatório!')], widget=SQLFORM.widgets.radio.widget, label='Atende chamados?'),
  Field('cliente_id', 'reference cliente', required=True, requires=IS_NOT_EMPTY('Campo obrigatório!'), notnull=True, label='Cliente'),
  Field('telefone', length=14, requires=IS_LENGTH(14, error_message='Informe no maxímo 14 caracteres!'), label='Telefone')]
auth.define_tables(username=True)

# verificar primary key da tabela
# TABLE liberacao_sistema - OK
db.define_table('liberacao_sistema',
                Field('cliente_id', 'reference cliente', required=True, requires=IS_NOT_EMPTY('Campo obrigatório!'), notnull=True, label='Cliente'),
                Field('solicitante_id', 'reference auth_user', required=True, requires=IS_NOT_EMPTY('Campo obrigatório!'), notnull=True, label='Solicitante'),
                Field('sistema_id', 'reference sistema', required=True, requires=IS_NOT_EMPTY('Campo obrigatório!'), notnull=True, label='Sistema'),
                Field('responsavel_id', 'reference auth_user', required=True, requires=IS_NOT_EMPTY('Campo obrigatório!'), notnull=True, label='Responsável'),
                Field('codigo_ativacao', type='string', length=45, required=True, requires=[IS_NOT_EMPTY('Campo obrigatório!'), IS_LENGTH(minsize=45, maxsize=45, error_message='O código deve possuir 45 caracteres!')], notnull=True, label='Codigo de ativação'),
                Field('codigo_liberacao', type='string', length=45, required=True, requires=[IS_NOT_EMPTY('Campo obrigatório!'), IS_LENGTH(minsize=45, maxsize=45, error_message='O código deve possuir 45 caracteres!')], notnull=True, label='Codigo de liberação'),
                Field('data', type='datetime', notnull=True, label='Data', default=request.now),
                Field('dias_liberado', type='integer', length=3, required=True, requires=[IS_NOT_EMPTY('Campo obrigatório!'), IS_LENGTH(3, error_message='Informe no maxímo 3 caracteres!')], notnull=True, label='Dias liberação'))
db.liberacao_sistema.data.writable = db.liberacao_sistema.data.readable = False

# TABLE usuario_setor
Esempio n. 14
0
db = DAL("sqlite://storage.sqlite")

from gluon.tools import Auth

auth = Auth(db)
auth.define_tables(username=True)

auth.define_tables(username=False, signature=False)

auth.settings.registration_requires_verification = False
auth.settings.registration_requires_approval = False
auth.settings.reset_password_requires_verification = True

db.define_table("chat", Field("me_from"), Field("me_body", "text"), Field("me_html", "text"))

db.define_table(
    "image",
    Field("x", default=10),
    Field("y", default=10),
    Field("title", default="Enter Username!"),
    # Field('player_id', 'reference auth_user', default=auth.user_id),
    format="%(title)s",
)

db.define_table(
    "charCore",
    Field("title", default="Enter Username!"),
    Field("pname"),
    Field("cname"),
    Field("STR", "integer", default=0),
    Field("DEX", "integer", default=0),
Esempio n. 15
0
        smtp_user = general_conf.smtp_user
    if general_conf.smtp_pass:
        smtp_pass = general_conf.smtp_pass
    if general_conf.smtp_host:
        smtp_host = general_conf.smtp_host
    if general_conf.smtp_port:
        smtp_port = str(general_conf.smtp_port)
    if general_conf.smtp_sender:
        smtp_sender = general_conf.smtp_sender

auth.settings.captcha = Recaptcha2(request,
                                   public_key=captcha_public_key,
                                   private_key=captcha_private_key,
                                   label='Please validate the captcha')
auth.define_tables(
    username=True,
    signature=True,
)
auth.settings.logout_next = URL()

#Comment the following line to allow registration
auth.settings.actions_disabled.append('register')

if enable_captcha:
    auth.settings.login_captcha = auth.settings.captcha
else:
    auth.settings.login_captcha = False
auth.settings.two_factor_authentication_group = "auth2step"
auth.settings.auth_two_factor_enabled = two_factor_authentication

#SMPT server configuration
mail = auth.settings.mailer
Esempio n. 16
0
db.define_table("SUBORDINADOS_EXCLUIR", Field('SIAPE_SERVIDOR', 'integer'),
                Field('SIAPE_CHEFIA_TITULAR', 'integer'),
                Field('OBSERVACAO', 'text'),
                Field('UNIDADE_EXERCICIO_SERVIDOR', 'string'),
                Field('TIPO', db.TIPOS_EXCLUSAO))

current.db = db

from gluon.tools import Auth, Service, PluginManager

auth = Auth(db)
service = Service()
plugins = PluginManager()

# # create all tables needed by auth if not custom tables
auth.define_tables(username=True)
auth.settings.create_user_groups = False

# # configure email
mail = auth.settings.mailer
# mail.settings.server = 'logging' if request.is_local else 'smtp.gmail.com:587'
mail.settings.server = 'smtp.gmail.com:587'  # 'logging'
mail.settings.sender = '*****@*****.**'  # your email
mail.settings.login = '******' + emailPass  # your credentials or None

current.mail = mail

# Se a requisição for local, utiliza base auth de teste, caso contrário, utiliza LDAP

from gluon.contrib.login_methods.ldap_auth import ldap_auth
auth.settings.login_methods = [
Esempio n. 17
0
db = DAL(settings.database_uri,
         pool_size=1,
         check_reserved=['all'],
         migrate=settings.migrate,
         fake_migrate_all=False,
         decode_credentials=True)

response.generic_patterns = ['*']  #if request.is_local else []

## configure email
from gluon.tools import Auth, Mail

auth = Auth(db, hmac_key=settings.security_key)
auth.define_tables(username=True, migrate=settings.migrate, fake_migrate=False)

mail = Mail()
mail.settings.server = settings.email_server
mail.settings.sender = settings.email_sender
mail.settings.login = settings.email_login

from datetime import datetime
from fs.osfs import OSFS

osFileServer = OSFS(settings.home_dir)

osFileServer = OSFS(settings.home_dir)

osStaticFolder = OSFS(settings.static_folder)
Esempio n. 18
0
## - email capabilities
## - authentication (registration, login, logout, ... )
## - authorization (role based authorization)
## - services (xml, csv, json, xmlrpc, jsonrpc, amf, rss)
## - old style crud actions
## (more options discussed in gluon/tools.py)
#########################################################################

from gluon.tools import Auth, Service, PluginManager

auth = Auth(db)
service = Service()
plugins = PluginManager()

## create all tables needed by auth if not custom tables
auth.define_tables(username=False, signature=False)

## configure email
mail = auth.settings.mailer
mail.settings.server = 'logging' if request.is_local else myconf.take(
    'smtp.sender')
mail.settings.sender = myconf.take('smtp.sender')
mail.settings.login = myconf.take('smtp.login')

## configure auth policy
auth.settings.registration_requires_verification = False
auth.settings.registration_requires_approval = False
auth.settings.reset_password_requires_verification = True

#########################################################################
## Define your tables below (or better in another model file) for example
Esempio n. 19
0
          requires=[CRYPT(auth.settings.hmac_key)]),
    Field('web_page',requires=IS_EMPTY_OR(IS_URL())),
    Field('mobile_number',default=''),    
    Field('short_profile','text',default=''),
    Field('profile_picture','upload', autodelete=True, requires=IS_EMPTY_OR(IS_IMAGE())),
    Hidden('registered_by','integer',default=0), #nobody
    Hidden('search_name',compute=lambda r: "%s %s (%s)" %( r['first_name'], r['last_name'], r['affiliation'])),
    Hidden('registration_id', length=512,default=''),
    Hidden('registration_key', length=512,default=''),
    Hidden('reset_password_key', length=512,default='',
          label=auth.messages.label_reset_password_key),
    ]

db.define_table('auth_user',
                format='%(first_name)s %(last_name)s (%(affiliation)s)',
                *fields
                )

auth.settings.create_user_groups = False
auth.settings.hmac_key = config.get('auth','hmac_key')   # before define_tables()
auth.define_tables()                           # creates all needed tables
auth.settings.mailer = mail                    # for user email verification
auth.settings.registration_requires_verification = config.getboolean('auth','verification')
auth.settings.registration_requires_approval =  config.getboolean('auth','approval')
auth.messages.verify_email = 'Click on the link http://'+request.env.http_host+URL('default','user',args=['verify_email'])+'/%(key)s to verify your email'
auth.settings.reset_password_requires_verification = True
auth.messages.reset_password = '******'+request.env.http_host+URL('default','user',args=['reset_password'])+'/%(key)s to reset your password'
auth.messages.email_sent = T("Verification Email Sent, please verify your email before you login")

crud.settings.auth = None        # =auth to enforce authorization on crud
Esempio n. 20
0
    Field('donated', type='boolean', writable=False, readable=False, default=False),
#    format='%(username)s',
    format=lambda u: (u.first_name or "") + " " + (u.last_name or ''),
    migrate='runestone_auth_user.table')


db.auth_user.first_name.requires = IS_NOT_EMPTY(error_message=auth.messages.is_empty)
db.auth_user.last_name.requires = IS_NOT_EMPTY(error_message=auth.messages.is_empty)
db.auth_user.password.requires = CRYPT(key=auth.settings.hmac_key)
db.auth_user.username.requires = (HAS_NO_DOTS(), IS_NOT_IN_DB(db, db.auth_user.username))
db.auth_user.registration_id.requires = IS_NOT_IN_DB(db, db.auth_user.registration_id)
db.auth_user.email.requires = (IS_EMAIL(error_message=auth.messages.invalid_email),
                               IS_NOT_IN_DB(db, db.auth_user.email))
db.auth_user.course_id.requires = IS_COURSE_ID()

auth.define_tables(username=True, signature=False, migrate='runestone_')


## configure email
mail=auth.settings.mailer
mail.settings.server = 'logging' or 'smtp.gmail.com:587'
mail.settings.sender = '*****@*****.**'
mail.settings.login = '******'

## configure auth policy
auth.settings.registration_requires_verification = False
auth.settings.registration_requires_approval = False
auth.settings.reset_password_requires_verification = True

auth.settings.register_next = URL('default', 'index')
Esempio n. 21
0
class TestSQLFORM(unittest.TestCase):
    def setUp(self):
        request = Request(env={})
        request.application = 'a'
        request.controller = 'c'
        request.function = 'f'
        request.folder = 'applications/admin'
        response = Response()
        session = Session()
        T = translator('', 'en')
        session.connect(request, response)
        from gluon.globals import current
        current.request = request
        current.response = response
        current.session = session
        current.T = T
        self.db = DAL(DEFAULT_URI, check_reserved=['all'])
        self.auth = Auth(self.db)
        self.auth.define_tables(username=True, signature=False)
        self.db.define_table('t0', Field('tt', default='web2py'),
                             self.auth.signature)
        self.auth.enable_record_versioning(self.db)
        # Create a user
        self.db.auth_user.insert(first_name='Bart',
                                 last_name='Simpson',
                                 username='******',
                                 email='*****@*****.**',
                                 password='******',
                                 registration_key=None,
                                 registration_id=None)

        self.db.commit()

    def test_SQLFORM(self):
        form = SQLFORM(self.db.auth_user)
        self.assertEqual(form.xml()[:5], b'<form')

    def test_represent_SQLFORM(self):
        id = self.db.t0.insert()
        self.db.t0.tt.represent = lambda value: value.capitalize()
        self.db.t0.tt.writable = False
        self.db.t0.tt.readable = True
        form = SQLFORM(self.db.t0, id)
        self.assertTrue(b'Web2py' in form.xml())
        self.db.t0.tt.represent = lambda value, row: value.capitalize()
        form = SQLFORM(self.db.t0, id)
        self.assertTrue(b'Web2py' in form.xml())

    # def test_assert_status(self):
    #     pass

    #  def test_createform(self):
    #     pass

    #  def test_accepts(self):
    #     pass

    #  def test_dictform(self):
    #     pass

    #  def test_smartdictform(self):
    #     pass

    def test_factory(self):
        factory_form = SQLFORM.factory(
            Field('field_one', 'string', IS_NOT_EMPTY()),
            Field('field_two', 'string'))
        self.assertEqual(factory_form.xml()[:5], b'<form')

    def test_factory_applies_default_validators(self):
        from gluon import current

        factory_form = SQLFORM.factory(Field('a_date', type='date'), )
        # Fake user input
        current.request.post_vars.update({
            '_formname': 'no_table/create',
            'a_date': '2018-09-14',
            '_formkey': '123',
        })
        # Fake the formkey
        current.session['_formkey[no_table/create]'] = ['123']

        self.assertTrue(factory_form.process().accepted)
        self.assertIsInstance(factory_form.vars.a_date, datetime.date)

    #  def test_build_query(self):
    #     pass

    #  def test_search_menu(self):
    #     pass

    def test_grid(self):
        grid_form = SQLFORM.grid(self.db.auth_user)
        self.assertEqual(grid_form.xml()[:4], b'<div')

    def test_smartgrid(self):
        smartgrid_form = SQLFORM.smartgrid(self.db.auth_user)
        self.assertEqual(smartgrid_form.xml()[:4], b'<div')
Esempio n. 22
0
#########################################################################
## Here is sample code if you need for
## - email capabilities
## - authentication (registration, login, logout, ... )
## - authorization (role based authorization)
## - services (xml, csv, json, xmlrpc, jsonrpc, amf, rss)
## - old style crud actions
## (more options discussed in gluon/tools.py)
#########################################################################

from gluon.tools import Auth, Crud, Service, PluginManager, prettydate
auth = Auth(db)
crud, service, plugins = Crud(db), Service(), PluginManager()

## create all tables needed by auth if not custom tables
auth.define_tables(migrate=False)

## configure email
mail = auth.settings.mailer
mail.settings.server = 'logging' or 'smtp.gmail.com:587'
mail.settings.sender = '*****@*****.**'
mail.settings.login = '******'

## configure auth policy
auth.settings.registration_requires_verification = False
auth.settings.registration_requires_approval = False
auth.settings.reset_password_requires_verification = True

## if you need to use OpenID, Facebook, MySpace, Twitter, Linkedin, etc.
## register with janrain.com, write your domain:api_key in private/janrain.key
from gluon.contrib.login_methods.rpx_account import use_janrain
Esempio n. 23
0
## - email capabilities
## - authentication (registration, login, logout, ... )
## - authorization (role based authorization)
## - services (xml, csv, json, xmlrpc, jsonrpc, amf, rss)
## - old style crud actions
## (more options discussed in gluon/tools.py)
#########################################################################

from gluon.tools import Auth, Crud, Service, PluginManager, prettydate

auth = Auth(db)
# add extra fields not defined by Auth :
auth.settings.extra_fields['auth_user'] = [
    Field('username'), Field('phone_number')
]
auth.define_tables(migrate=False, username=True)
crud, service, plugins = Crud(db), Service(), PluginManager()

## create all tables needed by auth if not custom tables
#auth.define_tables(username=False, signature=False)

## configure email
mail = auth.settings.mailer
mail.settings.server = dba.mail_server
mail.settings.sender = dba.mail_sender
mail.settings.login = dba.mail_login

## configure auth policy
auth.settings.registration_requires_verification = False
auth.settings.registration_requires_approval = True
auth.settings.reset_password_requires_verification = True
Esempio n. 24
0
		to="*****@*****.**",
		subject="Usuario %(first_name)s pendente" % form.vars,
		message="<html>Voce tem um novo usuario para aprovacao %(first_name)s %(last_name)s </html>" % form.vars
	)

#auth.settings.register_onaccept = notifica
#auth.settings.register_onaccept = funcao

#messages
auth.messages.login_button = "Entrar"

#fields
#auth.settings.extra_fields['auth_user'] = [
#	Field("bio", "text"),
#	Field("photo", "upload"),
#	Field("gender", requires=IS_IN_SET(["masculino","feminino"]))
#]

#janrain
#from gluon.contrib.login_methods.rpx_account import use_janrain
#use_janrain(auth, filename="private/janrain.key")

auth.define_tables(username=False)

#genericas views
if request.is_local:
	response.generic_patterns = ['*']

#response
response.title= "titulo response"
response.meta.keywords= "chave, outra, e outra"
Esempio n. 25
0
db = DAL('sqlite://storage.sqlite')

from gluon.tools import Auth, Crud

auth = Auth(db, hmac_key=Auth.get_or_create_key())
auth.define_tables()
crud = Crud(db)

db.define_table('image',
                Field('title', unique=True),
                Field('file', 'upload', autodelete=True),
                Field('author'),
                format='%(title)s')

db.define_table('comment', Field('image_id', db.image), Field('author'),
                Field('body', 'text'))

db.define_table('likes', Field('imageid', db.image),
                Field('authorid', db.auth_user))

db.image.title.requires = IS_NOT_IN_DB(db, db.image.title)
db.comment.image_id.requires = IS_IN_DB(db, db.image.id, '%(title)s')

db.comment.body.requires = IS_NOT_EMPTY()
db.comment.image_id.writable = db.comment.image_id.readable = False

#db.image.author.default = session.auth.user.first_name + " " + session.auth.user.last_name
#db.comment.author.default = session.auth.user.first_name + " " + session.auth.user.last_name
db.image.author.readable = db.image.author.writable = False
db.comment.author.readable = db.comment.author.writable = False
Esempio n. 26
0
auth.settings.extra_fields['auth_permission'] = [
    Field('uuid', length=64, default=lambda:str(uuid.uuid4())),
    Field('modified_on', 'datetime', default=request.now)
]

auth.settings.extra_fields['auth_event'] = [
    Field('uuid', length=64, default=lambda:str(uuid.uuid4())),
    Field('modified_on', 'datetime', default=request.now)
]

auth.settings.extra_fields['auth_cas'] = [
    Field('modified_on', 'datetime', default=request.now)
]

auth.define_tables()                           # creates all needed tables
db.auth_user._format = lambda row: '{}:{}, {}'.format(row.id, row.last_name,
                                                      row.first_name)

#-------------------------------------------------------------
# Mail config
#-------------------------------------------------------------

mail = Mail()
mail.settings.server = keydata['email_sender']  # 'logging' # SMTP server
mail.settings.sender = keydata['email_address']  # email
mail.settings.login = keydata['email_pass']  # credentials or None
current.mail = mail

auth.settings.mailer = mail                    # for user email verification
auth.settings.registration_requires_verification = False
Esempio n. 27
0
from gluon.tools import Auth, Crud, Service, PluginManager, prettydate
auth = Auth(db)
auth.settings.extra_fields['auth_user'] = [
    Field('street_address', label=T('Street Address'), length=100),
    Field('city', 'string', label=T('City'), length=50),
    Field('state', 'string', label=T('State'), length=20),
    Field('country', 'string', label=T('Country'), length=20),
    Field('zip_code', 'string', label=T('Zip Code'), length=9),
    Field('phone_number', 'string', label=T('Phone Number'), length=20)
]

crud, service, plugins = Crud(db), Service(), PluginManager()

## create all tables needed by auth if not custom tables
auth.define_tables(username=False, signature=False)

## configure email
mail = auth.settings.mailer
mail.settings.server = 'logging' or 'smtp.gmail.com:587'
mail.settings.sender = '*****@*****.**'
mail.settings.login = '******'

## configure auth policy
auth.settings.registration_requires_verification = False
auth.settings.registration_requires_approval = False
auth.settings.reset_password_requires_verification = True

## if you need to use OpenID, Facebook, MySpace, Twitter, Linkedin, etc.
## register with janrain.com, write your domain:api_key in private/janrain.key
from gluon.contrib.login_methods.rpx_account import use_janrain
Esempio n. 28
0
                migrate='runestone_auth_user.table')

db.auth_user.first_name.requires = IS_NOT_EMPTY(
    error_message=auth.messages.is_empty)
db.auth_user.last_name.requires = IS_NOT_EMPTY(
    error_message=auth.messages.is_empty)
db.auth_user.password.requires = CRYPT(key=auth.settings.hmac_key)
db.auth_user.username.requires = IS_NOT_IN_DB(db, db.auth_user.username)
db.auth_user.registration_id.requires = IS_NOT_IN_DB(
    db, db.auth_user.registration_id)
db.auth_user.email.requires = (IS_EMAIL(
    error_message=auth.messages.invalid_email),
                               IS_NOT_IN_DB(db, db.auth_user.email))
db.auth_user.course_id.requires = IS_COURSE_ID()

auth.define_tables(migrate='runestone_')

# create the instructor group if it doesn't already exist
if not db(db.auth_group.role == 'instructor').select().first():
    db.auth_group.insert(role='instructor')

## configure email
mail = auth.settings.mailer
mail.settings.server = 'logging' or 'smtp.gmail.com:587'
mail.settings.sender = '*****@*****.**'
mail.settings.login = '******'

## configure auth policy
auth.settings.registration_requires_verification = False
auth.settings.registration_requires_approval = False
auth.settings.reset_password_requires_verification = True
Esempio n. 29
0
                      default='',
                      writable=False,
                      readable=False),
                format='%(username)s',
                migrate=settings.migrate)

db.auth_user.first_name.requires = IS_NOT_EMPTY(
    error_message=auth.messages.is_empty)
db.auth_user.last_name.requires = IS_NOT_EMPTY(
    error_message=auth.messages.is_empty)
db.auth_user.password.requires = CRYPT(key=auth.settings.hmac_key)
db.auth_user.username.requires = IS_NOT_IN_DB(db, db.auth_user.username)
db.auth_user.email.requires = (IS_EMAIL(
    error_message=auth.messages.invalid_email),
                               IS_NOT_IN_DB(db, db.auth_user.email))
auth.define_tables(migrate=settings.migrate)

## configure email
mail = auth.settings.mailer
mail.settings.server = 'logging' or 'smtp.gmail.com:587'
mail.settings.sender = '*****@*****.**'
mail.settings.login = '******'

## configure auth policy
auth.settings.registration_requires_verification = False
auth.settings.registration_requires_approval = False
auth.settings.reset_password_requires_verification = True

## if you need to use OpenID, Facebook, MySpace, Twitter, Linkedin, etc.
## register with janrain.com, write your domain:api_key in private/janrain.key
from gluon.contrib.login_methods.rpx_account import use_janrain
Esempio n. 30
0
    Field('reset_password_key',default='',
          writable=False,readable=False),
    Field('registration_id',default='',
          writable=False,readable=False),
    Field('cohort_id','reference cohort_master', requires=IS_IN_DB(db, 'cohort_master.id', 'id'),
          writable=False,readable=False),
    Field('course_id',db.courses,label=T('Course Name'),
          required=True,
          default=1),
    Field('course_name',compute=lambda row: getCourseNameFromId(row.course_id)),
#    format='%(username)s',
    format=lambda u: u.first_name + " " + u.last_name,
    migrate=False)


db.auth_user.first_name.requires = IS_NOT_EMPTY(error_message=auth.messages.is_empty)
db.auth_user.last_name.requires = IS_NOT_EMPTY(error_message=auth.messages.is_empty)
db.auth_user.password.requires = CRYPT(key=auth.settings.hmac_key)
db.auth_user.username.requires = IS_NOT_IN_DB(db, db.auth_user.username)
db.auth_user.registration_id.requires = IS_NOT_IN_DB(db, db.auth_user.registration_id)
db.auth_user.email.requires = (IS_EMAIL(error_message=auth.messages.invalid_email),
                               IS_NOT_IN_DB(db, db.auth_user.email))
db.auth_user.course_id.requires = IS_COURSE_ID()
# Note - welcome/models/db.py should have username=True to insure username field exists
auth.define_tables(username=True, migrate=False)

# Define our tables
db.define_table('lti_keys', Field('consumer'), Field('secret'), Field('application'))

# print "LTI db.py", type(db), type(auth)
Esempio n. 31
0
# - services (xml, csv, json, xmlrpc, jsonrpc, amf, rss)
# - old style crud actions
# (more options discussed in gluon/tools.py)
# -------------------------------------------------------------------------

from gluon.tools import Auth, Service, PluginManager

# host names must be a list of allowed host names (glob syntax allowed)
auth = Auth(db, host_names=myconf.get('host.names'))
service = Service()
plugins = PluginManager()

# -------------------------------------------------------------------------
# create all tables needed by auth if not custom tables
# -------------------------------------------------------------------------
auth.define_tables(username=False, signature=False, migrate=0)
from gluon.contrib.login_methods.email_auth import email_auth
auth.settings.login_methods.append(
    email_auth("mail.etecsa.cu:587", "@etecsa.cu"))

# -------------------------------------------------------------------------
# configure email
# -------------------------------------------------------------------------
mail = auth.settings.mailer
mail.settings.server = 'logging' if request.is_local else myconf.get(
    'smtp.server')
mail.settings.sender = myconf.get('smtp.sender')
mail.settings.login = myconf.get('smtp.login')
mail.settings.tls = myconf.get('smtp.tls') or False
mail.settings.ssl = myconf.get('smtp.ssl') or False
Esempio n. 32
0
try:
    db = DAL('sqlite://pesquisa.db')
except:
    db=DAL('gae')
    session.connect(request,response,db=db)


response.generic_patterns = ['*'] if request.is_local else []


from gluon.tools import Mail, Auth, Crud, Service, PluginManager, prettydate
mail = Mail()                                  # mailer
auth = Auth(globals(), db)
auth.define_tables(username=True)                                # authentication/authorization
crud = Crud(globals(),db)                                # for CRUD helpers using auth
service = Service()                            # for json, xml, jsonrpc, xmlrpc, amfrpc
plugins = PluginManager()                      # for configuring plugins

mail.settings.server = 'logging' or 'smtp.gmail.com:587'  # your SMTP server
mail.settings.sender = '*****@*****.**'         # your email
mail.settings.login = '******'      # your credentials or None

auth.settings.hmac_key = 'sha512:4b841008-250d-45e3-82ca-e2edf506c2ab'   # before define_tables()
auth.define_tables()                           # creates all needed tables
auth.settings.mailer = mail                    # for user email verification
auth.settings.registration_requires_verification = False
auth.settings.registration_requires_approval = True
auth.messages.verify_email = 'Click on the link http://'+request.env.http_host+URL('default','user',args=['verify_email'])+'/%(key)s to verify your email'
auth.settings.reset_password_requires_verification = True
auth.messages.reset_password = '******'+request.env.http_host+URL('default','user',args=['reset_password'])+'/%(key)s to reset your password'
auth.define_tables(username=True)
Esempio n. 33
0
## - services (xml, csv, json, xmlrpc, jsonrpc, amf, rss)
## - old style crud actions
## (more options discussed in gluon/tools.py)
#########################################################################

from gluon.tools import Auth, Crud, Service, PluginManager, prettydate
auth = Auth(db)
crud, service, plugins = Crud(db), Service(), PluginManager()

auth.settings.extra_fields['auth_user']= [
  Field('username', 'string', requires = IS_NOT_EMPTY(error_message=auth.messages.is_empty)),
  Field('photo', 'upload', requires = IS_NOT_EMPTY(error_message=auth.messages.is_empty)),
  Field('description', 'text', requires = IS_NOT_EMPTY(error_message=auth.messages.is_empty)),]

## create all tables needed by auth if not custom tables
auth.define_tables(username=False)

db.auth_user.email.requires = IS_MATCH('\S.*@ucsc.edu', error_message='email must be @ucsc.edu')

## configure email
mail=auth.settings.mailer
mail.settings.server = 'logging' or 'smtp.gmail.com:587'
mail.settings.sender = '*****@*****.**'
mail.settings.login = '******'

## configure auth policy
auth.settings.registration_requires_verification = False
auth.settings.registration_requires_approval = False
auth.settings.reset_password_requires_verification = True

## if you need to use OpenID, Facebook, MySpace, Twitter, Linkedin, etc.
Esempio n. 34
0
## - email capabilities
## - authentication (registration, login, logout, ... )
## - authorization (role based authorization)
## - services (xml, csv, json, xmlrpc, jsonrpc, amf, rss)
## - old style crud actions
## (more options discussed in gluon/tools.py)
#########################################################################

from gluon.tools import Auth, Service, PluginManager

auth = Auth(db)
service = Service()
plugins = PluginManager()

## create all tables needed by auth if not custom tables
auth.define_tables(username=False, signature=False)

## configure email
mail = auth.settings.mailer
mail.settings.server = 'logging' if request.is_local else myconf.take('smtp.sender')
mail.settings.sender = myconf.take('smtp.sender')
mail.settings.login = myconf.take('smtp.login')

## configure auth policy
auth.settings.registration_requires_verification = False
auth.settings.registration_requires_approval = False
auth.settings.reset_password_requires_verification = True

#########################################################################
## Define your tables below (or better in another model file) for example
##
Esempio n. 35
0
    error_message=auth.messages.is_empty)
#custom_auth_table.password.requires = [IS_STRONG(), CRYPT()]
custom_auth_table.email.requires = [
    IS_EMAIL(error_message=auth.messages.invalid_email),
    IS_NOT_IN_DB(db, custom_auth_table.email)
]

auth.settings.table_user = custom_auth_table  # tell auth to use custom_auth_table
custom_auth_table.username.requires = IS_NOT_IN_DB(db,
                                                   custom_auth_table.username)

auth.settings.logged_url = URL('user', args='profile')
auth.settings.profile_next = URL('profile')

# create all tables needed by auth if not custom tables
auth.define_tables(signature=False)

# Hiding audience, follow and image list.
db.auth_user.follow_list.writable = db.auth_user.follow_list.readable = False
db.auth_user.audience_list.writable = db.auth_user.audience_list.readable = False

# configure email
mail = auth.settings.mailer
mail.settings.server = 'logging' if request.is_local else myconf.get(
    'smtp.server')
mail.settings.sender = myconf.get('smtp.sender')
mail.settings.login = myconf.get('smtp.login')
mail.settings.tls = myconf.get('smtp.tls') or False
mail.settings.ssl = myconf.get('smtp.ssl') or False

# configure auth policy
Esempio n. 36
0
          default=1),
    Field('course_name',compute=lambda row: getCourseNameFromId(row.course_id)),
    format='%(username)s',
    migrate='runestone_auth_user.table')


db.auth_user.first_name.requires = IS_NOT_EMPTY(error_message=auth.messages.is_empty)
db.auth_user.last_name.requires = IS_NOT_EMPTY(error_message=auth.messages.is_empty)
db.auth_user.password.requires = CRYPT(key=auth.settings.hmac_key)
db.auth_user.username.requires = IS_NOT_IN_DB(db, db.auth_user.username)
db.auth_user.registration_id.requires = IS_NOT_IN_DB(db, db.auth_user.registration_id)
db.auth_user.email.requires = (IS_EMAIL(error_message=auth.messages.invalid_email),
                               IS_NOT_IN_DB(db, db.auth_user.email))
db.auth_user.course_id.requires = IS_COURSE_ID()

auth.define_tables(migrate='runestone_')

# create the instructor group if it doesn't already exist
if not db(db.auth_group.role == 'instructor').select().first():
    db.auth_group.insert(role='instructor')

## configure email
mail=auth.settings.mailer
mail.settings.server = 'logging' or 'smtp.gmail.com:587'
mail.settings.sender = '*****@*****.**'
mail.settings.login = '******'

## configure auth policy
auth.settings.registration_requires_verification = False
auth.settings.registration_requires_approval = False
auth.settings.reset_password_requires_verification = True
Esempio n. 37
0
class TestSQLFORM(unittest.TestCase):

    def setUp(self):
        request = Request(env={})
        request.application = 'a'
        request.controller = 'c'
        request.function = 'f'
        request.folder = 'applications/admin'
        response = Response()
        session = Session()
        T = translator('', 'en')
        session.connect(request, response)
        from gluon.globals import current
        current.request = request
        current.response = response
        current.session = session
        current.T = T
        self.db = DAL(DEFAULT_URI, check_reserved=['all'])
        self.auth = Auth(self.db)
        self.auth.define_tables(username=True, signature=False)
        self.db.define_table('t0', Field('tt', default='web2py'), self.auth.signature)
        self.auth.enable_record_versioning(self.db)
        # Create a user
        self.db.auth_user.insert(first_name='Bart',
                                 last_name='Simpson',
                                 username='******',
                                 email='*****@*****.**',
                                 password='******',
                                 registration_key=None,
                                 registration_id=None)

        self.db.commit()

    def test_SQLFORM(self):
        form = SQLFORM(self.db.auth_user)
        self.assertEqual(form.xml(), b'<form action="#" enctype="multipart/form-data" method="post"><table><tr id="auth_user_first_name__row"><td class="w2p_fl"><label class="" for="auth_user_first_name" id="auth_user_first_name__label">First name: </label></td><td class="w2p_fw"><input class="string" id="auth_user_first_name" name="first_name" type="text" value="" /></td><td class="w2p_fc"></td></tr><tr id="auth_user_last_name__row"><td class="w2p_fl"><label class="" for="auth_user_last_name" id="auth_user_last_name__label">Last name: </label></td><td class="w2p_fw"><input class="string" id="auth_user_last_name" name="last_name" type="text" value="" /></td><td class="w2p_fc"></td></tr><tr id="auth_user_email__row"><td class="w2p_fl"><label class="" for="auth_user_email" id="auth_user_email__label">E-mail: </label></td><td class="w2p_fw"><input class="string" id="auth_user_email" name="email" type="text" value="" /></td><td class="w2p_fc"></td></tr><tr id="auth_user_username__row"><td class="w2p_fl"><label class="" for="auth_user_username" id="auth_user_username__label">Username: </label></td><td class="w2p_fw"><input class="string" id="auth_user_username" name="username" type="text" value="" /></td><td class="w2p_fc"></td></tr><tr id="auth_user_password__row"><td class="w2p_fl"><label class="" for="auth_user_password" id="auth_user_password__label">Password: </label></td><td class="w2p_fw"><input class="password" id="auth_user_password" name="password" type="password" value="" /></td><td class="w2p_fc"></td></tr><tr id="submit_record__row"><td class="w2p_fl"></td><td class="w2p_fw"><input type="submit" value="Submit" /></td><td class="w2p_fc"></td></tr></table></form>')

    def test_represent_SQLFORM(self):
        self.db.t0.tt.represent = lambda value: value.capitalize()
        self.db.t0.tt.writable = False
        self.db.t0.tt.readable = True
        form = SQLFORM(self.db.t0)
        self.assertTrue(b'Web2py' in form.xml())
        self.db.t0.tt.represent = lambda value, row: value.capitalize()
        form = SQLFORM(self.db.t0)
        self.assertTrue(b'Web2py' in form.xml())

    # def test_assert_status(self):
    #     pass

    #  def test_createform(self):
    #     pass

    #  def test_accepts(self):
    #     pass

    #  def test_dictform(self):
    #     pass

    #  def test_smartdictform(self):
    #     pass

    def test_factory(self):
        factory_form = SQLFORM.factory(Field('field_one', 'string', IS_NOT_EMPTY()),
                                       Field('field_two', 'string'))
        self.assertEqual(factory_form.xml(), b'<form action="#" enctype="multipart/form-data" method="post"><table><tr id="no_table_field_one__row"><td class="w2p_fl"><label class="" for="no_table_field_one" id="no_table_field_one__label">Field One: </label></td><td class="w2p_fw"><input class="string" id="no_table_field_one" name="field_one" type="text" value="" /></td><td class="w2p_fc"></td></tr><tr id="no_table_field_two__row"><td class="w2p_fl"><label class="" for="no_table_field_two" id="no_table_field_two__label">Field Two: </label></td><td class="w2p_fw"><input class="string" id="no_table_field_two" name="field_two" type="text" value="" /></td><td class="w2p_fc"></td></tr><tr id="submit_record__row"><td class="w2p_fl"></td><td class="w2p_fw"><input type="submit" value="Submit" /></td><td class="w2p_fc"></td></tr></table></form>')

    #  def test_build_query(self):
    #     pass

    #  def test_search_menu(self):
    #     pass

    def test_grid(self):
        grid_form = SQLFORM.grid(self.db.auth_user)
        self.assertEqual(grid_form.xml(), b'<div class="web2py_grid "><div class="web2py_console  "><form action="/a/c/f" enctype="multipart/form-data" method="GET"><input class="form-control" id="w2p_keywords" name="keywords" onfocus="jQuery(&#x27;#w2p_query_fields&#x27;).change();jQuery(&#x27;#w2p_query_panel&#x27;).slideDown();" type="text" value="" /><input class="btn btn-default" type="submit" value="Search" /><input class="btn btn-default" onclick="jQuery(&#x27;#w2p_keywords&#x27;).val(&#x27;&#x27;);" type="submit" value="Clear" /></form><div id="w2p_query_panel" style="display:none;"><select class="form-control" id="w2p_query_fields" onchange="jQuery(&#x27;.w2p_query_row&#x27;).hide();jQuery(&#x27;#w2p_field_&#x27;+jQuery(&#x27;#w2p_query_fields&#x27;).val().replace(&#x27;.&#x27;,&#x27;-&#x27;)).show();" style="float:left"><option value="auth_user.id">Id</option><option value="auth_user.first_name">First name</option><option value="auth_user.last_name">Last name</option><option value="auth_user.email">E-mail</option><option value="auth_user.username">Username</option></select><div class="w2p_query_row" id="w2p_field_auth_user-id" style="display:none"><select class="form-control"><option value="=">=</option><option value="!=">!=</option><option value="&lt;">&lt;</option><option value="&gt;">&gt;</option><option value="&lt;=">&lt;=</option><option value="&gt;=">&gt;=</option><option value="in">in</option><option value="not in">not in</option></select><input class="id form-control" id="w2p_value_auth_user-id" type="text" /><input class="btn btn-default" onclick="w2p_build_query(&#x27;new&#x27;,&#x27;auth_user.id&#x27;)" title="Start building a new search" type="button" value="New Search" /><input class="btn btn-default" onclick="w2p_build_query(&#x27;and&#x27;,&#x27;auth_user.id&#x27;)" title="Add this to the search as an AND term" type="button" value="+ And" /><input class="btn btn-default" onclick="w2p_build_query(&#x27;or&#x27;,&#x27;auth_user.id&#x27;)" title="Add this to the search as an OR term" type="button" value="+ Or" /><input class="btn btn-default" onclick="jQuery(&#x27;#w2p_query_panel&#x27;).slideUp()" type="button" value="Close" /></div><div class="w2p_query_row" id="w2p_field_auth_user-first_name" style="display:none"><select class="form-control"><option value="=">=</option><option value="!=">!=</option><option value="&lt;">&lt;</option><option value="&gt;">&gt;</option><option value="&lt;=">&lt;=</option><option value="&gt;=">&gt;=</option><option value="starts with">starts with</option><option value="contains">contains</option><option value="in">in</option><option value="not in">not in</option></select><input class="string form-control" id="w2p_value_auth_user-first_name" type="text" /><input class="btn btn-default" onclick="w2p_build_query(&#x27;new&#x27;,&#x27;auth_user.first_name&#x27;)" title="Start building a new search" type="button" value="New Search" /><input class="btn btn-default" onclick="w2p_build_query(&#x27;and&#x27;,&#x27;auth_user.first_name&#x27;)" title="Add this to the search as an AND term" type="button" value="+ And" /><input class="btn btn-default" onclick="w2p_build_query(&#x27;or&#x27;,&#x27;auth_user.first_name&#x27;)" title="Add this to the search as an OR term" type="button" value="+ Or" /><input class="btn btn-default" onclick="jQuery(&#x27;#w2p_query_panel&#x27;).slideUp()" type="button" value="Close" /></div><div class="w2p_query_row" id="w2p_field_auth_user-last_name" style="display:none"><select class="form-control"><option value="=">=</option><option value="!=">!=</option><option value="&lt;">&lt;</option><option value="&gt;">&gt;</option><option value="&lt;=">&lt;=</option><option value="&gt;=">&gt;=</option><option value="starts with">starts with</option><option value="contains">contains</option><option value="in">in</option><option value="not in">not in</option></select><input class="string form-control" id="w2p_value_auth_user-last_name" type="text" /><input class="btn btn-default" onclick="w2p_build_query(&#x27;new&#x27;,&#x27;auth_user.last_name&#x27;)" title="Start building a new search" type="button" value="New Search" /><input class="btn btn-default" onclick="w2p_build_query(&#x27;and&#x27;,&#x27;auth_user.last_name&#x27;)" title="Add this to the search as an AND term" type="button" value="+ And" /><input class="btn btn-default" onclick="w2p_build_query(&#x27;or&#x27;,&#x27;auth_user.last_name&#x27;)" title="Add this to the search as an OR term" type="button" value="+ Or" /><input class="btn btn-default" onclick="jQuery(&#x27;#w2p_query_panel&#x27;).slideUp()" type="button" value="Close" /></div><div class="w2p_query_row" id="w2p_field_auth_user-email" style="display:none"><select class="form-control"><option value="=">=</option><option value="!=">!=</option><option value="&lt;">&lt;</option><option value="&gt;">&gt;</option><option value="&lt;=">&lt;=</option><option value="&gt;=">&gt;=</option><option value="starts with">starts with</option><option value="contains">contains</option><option value="in">in</option><option value="not in">not in</option></select><input class="string form-control" id="w2p_value_auth_user-email" type="text" /><input class="btn btn-default" onclick="w2p_build_query(&#x27;new&#x27;,&#x27;auth_user.email&#x27;)" title="Start building a new search" type="button" value="New Search" /><input class="btn btn-default" onclick="w2p_build_query(&#x27;and&#x27;,&#x27;auth_user.email&#x27;)" title="Add this to the search as an AND term" type="button" value="+ And" /><input class="btn btn-default" onclick="w2p_build_query(&#x27;or&#x27;,&#x27;auth_user.email&#x27;)" title="Add this to the search as an OR term" type="button" value="+ Or" /><input class="btn btn-default" onclick="jQuery(&#x27;#w2p_query_panel&#x27;).slideUp()" type="button" value="Close" /></div><div class="w2p_query_row" id="w2p_field_auth_user-username" style="display:none"><select class="form-control"><option value="=">=</option><option value="!=">!=</option><option value="&lt;">&lt;</option><option value="&gt;">&gt;</option><option value="&lt;=">&lt;=</option><option value="&gt;=">&gt;=</option><option value="starts with">starts with</option><option value="contains">contains</option><option value="in">in</option><option value="not in">not in</option></select><input class="string form-control" id="w2p_value_auth_user-username" type="text" /><input class="btn btn-default" onclick="w2p_build_query(&#x27;new&#x27;,&#x27;auth_user.username&#x27;)" title="Start building a new search" type="button" value="New Search" /><input class="btn btn-default" onclick="w2p_build_query(&#x27;and&#x27;,&#x27;auth_user.username&#x27;)" title="Add this to the search as an AND term" type="button" value="+ And" /><input class="btn btn-default" onclick="w2p_build_query(&#x27;or&#x27;,&#x27;auth_user.username&#x27;)" title="Add this to the search as an OR term" type="button" value="+ Or" /><input class="btn btn-default" onclick="jQuery(&#x27;#w2p_query_panel&#x27;).slideUp()" type="button" value="Close" /></div></div><script><!--\n\n        jQuery(\'#w2p_query_fields input,#w2p_query_fields select\').css(\n            \'width\',\'auto\');\n        jQuery(function(){web2py_ajax_fields(\'#w2p_query_fields\');});\n        function w2p_build_query(aggregator,a) {\n          var b=a.replace(\'.\',\'-\');\n          var option = jQuery(\'#w2p_field_\'+b+\' select\').val();\n          var value;\n          var $value_item = jQuery(\'#w2p_value_\'+b);\n          if ($value_item.is(\':checkbox\')){\n            if  ($value_item.is(\':checked\'))\n                    value = \'True\';\n            else  value = \'False\';\n          }\n          else\n          { value = $value_item.val().replace(\'"\',\'\\\\"\')}\n          var s=a+\' \'+option+\' "\'+value+\'"\';\n          var k=jQuery(\'#w2p_keywords\');\n          var v=k.val();\n          if(aggregator==\'new\') k.val(s); else k.val((v?(v+\' \'+ aggregator +\' \'):\'\')+s);\n        }\n        \n//--></script><div class="web2py_counter">1 records found</div></div><div class="web2py_table"><div class="web2py_htmltable" style="width:100%;overflow-x:auto;-ms-overflow-x:scroll"><table><colgroup><col data-column="1" id="auth_user-id" /><col data-column="2" id="auth_user-first_name" /><col data-column="3" id="auth_user-last_name" /><col data-column="4" id="auth_user-email" /><col data-column="5" id="auth_user-username" /><col data-column="6" /></colgroup><thead><tr class=""><th class=""><a href="/a/c/f?keywords=&amp;order=auth_user.id">Id</a></th><th class=""><a href="/a/c/f?keywords=&amp;order=auth_user.first_name">First name</a></th><th class=""><a href="/a/c/f?keywords=&amp;order=auth_user.last_name">Last name</a></th><th class=""><a href="/a/c/f?keywords=&amp;order=auth_user.email">E-mail</a></th><th class=""><a href="/a/c/f?keywords=&amp;order=auth_user.username">Username</a></th><th class=""></th></tr></thead><tbody><tr class="w2p_odd odd with_id" id="1"><td>1</td><td>Bart</td><td>Simpson</td><td>[email protected]</td><td>user1</td><td class="row_buttons" nowrap="nowrap"><a class="button btn btn-default" href="/a/c/f/view/auth_user/1"><span class="icon magnifier icon-zoom-in glyphicon glyphicon-zoom-in"></span> <span class="buttontext button" title="View">View</span></a></td></tr></tbody></table></div></div><div class="w2p_export_menu">Export:<a class="btn btn-default" href="/a/c/f?_export_type=csv&amp;keywords=&amp;order=" title="Comma-separated export of visible columns. Fields from other tables are exported as they appear on-screen but this may be slow for many rows">CSV</a><a class="btn btn-default" href="/a/c/f?_export_type=csv_with_hidden_cols&amp;keywords=&amp;order=" title="Comma-separated export including columns not shown; fields from other tables are exported as raw values for faster export">CSV (hidden cols)</a><a class="btn btn-default" href="/a/c/f?_export_type=html&amp;keywords=&amp;order=" title="HTML export of visible columns">HTML</a><a class="btn btn-default" href="/a/c/f?_export_type=json&amp;keywords=&amp;order=" title="JSON export of visible columns">JSON</a><a class="btn btn-default" href="/a/c/f?_export_type=tsv&amp;keywords=&amp;order=" title="Spreadsheet-optimised export of tab-separated content, visible columns only. May be slow.">TSV (Spreadsheets)</a><a class="btn btn-default" href="/a/c/f?_export_type=tsv_with_hidden_cols&amp;keywords=&amp;order=" title="Spreadsheet-optimised export of tab-separated content including hidden columns. May be slow">TSV (Spreadsheets, hidden cols)</a><a class="btn btn-default" href="/a/c/f?_export_type=xml&amp;keywords=&amp;order=" title="XML export of columns shown">XML</a></div></div>')

    def test_smartgrid(self):
        smartgrid_form = SQLFORM.smartgrid(self.db.auth_user)
        self.assertEqual(smartgrid_form.xml(), b'<div class="web2py_grid "><div class="web2py_breadcrumbs"><ul class=""><li class="active w2p_grid_breadcrumb_elem"><a href="/a/c/f/auth_user">Auth users</a></li></ul></div><div class="web2py_console  "><form action="/a/c/f/auth_user" enctype="multipart/form-data" method="GET"><input class="form-control" id="w2p_keywords" name="keywords" onfocus="jQuery(&#x27;#w2p_query_fields&#x27;).change();jQuery(&#x27;#w2p_query_panel&#x27;).slideDown();" type="text" value="" /><input class="btn btn-default" type="submit" value="Search" /><input class="btn btn-default" onclick="jQuery(&#x27;#w2p_keywords&#x27;).val(&#x27;&#x27;);" type="submit" value="Clear" /></form><div id="w2p_query_panel" style="display:none;"><select class="form-control" id="w2p_query_fields" onchange="jQuery(&#x27;.w2p_query_row&#x27;).hide();jQuery(&#x27;#w2p_field_&#x27;+jQuery(&#x27;#w2p_query_fields&#x27;).val().replace(&#x27;.&#x27;,&#x27;-&#x27;)).show();" style="float:left"><option value="auth_user.id">Id</option><option value="auth_user.first_name">First name</option><option value="auth_user.last_name">Last name</option><option value="auth_user.email">E-mail</option><option value="auth_user.username">Username</option></select><div class="w2p_query_row" id="w2p_field_auth_user-id" style="display:none"><select class="form-control"><option value="=">=</option><option value="!=">!=</option><option value="&lt;">&lt;</option><option value="&gt;">&gt;</option><option value="&lt;=">&lt;=</option><option value="&gt;=">&gt;=</option><option value="in">in</option><option value="not in">not in</option></select><input class="id form-control" id="w2p_value_auth_user-id" type="text" /><input class="btn btn-default" onclick="w2p_build_query(&#x27;new&#x27;,&#x27;auth_user.id&#x27;)" title="Start building a new search" type="button" value="New Search" /><input class="btn btn-default" onclick="w2p_build_query(&#x27;and&#x27;,&#x27;auth_user.id&#x27;)" title="Add this to the search as an AND term" type="button" value="+ And" /><input class="btn btn-default" onclick="w2p_build_query(&#x27;or&#x27;,&#x27;auth_user.id&#x27;)" title="Add this to the search as an OR term" type="button" value="+ Or" /><input class="btn btn-default" onclick="jQuery(&#x27;#w2p_query_panel&#x27;).slideUp()" type="button" value="Close" /></div><div class="w2p_query_row" id="w2p_field_auth_user-first_name" style="display:none"><select class="form-control"><option value="=">=</option><option value="!=">!=</option><option value="&lt;">&lt;</option><option value="&gt;">&gt;</option><option value="&lt;=">&lt;=</option><option value="&gt;=">&gt;=</option><option value="starts with">starts with</option><option value="contains">contains</option><option value="in">in</option><option value="not in">not in</option></select><input class="string form-control" id="w2p_value_auth_user-first_name" type="text" /><input class="btn btn-default" onclick="w2p_build_query(&#x27;new&#x27;,&#x27;auth_user.first_name&#x27;)" title="Start building a new search" type="button" value="New Search" /><input class="btn btn-default" onclick="w2p_build_query(&#x27;and&#x27;,&#x27;auth_user.first_name&#x27;)" title="Add this to the search as an AND term" type="button" value="+ And" /><input class="btn btn-default" onclick="w2p_build_query(&#x27;or&#x27;,&#x27;auth_user.first_name&#x27;)" title="Add this to the search as an OR term" type="button" value="+ Or" /><input class="btn btn-default" onclick="jQuery(&#x27;#w2p_query_panel&#x27;).slideUp()" type="button" value="Close" /></div><div class="w2p_query_row" id="w2p_field_auth_user-last_name" style="display:none"><select class="form-control"><option value="=">=</option><option value="!=">!=</option><option value="&lt;">&lt;</option><option value="&gt;">&gt;</option><option value="&lt;=">&lt;=</option><option value="&gt;=">&gt;=</option><option value="starts with">starts with</option><option value="contains">contains</option><option value="in">in</option><option value="not in">not in</option></select><input class="string form-control" id="w2p_value_auth_user-last_name" type="text" /><input class="btn btn-default" onclick="w2p_build_query(&#x27;new&#x27;,&#x27;auth_user.last_name&#x27;)" title="Start building a new search" type="button" value="New Search" /><input class="btn btn-default" onclick="w2p_build_query(&#x27;and&#x27;,&#x27;auth_user.last_name&#x27;)" title="Add this to the search as an AND term" type="button" value="+ And" /><input class="btn btn-default" onclick="w2p_build_query(&#x27;or&#x27;,&#x27;auth_user.last_name&#x27;)" title="Add this to the search as an OR term" type="button" value="+ Or" /><input class="btn btn-default" onclick="jQuery(&#x27;#w2p_query_panel&#x27;).slideUp()" type="button" value="Close" /></div><div class="w2p_query_row" id="w2p_field_auth_user-email" style="display:none"><select class="form-control"><option value="=">=</option><option value="!=">!=</option><option value="&lt;">&lt;</option><option value="&gt;">&gt;</option><option value="&lt;=">&lt;=</option><option value="&gt;=">&gt;=</option><option value="starts with">starts with</option><option value="contains">contains</option><option value="in">in</option><option value="not in">not in</option></select><input class="string form-control" id="w2p_value_auth_user-email" type="text" /><input class="btn btn-default" onclick="w2p_build_query(&#x27;new&#x27;,&#x27;auth_user.email&#x27;)" title="Start building a new search" type="button" value="New Search" /><input class="btn btn-default" onclick="w2p_build_query(&#x27;and&#x27;,&#x27;auth_user.email&#x27;)" title="Add this to the search as an AND term" type="button" value="+ And" /><input class="btn btn-default" onclick="w2p_build_query(&#x27;or&#x27;,&#x27;auth_user.email&#x27;)" title="Add this to the search as an OR term" type="button" value="+ Or" /><input class="btn btn-default" onclick="jQuery(&#x27;#w2p_query_panel&#x27;).slideUp()" type="button" value="Close" /></div><div class="w2p_query_row" id="w2p_field_auth_user-username" style="display:none"><select class="form-control"><option value="=">=</option><option value="!=">!=</option><option value="&lt;">&lt;</option><option value="&gt;">&gt;</option><option value="&lt;=">&lt;=</option><option value="&gt;=">&gt;=</option><option value="starts with">starts with</option><option value="contains">contains</option><option value="in">in</option><option value="not in">not in</option></select><input class="string form-control" id="w2p_value_auth_user-username" type="text" /><input class="btn btn-default" onclick="w2p_build_query(&#x27;new&#x27;,&#x27;auth_user.username&#x27;)" title="Start building a new search" type="button" value="New Search" /><input class="btn btn-default" onclick="w2p_build_query(&#x27;and&#x27;,&#x27;auth_user.username&#x27;)" title="Add this to the search as an AND term" type="button" value="+ And" /><input class="btn btn-default" onclick="w2p_build_query(&#x27;or&#x27;,&#x27;auth_user.username&#x27;)" title="Add this to the search as an OR term" type="button" value="+ Or" /><input class="btn btn-default" onclick="jQuery(&#x27;#w2p_query_panel&#x27;).slideUp()" type="button" value="Close" /></div></div><script><!--\n\n        jQuery(\'#w2p_query_fields input,#w2p_query_fields select\').css(\n            \'width\',\'auto\');\n        jQuery(function(){web2py_ajax_fields(\'#w2p_query_fields\');});\n        function w2p_build_query(aggregator,a) {\n          var b=a.replace(\'.\',\'-\');\n          var option = jQuery(\'#w2p_field_\'+b+\' select\').val();\n          var value;\n          var $value_item = jQuery(\'#w2p_value_\'+b);\n          if ($value_item.is(\':checkbox\')){\n            if  ($value_item.is(\':checked\'))\n                    value = \'True\';\n            else  value = \'False\';\n          }\n          else\n          { value = $value_item.val().replace(\'"\',\'\\\\"\')}\n          var s=a+\' \'+option+\' "\'+value+\'"\';\n          var k=jQuery(\'#w2p_keywords\');\n          var v=k.val();\n          if(aggregator==\'new\') k.val(s); else k.val((v?(v+\' \'+ aggregator +\' \'):\'\')+s);\n        }\n        \n//--></script><div class="web2py_counter">1 records found</div></div><div class="web2py_table"><div class="web2py_htmltable" style="width:100%;overflow-x:auto;-ms-overflow-x:scroll"><table><colgroup><col data-column="1" id="auth_user-id" /><col data-column="2" id="auth_user-first_name" /><col data-column="3" id="auth_user-last_name" /><col data-column="4" id="auth_user-email" /><col data-column="5" id="auth_user-username" /><col data-column="6" /></colgroup><thead><tr class=""><th class=""><a href="/a/c/f/auth_user?keywords=&amp;order=auth_user.id">Id</a></th><th class=""><a href="/a/c/f/auth_user?keywords=&amp;order=auth_user.first_name">First name</a></th><th class=""><a href="/a/c/f/auth_user?keywords=&amp;order=auth_user.last_name">Last name</a></th><th class=""><a href="/a/c/f/auth_user?keywords=&amp;order=auth_user.email">E-mail</a></th><th class=""><a href="/a/c/f/auth_user?keywords=&amp;order=auth_user.username">Username</a></th><th class=""></th></tr></thead><tbody><tr class="w2p_odd odd with_id" id="1"><td>1</td><td>Bart</td><td>Simpson</td><td>[email protected]</td><td>user1</td><td class="row_buttons" nowrap="nowrap"><a href="/a/c/f/auth_user/auth_membership.user_id/1"><span>Auth memberships</span></a><a href="/a/c/f/auth_user/auth_event.user_id/1"><span>Auth events</span></a><a href="/a/c/f/auth_user/auth_cas.user_id/1"><span>Auth cases</span></a><a href="/a/c/f/auth_user/t0.created_by/1"><span>T0s(created_by)</span></a><a href="/a/c/f/auth_user/t0.modified_by/1"><span>T0s(modified_by)</span></a><a href="/a/c/f/auth_user/t0_archive.created_by/1"><span>T0 archives(created_by)</span></a><a href="/a/c/f/auth_user/t0_archive.modified_by/1"><span>T0 archives(modified_by)</span></a><a class="button btn btn-default" href="/a/c/f/auth_user/view/auth_user/1"><span class="icon magnifier icon-zoom-in glyphicon glyphicon-zoom-in"></span> <span class="buttontext button" title="View">View</span></a></td></tr></tbody></table></div></div><div class="w2p_export_menu">Export:<a class="btn btn-default" href="/a/c/f/auth_user?_export_type=csv&amp;keywords=&amp;order=" title="Comma-separated export of visible columns. Fields from other tables are exported as they appear on-screen but this may be slow for many rows">CSV</a><a class="btn btn-default" href="/a/c/f/auth_user?_export_type=csv_with_hidden_cols&amp;keywords=&amp;order=" title="Comma-separated export including columns not shown; fields from other tables are exported as raw values for faster export">CSV (hidden cols)</a><a class="btn btn-default" href="/a/c/f/auth_user?_export_type=html&amp;keywords=&amp;order=" title="HTML export of visible columns">HTML</a><a class="btn btn-default" href="/a/c/f/auth_user?_export_type=json&amp;keywords=&amp;order=" title="JSON export of visible columns">JSON</a><a class="btn btn-default" href="/a/c/f/auth_user?_export_type=tsv&amp;keywords=&amp;order=" title="Spreadsheet-optimised export of tab-separated content, visible columns only. May be slow.">TSV (Spreadsheets)</a><a class="btn btn-default" href="/a/c/f/auth_user?_export_type=tsv_with_hidden_cols&amp;keywords=&amp;order=" title="Spreadsheet-optimised export of tab-separated content including hidden columns. May be slow">TSV (Spreadsheets, hidden cols)</a><a class="btn btn-default" href="/a/c/f/auth_user?_export_type=xml&amp;keywords=&amp;order=" title="XML export of columns shown">XML</a></div></div>')
Esempio n. 38
0
File: db.py Progetto: wasuaje/flota
#--------

db.authuser.first_name.requires = IS_NOT_EMPTY(
    error_message=auth.messages.is_empty)
db.authuser.last_name.requires = IS_NOT_EMPTY(
    error_message=auth.messages.is_empty)
db.authuser.password.requires = CRYPT(key=auth.settings.hmac_key)
db.authuser.username.requires = IS_NOT_IN_DB(db, db.authuser.username)
db.authuser.registration_id.requires = IS_NOT_IN_DB(
    db, db.authuser.registration_id)
db.authuser.email.requires = (IS_EMAIL(
    error_message=auth.messages.invalid_email),
                              IS_NOT_IN_DB(db, db.authuser.email))

auth.define_tables(migrate=False)

db.define_table('cf_asignacion_tipo',
                Field('id', 'integer'),
                Field('nombre', 'string'),
                migrate=False)

#--------
db.define_table('cf_cargo',
                Field('id', 'integer'),
                Field('nombre', 'string'),
                migrate=False)
#--------
db.define_table('cf_viaje_tipo',
                Field('id', 'integer'),
                Field('nombre', 'string'),
Esempio n. 39
0
class TestSQLFORM(unittest.TestCase):
    def setUp(self):
        request = Request(env={})
        request.application = 'a'
        request.controller = 'c'
        request.function = 'f'
        request.folder = 'applications/admin'
        response = Response()
        session = Session()
        T = translator('', 'en')
        session.connect(request, response)
        from gluon.globals import current
        current.request = request
        current.response = response
        current.session = session
        current.T = T
        self.db = DAL(DEFAULT_URI, check_reserved=['all'])
        self.auth = Auth(self.db)
        self.auth.define_tables(username=True, signature=False)
        self.db.define_table('t0', Field('tt', default='web2py'),
                             self.auth.signature)
        self.auth.enable_record_versioning(self.db)
        # Create a user
        self.db.auth_user.insert(first_name='Bart',
                                 last_name='Simpson',
                                 username='******',
                                 email='*****@*****.**',
                                 password='******',
                                 registration_key=None,
                                 registration_id=None)

        self.db.commit()

    def test_SQLFORM(self):
        form = SQLFORM(self.db.auth_user)
        self.assertEqual(
            form.xml(),
            b'<form action="#" enctype="multipart/form-data" method="post"><table><tr id="auth_user_first_name__row"><td class="w2p_fl"><label class="" for="auth_user_first_name" id="auth_user_first_name__label">First name: </label></td><td class="w2p_fw"><input class="string" id="auth_user_first_name" name="first_name" type="text" value="" /></td><td class="w2p_fc"></td></tr><tr id="auth_user_last_name__row"><td class="w2p_fl"><label class="" for="auth_user_last_name" id="auth_user_last_name__label">Last name: </label></td><td class="w2p_fw"><input class="string" id="auth_user_last_name" name="last_name" type="text" value="" /></td><td class="w2p_fc"></td></tr><tr id="auth_user_email__row"><td class="w2p_fl"><label class="" for="auth_user_email" id="auth_user_email__label">E-mail: </label></td><td class="w2p_fw"><input class="string" id="auth_user_email" name="email" type="text" value="" /></td><td class="w2p_fc"></td></tr><tr id="auth_user_username__row"><td class="w2p_fl"><label class="" for="auth_user_username" id="auth_user_username__label">Username: </label></td><td class="w2p_fw"><input class="string" id="auth_user_username" name="username" type="text" value="" /></td><td class="w2p_fc"></td></tr><tr id="auth_user_password__row"><td class="w2p_fl"><label class="" for="auth_user_password" id="auth_user_password__label">Password: </label></td><td class="w2p_fw"><input class="password" id="auth_user_password" name="password" type="password" value="" /></td><td class="w2p_fc"></td></tr><tr id="submit_record__row"><td class="w2p_fl"></td><td class="w2p_fw"><input type="submit" value="Submit" /></td><td class="w2p_fc"></td></tr></table></form>'
        )

    def test_represent_SQLFORM(self):
        self.db.t0.tt.represent = lambda value: value.capitalize()
        self.db.t0.tt.writable = False
        self.db.t0.tt.readable = True
        form = SQLFORM(self.db.t0)
        self.assertTrue(b'Web2py' in form.xml())
        self.db.t0.tt.represent = lambda value, row: value.capitalize()
        form = SQLFORM(self.db.t0)
        self.assertTrue(b'Web2py' in form.xml())

    # def test_assert_status(self):
    #     pass

    #  def test_createform(self):
    #     pass

    #  def test_accepts(self):
    #     pass

    #  def test_dictform(self):
    #     pass

    #  def test_smartdictform(self):
    #     pass

    def test_factory(self):
        factory_form = SQLFORM.factory(
            Field('field_one', 'string', IS_NOT_EMPTY()),
            Field('field_two', 'string'))
        self.assertEqual(
            factory_form.xml(),
            b'<form action="#" enctype="multipart/form-data" method="post"><table><tr id="no_table_field_one__row"><td class="w2p_fl"><label class="" for="no_table_field_one" id="no_table_field_one__label">Field One: </label></td><td class="w2p_fw"><input class="string" id="no_table_field_one" name="field_one" type="text" value="" /></td><td class="w2p_fc"></td></tr><tr id="no_table_field_two__row"><td class="w2p_fl"><label class="" for="no_table_field_two" id="no_table_field_two__label">Field Two: </label></td><td class="w2p_fw"><input class="string" id="no_table_field_two" name="field_two" type="text" value="" /></td><td class="w2p_fc"></td></tr><tr id="submit_record__row"><td class="w2p_fl"></td><td class="w2p_fw"><input type="submit" value="Submit" /></td><td class="w2p_fc"></td></tr></table></form>'
        )

    #  def test_build_query(self):
    #     pass

    #  def test_search_menu(self):
    #     pass

    def test_grid(self):
        grid_form = SQLFORM.grid(self.db.auth_user)
        self.assertEqual(
            grid_form.xml(),
            b'<div class="web2py_grid "><div class="web2py_console  "><form action="/a/c/f" enctype="multipart/form-data" method="GET"><input class="form-control" id="w2p_keywords" name="keywords" onfocus="jQuery(&#x27;#w2p_query_fields&#x27;).change();jQuery(&#x27;#w2p_query_panel&#x27;).slideDown();" type="text" value="" /><input class="btn btn-default" type="submit" value="Search" /><input class="btn btn-default" onclick="jQuery(&#x27;#w2p_keywords&#x27;).val(&#x27;&#x27;);" type="submit" value="Clear" /></form><div id="w2p_query_panel" style="display:none;"><select class="form-control" id="w2p_query_fields" onchange="jQuery(&#x27;.w2p_query_row&#x27;).hide();jQuery(&#x27;#w2p_field_&#x27;+jQuery(&#x27;#w2p_query_fields&#x27;).val().replace(&#x27;.&#x27;,&#x27;-&#x27;)).show();" style="float:left"><option value="auth_user.id">Id</option><option value="auth_user.first_name">First name</option><option value="auth_user.last_name">Last name</option><option value="auth_user.email">E-mail</option><option value="auth_user.username">Username</option></select><div class="w2p_query_row" id="w2p_field_auth_user-id" style="display:none"><select class="form-control"><option value="=">=</option><option value="!=">!=</option><option value="&lt;">&lt;</option><option value="&gt;">&gt;</option><option value="&lt;=">&lt;=</option><option value="&gt;=">&gt;=</option><option value="in">in</option><option value="not in">not in</option></select><input class="id form-control" id="w2p_value_auth_user-id" type="text" /><input class="btn btn-default" onclick="w2p_build_query(&#x27;new&#x27;,&#x27;auth_user.id&#x27;)" title="Start building a new search" type="button" value="New Search" /><input class="btn btn-default" onclick="w2p_build_query(&#x27;and&#x27;,&#x27;auth_user.id&#x27;)" title="Add this to the search as an AND term" type="button" value="+ And" /><input class="btn btn-default" onclick="w2p_build_query(&#x27;or&#x27;,&#x27;auth_user.id&#x27;)" title="Add this to the search as an OR term" type="button" value="+ Or" /><input class="btn btn-default" onclick="jQuery(&#x27;#w2p_query_panel&#x27;).slideUp()" type="button" value="Close" /></div><div class="w2p_query_row" id="w2p_field_auth_user-first_name" style="display:none"><select class="form-control"><option value="=">=</option><option value="!=">!=</option><option value="&lt;">&lt;</option><option value="&gt;">&gt;</option><option value="&lt;=">&lt;=</option><option value="&gt;=">&gt;=</option><option value="starts with">starts with</option><option value="contains">contains</option><option value="in">in</option><option value="not in">not in</option></select><input class="string form-control" id="w2p_value_auth_user-first_name" type="text" /><input class="btn btn-default" onclick="w2p_build_query(&#x27;new&#x27;,&#x27;auth_user.first_name&#x27;)" title="Start building a new search" type="button" value="New Search" /><input class="btn btn-default" onclick="w2p_build_query(&#x27;and&#x27;,&#x27;auth_user.first_name&#x27;)" title="Add this to the search as an AND term" type="button" value="+ And" /><input class="btn btn-default" onclick="w2p_build_query(&#x27;or&#x27;,&#x27;auth_user.first_name&#x27;)" title="Add this to the search as an OR term" type="button" value="+ Or" /><input class="btn btn-default" onclick="jQuery(&#x27;#w2p_query_panel&#x27;).slideUp()" type="button" value="Close" /></div><div class="w2p_query_row" id="w2p_field_auth_user-last_name" style="display:none"><select class="form-control"><option value="=">=</option><option value="!=">!=</option><option value="&lt;">&lt;</option><option value="&gt;">&gt;</option><option value="&lt;=">&lt;=</option><option value="&gt;=">&gt;=</option><option value="starts with">starts with</option><option value="contains">contains</option><option value="in">in</option><option value="not in">not in</option></select><input class="string form-control" id="w2p_value_auth_user-last_name" type="text" /><input class="btn btn-default" onclick="w2p_build_query(&#x27;new&#x27;,&#x27;auth_user.last_name&#x27;)" title="Start building a new search" type="button" value="New Search" /><input class="btn btn-default" onclick="w2p_build_query(&#x27;and&#x27;,&#x27;auth_user.last_name&#x27;)" title="Add this to the search as an AND term" type="button" value="+ And" /><input class="btn btn-default" onclick="w2p_build_query(&#x27;or&#x27;,&#x27;auth_user.last_name&#x27;)" title="Add this to the search as an OR term" type="button" value="+ Or" /><input class="btn btn-default" onclick="jQuery(&#x27;#w2p_query_panel&#x27;).slideUp()" type="button" value="Close" /></div><div class="w2p_query_row" id="w2p_field_auth_user-email" style="display:none"><select class="form-control"><option value="=">=</option><option value="!=">!=</option><option value="&lt;">&lt;</option><option value="&gt;">&gt;</option><option value="&lt;=">&lt;=</option><option value="&gt;=">&gt;=</option><option value="starts with">starts with</option><option value="contains">contains</option><option value="in">in</option><option value="not in">not in</option></select><input class="string form-control" id="w2p_value_auth_user-email" type="text" /><input class="btn btn-default" onclick="w2p_build_query(&#x27;new&#x27;,&#x27;auth_user.email&#x27;)" title="Start building a new search" type="button" value="New Search" /><input class="btn btn-default" onclick="w2p_build_query(&#x27;and&#x27;,&#x27;auth_user.email&#x27;)" title="Add this to the search as an AND term" type="button" value="+ And" /><input class="btn btn-default" onclick="w2p_build_query(&#x27;or&#x27;,&#x27;auth_user.email&#x27;)" title="Add this to the search as an OR term" type="button" value="+ Or" /><input class="btn btn-default" onclick="jQuery(&#x27;#w2p_query_panel&#x27;).slideUp()" type="button" value="Close" /></div><div class="w2p_query_row" id="w2p_field_auth_user-username" style="display:none"><select class="form-control"><option value="=">=</option><option value="!=">!=</option><option value="&lt;">&lt;</option><option value="&gt;">&gt;</option><option value="&lt;=">&lt;=</option><option value="&gt;=">&gt;=</option><option value="starts with">starts with</option><option value="contains">contains</option><option value="in">in</option><option value="not in">not in</option></select><input class="string form-control" id="w2p_value_auth_user-username" type="text" /><input class="btn btn-default" onclick="w2p_build_query(&#x27;new&#x27;,&#x27;auth_user.username&#x27;)" title="Start building a new search" type="button" value="New Search" /><input class="btn btn-default" onclick="w2p_build_query(&#x27;and&#x27;,&#x27;auth_user.username&#x27;)" title="Add this to the search as an AND term" type="button" value="+ And" /><input class="btn btn-default" onclick="w2p_build_query(&#x27;or&#x27;,&#x27;auth_user.username&#x27;)" title="Add this to the search as an OR term" type="button" value="+ Or" /><input class="btn btn-default" onclick="jQuery(&#x27;#w2p_query_panel&#x27;).slideUp()" type="button" value="Close" /></div></div><script><!--\n\n        jQuery(\'#w2p_query_fields input,#w2p_query_fields select\').css(\n            \'width\',\'auto\');\n        jQuery(function(){web2py_ajax_fields(\'#w2p_query_fields\');});\n        function w2p_build_query(aggregator,a) {\n          var b=a.replace(\'.\',\'-\');\n          var option = jQuery(\'#w2p_field_\'+b+\' select\').val();\n          var value;\n          var $value_item = jQuery(\'#w2p_value_\'+b);\n          if ($value_item.is(\':checkbox\')){\n            if  ($value_item.is(\':checked\'))\n                    value = \'True\';\n            else  value = \'False\';\n          }\n          else\n          { value = $value_item.val().replace(\'"\',\'\\\\"\')}\n          var s=a+\' \'+option+\' "\'+value+\'"\';\n          var k=jQuery(\'#w2p_keywords\');\n          var v=k.val();\n          if(aggregator==\'new\') k.val(s); else k.val((v?(v+\' \'+ aggregator +\' \'):\'\')+s);\n        }\n        \n//--></script><div class="web2py_counter">1 records found</div></div><div class="web2py_table"><div class="web2py_htmltable" style="width:100%;overflow-x:auto;-ms-overflow-x:scroll"><table><colgroup><col data-column="1" id="auth_user-id" /><col data-column="2" id="auth_user-first_name" /><col data-column="3" id="auth_user-last_name" /><col data-column="4" id="auth_user-email" /><col data-column="5" id="auth_user-username" /><col data-column="6" /></colgroup><thead><tr class=""><th class=""><a href="/a/c/f?keywords=&amp;order=auth_user.id">Id</a></th><th class=""><a href="/a/c/f?keywords=&amp;order=auth_user.first_name">First name</a></th><th class=""><a href="/a/c/f?keywords=&amp;order=auth_user.last_name">Last name</a></th><th class=""><a href="/a/c/f?keywords=&amp;order=auth_user.email">E-mail</a></th><th class=""><a href="/a/c/f?keywords=&amp;order=auth_user.username">Username</a></th><th class=""></th></tr></thead><tbody><tr class="w2p_odd odd with_id" id="1"><td>1</td><td>Bart</td><td>Simpson</td><td>[email protected]</td><td>user1</td><td class="row_buttons" nowrap="nowrap"><a class="button btn btn-default" href="/a/c/f/view/auth_user/1"><span class="icon magnifier icon-zoom-in glyphicon glyphicon-zoom-in"></span> <span class="buttontext button" title="View">View</span></a></td></tr></tbody></table></div></div><div class="w2p_export_menu">Export:<a class="btn btn-default" href="/a/c/f?_export_type=csv&amp;keywords=&amp;order=" title="Comma-separated export of visible columns. Fields from other tables are exported as they appear on-screen but this may be slow for many rows">CSV</a><a class="btn btn-default" href="/a/c/f?_export_type=csv_with_hidden_cols&amp;keywords=&amp;order=" title="Comma-separated export including columns not shown; fields from other tables are exported as raw values for faster export">CSV (hidden cols)</a><a class="btn btn-default" href="/a/c/f?_export_type=html&amp;keywords=&amp;order=" title="HTML export of visible columns">HTML</a><a class="btn btn-default" href="/a/c/f?_export_type=json&amp;keywords=&amp;order=" title="JSON export of visible columns">JSON</a><a class="btn btn-default" href="/a/c/f?_export_type=tsv&amp;keywords=&amp;order=" title="Spreadsheet-optimised export of tab-separated content, visible columns only. May be slow.">TSV (Spreadsheets)</a><a class="btn btn-default" href="/a/c/f?_export_type=tsv_with_hidden_cols&amp;keywords=&amp;order=" title="Spreadsheet-optimised export of tab-separated content including hidden columns. May be slow">TSV (Spreadsheets, hidden cols)</a><a class="btn btn-default" href="/a/c/f?_export_type=xml&amp;keywords=&amp;order=" title="XML export of columns shown">XML</a></div></div>'
        )

    def test_smartgrid(self):
        smartgrid_form = SQLFORM.smartgrid(self.db.auth_user)
        self.assertEqual(
            smartgrid_form.xml(),
            b'<div class="web2py_grid "><div class="web2py_breadcrumbs"><ul class=""><li class="active w2p_grid_breadcrumb_elem"><a href="/a/c/f/auth_user">Auth users</a></li></ul></div><div class="web2py_console  "><form action="/a/c/f/auth_user" enctype="multipart/form-data" method="GET"><input class="form-control" id="w2p_keywords" name="keywords" onfocus="jQuery(&#x27;#w2p_query_fields&#x27;).change();jQuery(&#x27;#w2p_query_panel&#x27;).slideDown();" type="text" value="" /><input class="btn btn-default" type="submit" value="Search" /><input class="btn btn-default" onclick="jQuery(&#x27;#w2p_keywords&#x27;).val(&#x27;&#x27;);" type="submit" value="Clear" /></form><div id="w2p_query_panel" style="display:none;"><select class="form-control" id="w2p_query_fields" onchange="jQuery(&#x27;.w2p_query_row&#x27;).hide();jQuery(&#x27;#w2p_field_&#x27;+jQuery(&#x27;#w2p_query_fields&#x27;).val().replace(&#x27;.&#x27;,&#x27;-&#x27;)).show();" style="float:left"><option value="auth_user.id">Id</option><option value="auth_user.first_name">First name</option><option value="auth_user.last_name">Last name</option><option value="auth_user.email">E-mail</option><option value="auth_user.username">Username</option></select><div class="w2p_query_row" id="w2p_field_auth_user-id" style="display:none"><select class="form-control"><option value="=">=</option><option value="!=">!=</option><option value="&lt;">&lt;</option><option value="&gt;">&gt;</option><option value="&lt;=">&lt;=</option><option value="&gt;=">&gt;=</option><option value="in">in</option><option value="not in">not in</option></select><input class="id form-control" id="w2p_value_auth_user-id" type="text" /><input class="btn btn-default" onclick="w2p_build_query(&#x27;new&#x27;,&#x27;auth_user.id&#x27;)" title="Start building a new search" type="button" value="New Search" /><input class="btn btn-default" onclick="w2p_build_query(&#x27;and&#x27;,&#x27;auth_user.id&#x27;)" title="Add this to the search as an AND term" type="button" value="+ And" /><input class="btn btn-default" onclick="w2p_build_query(&#x27;or&#x27;,&#x27;auth_user.id&#x27;)" title="Add this to the search as an OR term" type="button" value="+ Or" /><input class="btn btn-default" onclick="jQuery(&#x27;#w2p_query_panel&#x27;).slideUp()" type="button" value="Close" /></div><div class="w2p_query_row" id="w2p_field_auth_user-first_name" style="display:none"><select class="form-control"><option value="=">=</option><option value="!=">!=</option><option value="&lt;">&lt;</option><option value="&gt;">&gt;</option><option value="&lt;=">&lt;=</option><option value="&gt;=">&gt;=</option><option value="starts with">starts with</option><option value="contains">contains</option><option value="in">in</option><option value="not in">not in</option></select><input class="string form-control" id="w2p_value_auth_user-first_name" type="text" /><input class="btn btn-default" onclick="w2p_build_query(&#x27;new&#x27;,&#x27;auth_user.first_name&#x27;)" title="Start building a new search" type="button" value="New Search" /><input class="btn btn-default" onclick="w2p_build_query(&#x27;and&#x27;,&#x27;auth_user.first_name&#x27;)" title="Add this to the search as an AND term" type="button" value="+ And" /><input class="btn btn-default" onclick="w2p_build_query(&#x27;or&#x27;,&#x27;auth_user.first_name&#x27;)" title="Add this to the search as an OR term" type="button" value="+ Or" /><input class="btn btn-default" onclick="jQuery(&#x27;#w2p_query_panel&#x27;).slideUp()" type="button" value="Close" /></div><div class="w2p_query_row" id="w2p_field_auth_user-last_name" style="display:none"><select class="form-control"><option value="=">=</option><option value="!=">!=</option><option value="&lt;">&lt;</option><option value="&gt;">&gt;</option><option value="&lt;=">&lt;=</option><option value="&gt;=">&gt;=</option><option value="starts with">starts with</option><option value="contains">contains</option><option value="in">in</option><option value="not in">not in</option></select><input class="string form-control" id="w2p_value_auth_user-last_name" type="text" /><input class="btn btn-default" onclick="w2p_build_query(&#x27;new&#x27;,&#x27;auth_user.last_name&#x27;)" title="Start building a new search" type="button" value="New Search" /><input class="btn btn-default" onclick="w2p_build_query(&#x27;and&#x27;,&#x27;auth_user.last_name&#x27;)" title="Add this to the search as an AND term" type="button" value="+ And" /><input class="btn btn-default" onclick="w2p_build_query(&#x27;or&#x27;,&#x27;auth_user.last_name&#x27;)" title="Add this to the search as an OR term" type="button" value="+ Or" /><input class="btn btn-default" onclick="jQuery(&#x27;#w2p_query_panel&#x27;).slideUp()" type="button" value="Close" /></div><div class="w2p_query_row" id="w2p_field_auth_user-email" style="display:none"><select class="form-control"><option value="=">=</option><option value="!=">!=</option><option value="&lt;">&lt;</option><option value="&gt;">&gt;</option><option value="&lt;=">&lt;=</option><option value="&gt;=">&gt;=</option><option value="starts with">starts with</option><option value="contains">contains</option><option value="in">in</option><option value="not in">not in</option></select><input class="string form-control" id="w2p_value_auth_user-email" type="text" /><input class="btn btn-default" onclick="w2p_build_query(&#x27;new&#x27;,&#x27;auth_user.email&#x27;)" title="Start building a new search" type="button" value="New Search" /><input class="btn btn-default" onclick="w2p_build_query(&#x27;and&#x27;,&#x27;auth_user.email&#x27;)" title="Add this to the search as an AND term" type="button" value="+ And" /><input class="btn btn-default" onclick="w2p_build_query(&#x27;or&#x27;,&#x27;auth_user.email&#x27;)" title="Add this to the search as an OR term" type="button" value="+ Or" /><input class="btn btn-default" onclick="jQuery(&#x27;#w2p_query_panel&#x27;).slideUp()" type="button" value="Close" /></div><div class="w2p_query_row" id="w2p_field_auth_user-username" style="display:none"><select class="form-control"><option value="=">=</option><option value="!=">!=</option><option value="&lt;">&lt;</option><option value="&gt;">&gt;</option><option value="&lt;=">&lt;=</option><option value="&gt;=">&gt;=</option><option value="starts with">starts with</option><option value="contains">contains</option><option value="in">in</option><option value="not in">not in</option></select><input class="string form-control" id="w2p_value_auth_user-username" type="text" /><input class="btn btn-default" onclick="w2p_build_query(&#x27;new&#x27;,&#x27;auth_user.username&#x27;)" title="Start building a new search" type="button" value="New Search" /><input class="btn btn-default" onclick="w2p_build_query(&#x27;and&#x27;,&#x27;auth_user.username&#x27;)" title="Add this to the search as an AND term" type="button" value="+ And" /><input class="btn btn-default" onclick="w2p_build_query(&#x27;or&#x27;,&#x27;auth_user.username&#x27;)" title="Add this to the search as an OR term" type="button" value="+ Or" /><input class="btn btn-default" onclick="jQuery(&#x27;#w2p_query_panel&#x27;).slideUp()" type="button" value="Close" /></div></div><script><!--\n\n        jQuery(\'#w2p_query_fields input,#w2p_query_fields select\').css(\n            \'width\',\'auto\');\n        jQuery(function(){web2py_ajax_fields(\'#w2p_query_fields\');});\n        function w2p_build_query(aggregator,a) {\n          var b=a.replace(\'.\',\'-\');\n          var option = jQuery(\'#w2p_field_\'+b+\' select\').val();\n          var value;\n          var $value_item = jQuery(\'#w2p_value_\'+b);\n          if ($value_item.is(\':checkbox\')){\n            if  ($value_item.is(\':checked\'))\n                    value = \'True\';\n            else  value = \'False\';\n          }\n          else\n          { value = $value_item.val().replace(\'"\',\'\\\\"\')}\n          var s=a+\' \'+option+\' "\'+value+\'"\';\n          var k=jQuery(\'#w2p_keywords\');\n          var v=k.val();\n          if(aggregator==\'new\') k.val(s); else k.val((v?(v+\' \'+ aggregator +\' \'):\'\')+s);\n        }\n        \n//--></script><div class="web2py_counter">1 records found</div></div><div class="web2py_table"><div class="web2py_htmltable" style="width:100%;overflow-x:auto;-ms-overflow-x:scroll"><table><colgroup><col data-column="1" id="auth_user-id" /><col data-column="2" id="auth_user-first_name" /><col data-column="3" id="auth_user-last_name" /><col data-column="4" id="auth_user-email" /><col data-column="5" id="auth_user-username" /><col data-column="6" /></colgroup><thead><tr class=""><th class=""><a href="/a/c/f/auth_user?keywords=&amp;order=auth_user.id">Id</a></th><th class=""><a href="/a/c/f/auth_user?keywords=&amp;order=auth_user.first_name">First name</a></th><th class=""><a href="/a/c/f/auth_user?keywords=&amp;order=auth_user.last_name">Last name</a></th><th class=""><a href="/a/c/f/auth_user?keywords=&amp;order=auth_user.email">E-mail</a></th><th class=""><a href="/a/c/f/auth_user?keywords=&amp;order=auth_user.username">Username</a></th><th class=""></th></tr></thead><tbody><tr class="w2p_odd odd with_id" id="1"><td>1</td><td>Bart</td><td>Simpson</td><td>[email protected]</td><td>user1</td><td class="row_buttons" nowrap="nowrap"><a href="/a/c/f/auth_user/auth_membership.user_id/1"><span>Auth memberships</span></a><a href="/a/c/f/auth_user/auth_event.user_id/1"><span>Auth events</span></a><a href="/a/c/f/auth_user/auth_cas.user_id/1"><span>Auth cases</span></a><a href="/a/c/f/auth_user/t0.created_by/1"><span>T0s(created_by)</span></a><a href="/a/c/f/auth_user/t0.modified_by/1"><span>T0s(modified_by)</span></a><a href="/a/c/f/auth_user/t0_archive.created_by/1"><span>T0 archives(created_by)</span></a><a href="/a/c/f/auth_user/t0_archive.modified_by/1"><span>T0 archives(modified_by)</span></a><a class="button btn btn-default" href="/a/c/f/auth_user/view/auth_user/1"><span class="icon magnifier icon-zoom-in glyphicon glyphicon-zoom-in"></span> <span class="buttontext button" title="View">View</span></a></td></tr></tbody></table></div></div><div class="w2p_export_menu">Export:<a class="btn btn-default" href="/a/c/f/auth_user?_export_type=csv&amp;keywords=&amp;order=" title="Comma-separated export of visible columns. Fields from other tables are exported as they appear on-screen but this may be slow for many rows">CSV</a><a class="btn btn-default" href="/a/c/f/auth_user?_export_type=csv_with_hidden_cols&amp;keywords=&amp;order=" title="Comma-separated export including columns not shown; fields from other tables are exported as raw values for faster export">CSV (hidden cols)</a><a class="btn btn-default" href="/a/c/f/auth_user?_export_type=html&amp;keywords=&amp;order=" title="HTML export of visible columns">HTML</a><a class="btn btn-default" href="/a/c/f/auth_user?_export_type=json&amp;keywords=&amp;order=" title="JSON export of visible columns">JSON</a><a class="btn btn-default" href="/a/c/f/auth_user?_export_type=tsv&amp;keywords=&amp;order=" title="Spreadsheet-optimised export of tab-separated content, visible columns only. May be slow.">TSV (Spreadsheets)</a><a class="btn btn-default" href="/a/c/f/auth_user?_export_type=tsv_with_hidden_cols&amp;keywords=&amp;order=" title="Spreadsheet-optimised export of tab-separated content including hidden columns. May be slow">TSV (Spreadsheets, hidden cols)</a><a class="btn btn-default" href="/a/c/f/auth_user?_export_type=xml&amp;keywords=&amp;order=" title="XML export of columns shown">XML</a></div></div>'
        )
Esempio n. 40
0
    Field('room_partner',unique=True),
    #Field('room_alotted_or_not',requires=IS_IN_SET(['Yes','No'])),
    Field('phone_number',requires=IS_MATCH('^\s*(?:\+?(\d{1,3}))?[-. (]*(\d{3})[-. )]*(\d{3})[-. ]*(\d{4})(?: *x(\d+))?\s*$')),
    Field('physically_handicapped',requires=IS_IN_SET(['Yes','No'])),
    Field('admission_number'),
    #Field('which_hostel',requires=IS_IN_SET(['Boys Hostel','Girls Hostel'])),
    #Field('floor_no',requires=IS_IN_SET(['Ground','First','Second','Third','Fourth'])),
    Field('room_number',requires= [IS_INT_IN_RANGE(1,29) or IS_MATCH('^\d{1}([A-Z])')]),
    Field('type_of_account',requires=IS_IN_SET(['Student','Faculty','Hostel Committee','Super Admin']))]


#if db.auth_user.which_hostel=='Boys Hostel':
#    auth.settings.extra_fields['auth_user']=[Field('room_number')]
    #Field('which_hostel',requires=IS_IN_SET(['Boys Hostel','Girls Hostel'])),
    #Field('floor_no',requires=IS_IN_SET(['Ground','First','Second','Third','Fourth']))]
auth.define_tables(migrate=False)
#db.auth_user.email.requires=IS_EMAIL(forced='^.*\.in(|\..*)$')

db.auth_user.email.requires=IS_IIITS("iiits.in")
'''auth.settings.manager_actions = dict(
    db_admin=dict(role='Super', heading="Manage Database", tables=db.tables),
    content_admin=dict(role='Content Manager', tables=[content_db.articles, content_db.recipes, content_db.comments]),
    content_mgr_grp_v2 = dict(role='Content Manager v2', db=content_db,
        tables=['articles','recipes','comments'],
        smartgrid_args=dict(
                DEFAULT=dict(maxtextlength=50,paginate=30),
                comments=dict(maxtextlength=100,editable=False)
        )
    )
'''
###############################################################
Esempio n. 41
0
def define_new_tables(db):

    auth = Auth(db)
    auth.define_tables(username=False, signature=False,migrate=False)

    db.define_table('bibliography',
                    Field('title','string'))

    db.define_table('user_document',
                    Field('citation_id','integer'),
                    Field('file_upload','upload'),
                    Field('file_name','string'),
                    Field('last_modified','datetime'),
                    Field('date_created','datetime'),
                    Field('d_pkey', 'integer'),
                    Field('d_id', 'string'),
                    Field('d_cid', 'integer'),
                    Field('d_lang', 'string'),
                    Field('d_type', 'string'),
                    Field('d_url', 'text'),
                    Field('d_ckey', 'integer'),
                    Field('d_cdate', 'integer'),
                    Field('d_mdate', 'integer'),
                    Field('d_owner', 'integer'))


    db.define_table('review',
                     Field('user_id','integer'),
                     Field('title','string'),
                     Field('body','text'),
                     Field('user_documents','list:string'),
                     Field('tags','list:string'),
                     Field('date_created','datetime'),
                     Field('date_modified','datetime'),
                     Field('study_purpose','text'),
                     Field('study_subjects','text'),
                     Field('study_design','text'),
                     Field('study_measures','text'),
                     Field('study_analyses','text'),
                     Field('study_results','text'),
                     Field('study_effects_observed','text'),
                     Field('study_effects_a','text'),
                     Field('study_comments','text'),
                     Field('review_type','string'),
                     Field('s_id','integer'),
                     Field('s_ckey','integer'),
                     Field('s_keywords','string'),
                     Field('r_id','integer'),
                     Field('r_ckey','integer'))

    db.review.user_documents.default = []
    db.review.tags.default = []
    
    db.define_table('citation',
                    Field('user_id','integer'),
                    Field('publicly_searchable','boolean'),
                    Field('primary_document','reference user_document'),
                    Field('author','string'),
                    Field('title','text'),
                    Field('journal','text'),
                    Field('publication_date','string'),
                    Field('issue','string'),
                    Field('page_span','string'),
                    Field('abstract','text'),
                    Field('isbn_issn','string'),
                    Field('collections','list:reference bibliography'),
                    Field('downloadable_resources','list:reference user_document'),
                    Field('literature_reviews','list:reference review'),
                    Field('tags','list:string'),
                    Field('last_modified','datetime'),
                    Field('date_created','datetime'),
                    Field('c_pkey','integer'),
                    Field('c_key', 'string'),
                    Field('c_id', 'string'),
                    Field('c_auth', 'string'),
                    Field('c_date', 'string'),
                    Field('c_title', 'text'),
                    Field('c_name', 'string'),
                    Field('c_issue', 'string'),
                    Field('c_pages', 'string'),
                    Field('c_abstract', 'text'),
                    Field('c_subjects', 'string'),
                    Field('c_bibname', 'string'),
                    Field('c_ishof', 'string'),
                    Field('c_lsdid', 'string'),
                    Field('c_psiid', 'string'),
                    Field('c_catnum', 'string'),
                    Field('c_keywords', 'string'),
                    Field('c_category', 'string'),
                    Field('c_af', 'text'),
                    Field('c_cdate', 'integer'),
                    Field('c_mdate', 'integer'),
                    Field('c_pmid', 'integer'),
                    Field('c_owner', 'integer'),
                    Field('c_mode','string'))

    db.citation.collections.default = []
    db.citation.downloadable_resources.default = []
    db.citation.literature_reviews.default = []


    db.define_table('tag',
                    Field('title','string'),
                    Field('description','text'))

    db.user_document.file_upload.uploadfs = UPLOAD_FILESYSTEM
Esempio n. 42
0
    format='%(username)s',
    migrate=settings.migrate)

db.auth_user.first_name.requires = IS_NOT_EMPTY(error_message=auth.messages.is_empty)
db.auth_user.last_name.requires = IS_NOT_EMPTY(error_message=auth.messages.is_empty)
db.auth_user.password.requires = CRYPT(key=auth.settings.hmac_key)
db.auth_user.username.requires = IS_NOT_IN_DB(db, db.auth_user.username)
db.auth_user.registration_id.requires = IS_NOT_IN_DB(db, db.auth_user.registration_id)
db.auth_user.email.requires = (IS_EMAIL(error_message=auth.messages.invalid_email),
                               IS_NOT_IN_DB(db, db.auth_user.email))
db.auth_user.first_name.writable = True
db.auth_user.last_name.writable  = True
db.auth_user.username.writable = True
db.auth_user.email.writable  = True
auth.settings.create_user_groups = False
auth.define_tables(migrate = settings.migrate)

## configure email
mail=auth.settings.mailer
mail.settings.server = 'smtp.gmail.com:587'
mail.settings.sender = '*****@*****.**'
mail.settings.login = '******'

## configure auth policy
auth.settings.registration_requires_verification = False
auth.settings.registration_requires_approval = False
auth.settings.reset_password_requires_verification = True

## if you need to use OpenID, Facebook, MySpace, Twitter, Linkedin, etc.
## register with janrain.com, write your domain:api_key in private/janrain.key
from gluon.contrib.login_methods.rpx_account import use_janrain, RPXAccount
Esempio n. 43
0
## - email capabilities
## - authentication (registration, login, logout, ... )
## - authorization (role based authorization)
## - services (xml, csv, json, xmlrpc, jsonrpc, amf, rss)
## - old style crud actions
## (more options discussed in gluon/tools.py)
#########################################################################

from gluon.tools import Auth, Service, PluginManager

auth = Auth(db)
service = Service()
plugins = PluginManager()

## create all tables needed by auth if not custom tables
auth.define_tables(username=False, signature=True, enable_tokens=True)

## configure email
mail = auth.settings.mailer
mail.settings.server = 'secure.emailsrvr.com:465' #'logging' if request.is_local else 'secure.emailsrvr.com:465'
mail.settings.sender = '*****@*****.**'
mail.settings.login = '******'
mail.settings.ssl = True

## configure auth policy
#auth.settings.create_user_groups = False
auth.settings.registration_requires_verification = False
auth.settings.registration_requires_approval = False
auth.settings.reset_password_requires_verification = True
#auth.settings.actions_disabled.append('register')
auth.settings.email_case_sensitive = False
Esempio n. 44
0
    Field('nombre', 'string', length=128, label='Nombre de la Sucursal'),
    db.persona,
    format='%(nombre)s'
    )

db.define_table('departamento',
    Field('sucursal_id', 'reference sucursal', label='Sucursal'),
    Field('nombre', 'string', length=128),
    format='%(nombre)s'
    )

auth.settings.extra_fields['auth_user']= [
    Field('empleado_id', 'reference empleado'),
    ]

auth.define_tables(username=False, signature=False, migrate=False) ##creamos las tablas auth
##auth.define_tables(username=False, signature=False)

db.auth_user._format = '%(first_name)s %(last_name)s (%(email)s)'
auth.settings.everybody_group_id = 1 ##asignar a nuevos usuarios a un grupo por default 1=ADMIN, 2=BASICO, 3=ETC
auth.settings.create_user_groups = None

db.define_table('cc_empresa',
    Field('empresa_id', 'reference empresa', label='Empresa'),
    Field('num_cc', 'string', length=128, label='Número de Cuenta Contable'),
    Field('descripcion', 'string', length=128, label='Descripción'),
    Field('nivel', 'integer'),
    Field('naturaleza', 'string', length=40),
    format='%(num_cc)s %(descripcion)s'
    )
Esempio n. 45
0
	))]


elif settings.login_method == 'CAS':

	auth = Auth(db,cas_provider = settings.cas_provider)
	auth.settings.cas_actions['login']=settings.cas_actions_login
	auth.settings.cas_actions['validate']=settings.cas_actions_validate
	auth.settings.cas_actions['logout']=settings.cas_actions_logout


crud, service, plugins = Crud(db), Service(), PluginManager()

## create all tables needed by auth if not custom tables
auth.define_tables(username=True, signature=False, migrate=settings.migrate)

#We dont create a group for each user
auth.settings.create_user_groups=False

## configure auth policy
auth.settings.registration_requires_verification = False
auth.settings.registration_requires_approval = False
auth.settings.reset_password_requires_verification = False

if settings.login_method == 'CAS' or settings.login_method == 'ldap':
	auth.settings.actions_disabled.append('register')
	auth.settings.actions_disabled.append('change_password')

auth.settings.actions_disabled.append('request_reset_password')
auth.settings.actions_disabled.append('retrieve_username')
Esempio n. 46
0
    Field('active',type='boolean',writable=False,readable=False,default=True),
#    format='%(username)s',
    format=lambda u: u.first_name + " " + u.last_name,
    migrate='runestone_auth_user.table')


db.auth_user.first_name.requires = IS_NOT_EMPTY(error_message=auth.messages.is_empty)
db.auth_user.last_name.requires = IS_NOT_EMPTY(error_message=auth.messages.is_empty)
db.auth_user.password.requires = CRYPT(key=auth.settings.hmac_key)
db.auth_user.username.requires = (HAS_NO_DOTS(), IS_NOT_IN_DB(db, db.auth_user.username))
db.auth_user.registration_id.requires = IS_NOT_IN_DB(db, db.auth_user.registration_id)
db.auth_user.email.requires = (IS_EMAIL(error_message=auth.messages.invalid_email),
                               IS_NOT_IN_DB(db, db.auth_user.email))
db.auth_user.course_id.requires = IS_COURSE_ID()

auth.define_tables(username=True, signature=False, migrate='runestone_')

# create the instructor group if it doesn't already exist
if not db(db.auth_group.role == 'instructor').select().first():
    db.auth_group.insert(role='instructor')

## configure email
mail=auth.settings.mailer
mail.settings.server = 'logging' or 'smtp.gmail.com:587'
mail.settings.sender = '*****@*****.**'
mail.settings.login = '******'

## configure auth policy
auth.settings.registration_requires_verification = False
auth.settings.registration_requires_approval = False
auth.settings.reset_password_requires_verification = True
Esempio n. 47
0
File: db.py Progetto: ksdtech/vppmgr
    Field('reset_password_key',default='',
          writable=False,readable=False),
    Field('registration_id',default='',
          writable=False,readable=False),
    format='%(email)s',
    migrate=settings.migrate)


db.auth_user.first_name.requires = IS_NOT_EMPTY(error_message=auth.messages.is_empty)
db.auth_user.last_name.requires = IS_NOT_EMPTY(error_message=auth.messages.is_empty)
db.auth_user.password.requires = CRYPT(key=auth.settings.hmac_key)
# db.auth_user.username.requires = IS_NOT_IN_DB(db, db.auth_user.username)
db.auth_user.registration_id.requires = IS_NOT_IN_DB(db, db.auth_user.registration_id)
db.auth_user.email.requires = (IS_EMAIL(error_message=auth.messages.invalid_email),
                               IS_NOT_IN_DB(db, db.auth_user.email))
auth.define_tables(username=False, migrate=settings.migrate)

## configure email for Kentfield Google Apps
mail = auth.settings.mailer
mail.settings.server = settings.email_server
mail.settings.sender = settings.email_sender
mail.settings.login  = settings.email_login

## configure auth policy
auth.settings.registration_requires_verification = False
auth.settings.registration_requires_approval = False
auth.settings.reset_password_requires_verification = True

## if you need to use OpenID, Facebook, MySpace, Twitter, Linkedin, etc.
## register with janrain.com, write your domain:api_key in private/janrain.key
from gluon.contrib.login_methods.rpx_account import use_janrain
Esempio n. 48
0
import random
import time

now = time.time()
import datetime

timestamp = datetime.datetime.today()
today = datetime.date.today()

db = DAL("sqlite://main.db")

from gluon.tools import Auth

auth = Auth(db)

auth.settings.extra_fields["auth_user"] = [Field("name", compute=lambda r: "%(first_name)s %(last_name)s" % r)]
auth.define_tables()
Esempio n. 49
0
    error_message=auth.messages.is_empty)
db.auth_user.password.requires = CRYPT(key=auth.settings.hmac_key)
db.auth_user.username.requires = (
    HAS_NO_DOTS(),
    IS_NOT_IN_DB(db, db.auth_user.username),
)
db.auth_user.registration_id.requires = IS_NOT_IN_DB(
    db, db.auth_user.registration_id)
db.auth_user.email.requires = (
    IS_EMAIL(error_message=auth.messages.invalid_email),
    IS_NOT_IN_DB(db, db.auth_user.email),
)
db.auth_user.course_id.requires = IS_COURSE_ID()

auth.define_tables(username=True,
                   signature=False,
                   migrate=table_migrate_prefix + "")

# Because so many pages rely on `views/_sphinx_static_file.html` it makes
# sense to provide some default values for variables used in the template here
# The latex_preamble attribute can be used for any custom latex macros used in
# the text, that need to be available for grading, assignments, and practice
# This is used in nearly every PreTeXt book.
request.latex_preamble = ""


def set_latex_preamble(base_course: str):
    # See `models/db_ebook.py` for course_attributes table
    bc = db(db.courses.course_name == base_course).select().first()
    res = (
        db((db.course_attributes.course_id == bc.id)