Ejemplo n.º 1
0
 def __init__(self, db):
     self.db = db
     self.hmac_key = Auth.get_or_create_key()
     Auth.__init__(self, self.db, hmac_key=self.hmac_key)
     #self.settings.logout_onlogout = lambda user: remove_session(user)
     #self.settings.register_onaccept = lambda form: add_to_users_group(form)
     self.settings.controller = 'person'
     self.settings.on_failed_authorization = self.url('account', args='not_authorized')
     self.settings.formstyle = 'divs'
     self.settings.label_separator = ''
     self.settings.register_next = self.url('show')
     self.settings.registration_requires_verification = self.db.config.auth.registration_requires_verification
     self.settings.registration_requires_approval = self.db.config.auth.registration_requires_approval
     if 'register' in self.db.request.args and self.db.config.auth.use_recaptcha:
         from gluon.tools import Recaptcha
         recaptcha_options = dict(self.db.config.get_list('auth', 'recaptcha'))
         self.settings.captcha = Recaptcha(self.db.request,
                                 recaptcha_options['public'],
                                 recaptcha_options['private'],
                                 options="theme:'%(theme)s', lang:'%(lang)s'" % recaptcha_options)
     from datamodel.user import User
     user = User(self)
     self.entity = user.entity
     if self.db.config.auth.server == 'default':
         self.settings.mailer = Mailer(self.db)
     else:
         self.settings.mailer.server = self.db.config.auth.server
         self.settings.mailer.sender = self.db.config.auth.sender
         self.settings.mailer.login = self.db.config.auth.login
Ejemplo 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()
Ejemplo n.º 3
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()
Ejemplo n.º 4
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
Ejemplo n.º 5
0
    def __init__(self, db):
        self.db = db
        self.hmac_key = Auth.get_or_create_key()
        Auth.__init__(self, self.db, hmac_key=self.hmac_key)
        #self.settings.logout_onlogout = lambda user: self.remove_session(user)
        #self.settings.register_onaccept = lambda form: add_to_users_group(form)
        self.settings.register_onaccept = [lambda form: self.send_welcome_email(form.vars),
                                           lambda form: self.initial_user_permission(form.vars)]
        #self.settings.login_onaccept = [lambda form: self.initial_user_permission(form.vars)]
        #self.settings.profile_onvalidation = []
        self.settings.profile_onaccept = [lambda form: self.remove_facebook_google_alert(form)]  # remove facebook / google alert session
        #self.settings.change_password_onaccept = [] # send alert email
        self.settings.controller = 'person'
        self.settings.allow_basic_login = True
        self.settings.register_verify_password = True
        self.settings.login_url = self.url('account', args='login')
        self.settings.verify_email_next = self.url('account', args='login')
        self.settings.logged_url = self.url('account', args='profile')
        self.settings.login_next = self.db.CURL('person', 'show')
        self.settings.register_next = self.db.CURL('person', 'show')
        self.settings.profile_next = self.db.CURL('person', 'account', args='profile')
        self.settings.retrieve_username_next = self.url('account', args='login')
        self.settings.retrieve_password_next = self.url('account', args='login')
        self.settings.request_reset_password_next = self.url('account', args='login')
        self.settings.reset_password_next = self.url('account', args='login')
        self.settings.change_password_next = self.db.CURL('person', 'show')

        self.messages.verify_email = \
            'Click on the link http://' + self.db.request.env.http_host + \
            self.db.CURL('person', 'account', args=['verify_email']) + \
            '/%(key)s to verify your email'

        self.messages.reset_password = \
            'Click on the link http://' + self.db.request.env.http_host + \
            self.db.CURL('person', 'account', args=['reset_password']) + \
            '/%(key)s to reset your password'

        self.settings.on_failed_authorization = self.url('account', args='not_authorized')
        self.settings.formstyle = 'divs'
        self.settings.label_separator = ''
        self.settings.register_next = self.url('show')
        self.settings.registration_requires_verification = self.db.config.auth.registration_requires_verification
        self.settings.registration_requires_approval = self.db.config.auth.registration_requires_approval
        if 'register' in self.db.request.args and self.db.config.auth.use_recaptcha:
            from gluon.tools import Recaptcha
            recaptcha_options = dict(self.db.config.get_list('auth', 'recaptcha'))
            self.settings.captcha = Recaptcha(self.db.request,
                                    recaptcha_options['public'],
                                    recaptcha_options['private'],
                                    options="theme:'%(theme)s', lang:'%(lang)s'" % recaptcha_options)
        from datamodel.user import User
        user = User(self)
        self.entity = user.entity
        if self.db.config.auth.server == 'default':
            self.settings.mailer = Mailer(self.db)
        else:
            self.settings.mailer.server = self.db.config.auth.server
            self.settings.mailer.sender = self.db.config.auth.sender
            self.settings.mailer.login = self.db.config.auth.login
Ejemplo n.º 6
0
def login():
    from gluon.tools import Auth, Crud, Service, PluginManager, prettydate
    auth = Auth(db_maestro)
    ## configure email
    mail = auth.settings.mailer
    mail.settings.server = 'smtp.gmail.com:587'
    mail.settings.sender = '*****@*****.**'
    mail.settings.login = '******'
    form = auth.login()
    return dict(form=form, formReset = auth.retrieve_password())
Ejemplo n.º 7
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
Ejemplo n.º 8
0
 def __init__(self, file, globals, db, mail):
     ''' Inicio de variables globales
         que pertenecen al framework'''
         
     Auth.__init__(self, globals, db)
     datos           = ConvertXmlToDict(file)
     self.config     = datos.config_var
     self.globals    = globals
     self.db   		= db
     self.mail 		= mail
     self.setMessa()
Ejemplo n.º 9
0
    def __init__(self, db):
        self.db = db
        self.hmac_key = Auth.get_or_create_key()
        Auth.__init__(self, self.db, hmac_key=self.hmac_key)
        user = User(self)
        self.entity = user.entity

        # READ AUTH CONFIGURATION FROM CONFIG
        self.settings.formstyle = self.db.config.auth.formstyle
        if self.db.config.auth.server == "default":
            self.settings.mailer = Mailer(self.db.config)
        else:
            self.settings.mailer.server = self.db.config.auth.server
            self.settings.mailer.sender = self.db.config.auth.sender
            self.settings.mailer.login = self.db.config.auth.login
Ejemplo n.º 10
0
    def __init__(self, environment, deployment_settings, db=None):

        """ Initialise parent class & make any necessary modifications """

        Auth.__init__(self, environment, db)

        self.deployment_settings = deployment_settings
        self.session = self.environment.session

        self.settings.lock_keys = False
        self.settings.username_field = False
        self.settings.lock_keys = True
        self.messages.lock_keys = False
        self.messages.email_sent = 'Verification Email sent - please check your email to validate. If you do not receive this email please check you junk email or spam filters'
        self.messages.email_verified = 'Email verified - you can now login'
        self.messages.registration_disabled = "Registration Disabled!"
        self.messages.lock_keys = True
Ejemplo n.º 11
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
Ejemplo n.º 12
0
 def __init__(self, environment, p, db=None, migrate=True):
     Auth.__init__(self, environment, db)
     global T
     T = p
     self.messages.invalid_login = T("We're sorry. " + \
         "The email or password you entered didn't match our records.  " + \
         "Please try again.")
     self.messages.lock_keys = False
     self.messages.disabled_login = T('Sorry. Your account has been disabled. Please contact support.')
     self.messages.lock_keys = True
     self.settings.table_user = db.define_table(
         self.settings.table_user_name,
         db.Field('first_name', length=128,default=''),
         db.Field('last_name', length=128,default=''),
         db.Field('email', length=128,default='',unique=True),
         db.Field('twitter_id', length=128,default=None,unique=True),
         db.Field('facebook_id', length=128,default=None,unique=True),
         db.Field('password', 'password', readable=False),
         db.Field('marketing', 'boolean', default=False),
         db.Field('zipcode', 'integer'),
         db.Field('birthday', 'date'),
         db.Field('registration_key', length=128, writable=False,
                  readable=False,default=''),
         migrate=migrate)
     table = self.settings.table_user
     table.first_name.requires = IS_NOT_EMPTY()
     table.last_name.requires = IS_NOT_EMPTY()
     table.password.requires = [IS_LENGTH(minsize=6,
                                 error_message="We're sorry.  Please " + \
                                 "enter a password with at least six " + \
                                 "characters."),
                                CRYPT()]
     table.email.requires = [IS_EMAIL(error_message=T("Please enter a valid email address.")),
                          IS_NOT_IN_DB(db, '%s.email'
                          % self.settings.table_user._tablename,
                          error_message=T("We're sorry. " + \
                          "That email address already exists in our system. " + \
                          "Please login or choose another email address."))]
     table.zipcode.requires = IS_NULL_OR(IS_INT_IN_RANGE(1, 99999,
                                              error_message=T("Invalid Zip Code")))
     table.birthday.requires=IS_NULL_OR(IS_DATE(format=T('%Y-%m-%d'),
                                     error_message=T('must be YYYY-MM-DD!')))
     table.registration_key.default = ''
Ejemplo n.º 13
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()
    def setUp(self):
        global request, session, auth
        request = Request(globals())  # Use a clean Request object
        request.application = 'runestone'
        session = Session()
        auth = Auth(db, hmac_key=Auth.get_or_create_key())
        # bring in the ajax controllers
        exec(compile(open("applications/runestone/controllers/ajax.py").read(), "applications/runestone/controllers/ajax.py", 'exec'), globals())

        # Create a default user and course.
        self.course_name_1 = 'test_course_1'
        self.course_id_1 = self.createCourse(self.course_name_1)
        self.user_name_1 = 'test_user_1'
        self.user_id_1 = self.createUser(self.user_name_1, self.course_id_1)
Ejemplo n.º 15
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>')
Ejemplo n.º 16
0
 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
Ejemplo n.º 17
0
if request.env.web2py_runtime_gae:  # if running on Google App Engine
    db = DAL('gae')  # connect to Google BigTable
    session.connect(request, response,
                    db=db)  # and store sessions and tickets there
    ### or use the following lines to store sessions in Memcache
    # from gluon.contrib.memdb import MEMDB
    # from google.appengine.api.memcache import Client
    # session.connect(request, response, db = MEMDB(Client()))
else:  # else use a normal relational database
    db = DAL(settings.database_uri,
             check_reserved=['all'],
             lazy_tables=lazy_tables,
             pool_size=pool_size)

auth = Auth(db)  # authentication/authorization
crud = Crud(db)  # for CRUD helpers using auth
service = Service()  # for json, xml, jsonrpc, xmlrpc, amfrpc
plugins = PluginManager()
#db._common_fields.append(auth.signature)

auth.settings.hmac_key = settings.kvasir_config.get(
    'security_key')  # before define_tables()
auth.settings.actions_disabled = [
    'register', 'request_reset_password', 'retrieve_username'
]
auth.settings.allow_basic_login = True
#crud.settings.auth = auth                      # =auth to enforce authorization on crud
current.auth = auth

response.generic_patterns = ['*.load', '*.json', '*.xml', '*.html', '*.csv']
Ejemplo n.º 18
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),
Ejemplo n.º 19
0
## (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 gluon.tools import Auth, Crud, Service, PluginManager, prettydate
auth = Auth(db, csrf_prevention=False)
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
Ejemplo n.º 20
0
## (optional) static assets folder versioning
# response.static_version = '0.0.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, Mail, datetime, prettydate

crud = Crud(db)
auth = Auth(db, hmac_key=Auth.get_or_create_key())
service = Service()
plugins = PluginManager()

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

# all we need is login
auth.settings.actions_disabled = [
    'register', 'change_password', 'request_reset_password',
    'retrieve_username', 'profile'
]

# you don't have to remember me
auth.settings.remember_me_form = False
Ejemplo n.º 21
0
# response.static_version = '0.0.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, 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=True, signature=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')
Ejemplo n.º 22
0
## (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 gluon.tools import Auth, Crud, Service, PluginManager, prettydate
auth = Auth(db)
crud, service, plugins = Crud(db), Service(), PluginManager()

## add field for user.active
auth.settings.extra_fields['auth_user'] = [
    Field('active', 'boolean', default=True)
]

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

## configure email
mail = auth.settings.mailer
mail.settings.server = 'smtp.gmail.com:587'
mail.settings.sender = '*****@*****.**'
mail.settings.login = '******'
Ejemplo n.º 23
0
# 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 gluon.tools import Auth, Crud, Service, PluginManager, prettydate

auth = Auth(db, hmac_key=Auth.get_or_create_key())
crud, service, plugins = Crud(db), Service(), PluginManager()
username = True

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

## 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
Ejemplo n.º 24
0
    Field('userid', 'string', required=True, unique=True),
    Field('email', 'string', requires=IS_EMAIL()),
    Field('faculty_privileges', 'integer', requires=IS_INT_IN_RANGE(0, 1)),
    Field('password', 'string', required=True),
    Field('request_time', 'integer', requires=IS_INT_IN_RANGE(0, 1)),
    Field('approval_status', 'integer'))

db.define_table(
    'clone_requests', Field('id', 'integer'),
    Field('user', 'string', required=True),
    Field('vm_id', 'string', required=True), Field('clone_name', 'string'),
    Field('full_clone', 'integer', requires=IS_INT_IN_RANGE(0, 1)),
    Field('request_time', 'integer', requires=IS_INT_IN_RANGE(0, 1)),
    Field('status', 'integer'))

auth = Auth(db)
auth.define_tables(username=True)
auth.settings.login_methods.append(
    ldap_auth(mode='custom',
              username_attrib='uid',
              custom_scope='subtree',
              server=ldap_host,
              base_dn=ldap_dn))
auth.settings.create_user_groups = False
auth.settings.login_onaccept = [login_callback]

#auth.settings.login_url = '/baadal/user/login.html'
auth.settings.remember_me_form = False
auth.settings.logout_next = '/baadal/default/user/login'
auth.settings.login_next = '/baadal/user/index'
#auth.settings.on_failed_authorization = '/baadal/default/404.html'
Ejemplo n.º 25
0
    ## store sessions and tickets there
    session.connect(request, response, db=db)
    ## or store session in Memcache, Redis, etc.
    ## from gluon.contrib.memdb import MEMDB
    ## from google.appengine.api.memcache import Client
    ## session.connect(request, response, db = MEMDB(Client()))

## 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 []
## choose a style for forms
response.formstyle = myconf.take('forms.formstyle')  # or 'bootstrap3_stacked' or 'bootstrap2' or other
response.form_label_separator = myconf.take('forms.separator')

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(username=True)
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 = True

## after defining tables, uncomment below to enable auditing
auth.enable_record_versioning(db)

# Active Directory Authentication
Ejemplo n.º 26
0
db = DAL(settings.database_uri,
         pool_size=10,
         check_reserved=['all'],
         migrate_enabled=settings.migrate,
         decode_credentials=True)

response.generic_patterns = ['*']

from gluon.tools import Auth, Mail
auth = Auth(db, hmac_key=settings.security_key)
auth.define_tables(username=True, migrate=settings.migrate, signature=True)

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)

## Google Api Key
GOOGLE_API_KEY = "AIzaSyBFA3zO-fDW6iVg11fMqf6MANE4AwB1xRU"
GCM_SEND_HOST = "android.googleapis.com"
GCM_SEND_URL = "/gcm/send"
Ejemplo n.º 27
0
# coding: utf-8

# auth
# mailer
# crypto

from gluon.tools import Auth, Mail, Service

# class MyServiceHandler(Service):
#     def windows_wpf(self, *args, **kwargs):
#         pass

service = Service()

auth = Auth(db, hmac_key=Auth.get_or_create_key(), controller="home")

mail = Mail()
mail.settings.server = "logging"
mail.settings.sender = "*****@*****.**"
mail.settings.login = "******"

auth.settings.mailer = mail
auth.settings.formstyle = "divs"
auth.settings.extra_fields['auth_user'] = [
    Field("cliente_especial", "boolean", default=False),
    Field("bloqueado", "boolean", default=False)
]

# auth.settings.login_next = URL()

auth.define_tables()
Ejemplo n.º 28
0
## 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 []

#########################################################################
## 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, hmac_key=Auth.get_or_create_key())
crud, service, plugins = Crud(db), Service(), PluginManager()

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

## 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
Ejemplo n.º 29
0
 def setUp(self):
     global request, session, auth
     request = Request(globals())  # Use a clean Request object
     session = Session()
     auth = Auth(db, hmac_key=Auth.get_or_create_key())
     execfile("applications/runestone/controllers/ajax.py", globals())
Ejemplo n.º 30
0
Archivo: db.py Proyecto: chugle/hw2
db = DAL("sqlite://storage.sqlite")

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

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

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.author.requires = IS_NOT_EMPTY()
db.comment.email.requires = IS_EMAIL()
db.comment.body.requires = IS_NOT_EMPTY()

db.comment.image_id.writable = db.comment.image_id.readable = False

from gluon.tools import Auth
auth = Auth(db)
auth.define_tables()
Ejemplo n.º 31
0
# (optional) static assets folder versioning
# -------------------------------------------------------------------------
# response.static_version = '0.0.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)
# -------------------------------------------------------------------------

# host names must be a list of allowed host names (glob syntax allowed)
auth = Auth(db, host_names=configuration.get('host.names'))

# -------------------------------------------------------------------------
# create all tables needed by auth, maybe add a list of extra fields
# -------------------------------------------------------------------------
auth.settings.extra_fields['auth_user'] = []
auth.define_tables(username=False, signature=False)

# -------------------------------------------------------------------------
# configure email
# -------------------------------------------------------------------------
mail = auth.settings.mailer
mail.settings.server = 'logging' if request.is_local else configuration.get(
    'smtp.server')
mail.settings.sender = configuration.get('smtp.sender')
mail.settings.login = configuration.get('smtp.login')
Ejemplo n.º 32
0
db = DAL('sqlite://storage.sqlite')
from gluon.tools import Auth

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

#db.auth_user.password.requires=IS_STRONG()
#fr#om gluon.tools import Recaptcha
#auth.settings.captcha = Recaptcha(request,
#   '6LcD0PESAAAAAAv8xXDZS_g39KeqDKVhdpw5Ui3B',
#  '6LcD0PESAAAAACBYOTT1juQXfClchb_QP8BuXCOZ')

db.define_table('Restaurants',
                Field('name', 'string', required=True, requires=IS_LOWER()),
                Field('area', required=True, requires=IS_LOWER()),
                Field('city', required=True, requires=IS_LOWER()),
                Field('address', 'string', requires=IS_NOT_EMPTY()),
                Field('cuisine', 'string', requires=IS_NOT_EMPTY()),
                Field('comments'), Field('images', 'upload'))

db.Restaurants.name.requires = IS_NOT_EMPTY()
db.Restaurants.area.requires = IS_NOT_EMPTY()
db.Restaurants.city.requires = IS_NOT_EMPTY()

db.define_table('Comments', Field('comment', 'string',
                                  requires=IS_NOT_EMPTY()),
                Field('user', 'string', readable=False, writable=False),
                Field('rid', 'integer', readable=False, writable=False),
                Field('table_name', 'string', readable=False, writable=False))

db.define_table('Images', Field('image', 'upload', requires=IS_NOT_EMPTY()),
Ejemplo n.º 33
0
if 0:

    from gluon.html import *
    from gluon.validators import *
    from gluon.http import redirect, HTTP
    from gluon.sqlhtml import SQLFORM, SQLTABLE
    from gluon.compileapp import LOAD

    from gluon.globals import Request, Response, Session, current
    from gluon.cache import Cache
    from gluon.languages import translator
    from gluon.tools import Auth, Crud, Mail, Service, PluginManager
    from gluon.dal import DAL, Field
    from chimitheque_multiple_widget import CHIMITHEQUE_MULTIPLE_widget

    # API objects
    request = Request()
    response = Response()
    session = Session()
    cache = Cache(request)
    T = translator(request, 'fr')

    # Objects commonly defined in application model files
    # (names are conventions only -- not part of API)
    db = DAL()
    auth = Auth(db)
    crud = Crud(db)
    mail = Mail()
    service = Service()
    plugins = PluginManager()
    settings = {}
Ejemplo n.º 34
0
#db.dependencia.id.format = "%(nombre)s"
#db.dependencia.id.represent= lambda id, row: db.dependencia[id].nombre

db.define_table('departamento',
    Field('departamento', 'string', length=100, required= True, notnull=True),
    Field('dependencia', 'reference dependencia'),
    format = "%(departamento)s",
    singular = "Departamento",
    plural = "Departamentos",    
)
#db.departamento.dependencia.requires = IS_IN_DB(db, 'dependencia.id', '%(nombre)s', 
 #                                              zero='--Seleccione una dependencia--', error_message='Valor no Permitido')


from gluon.tools import Auth, Crud, Service, PluginManager, prettydate
auth = Auth(db)
auth.settings.cas_domains.append('http://190.169.221.43:8080')
crud, service, plugins = Crud(db), Service(), PluginManager()

## create all tables needed by auth if not custom tables
# after
# auth = Auth(globals(),db)
#db.define_table(
#    auth.settings.table_user_name,
#    Field('first_name', length=128, label = 'nombre'),
#    Field('last_name', length=128, label = 'apellido'),
#    Field('email', length=128, unique=True),
#    Field('password', 'password', length=512, readable=False, label='Password'),
#    Field('registration_key', length=512, writable=False, readable=False, default=''),
#    Field('reset_password_key', length=512, writable=False, readable=False, default=''),
#    Field('registration_id', length=512, writable=False, readable=False, default=''),
Ejemplo n.º 35
0
## (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 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(username=True, signature=False)

response.generic_patterns = ['*'] if request.is_local else []
response.generic_patterns = ['load']
## configure email
mail = auth.settings.mailer
mail.settings.server = 'logging' or 'mail.darwish-group.com:143'
mail.settings.sender = '*****@*****.**'
mail.settings.login = '******'

## configure auth policy
auth.settings.registration_requires_verification = False
Ejemplo n.º 36
0
 def define_table(self):
     fakeauth = Auth(DAL(None))
     self.fields.extend([fakeauth.signature])
     self.entity = self.db.define_table(
         self.tablename, *self.fields,
         **dict(migrate=self.migrate, format=self.format))
Ejemplo n.º 37
0
# response.static_version = '0.0.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

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

# -------------------------------------------------------------------------
# Turn of record change detection globally to allow saving a form multiple times
crud.settings.detect_record_change = False
crud.settings.label_separator = ' '
crud.settings.update_deletable = False
crud.settings.auth = auth
crud.messages.record_created = T('Saved')
crud.messages.record_updated = T('Saved')
crud.messages.submit_button = T('Save')
# -------------------------------------------------------------------------
Ejemplo n.º 38
0
# response.static_version = '0.0.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, 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)

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(
Ejemplo n.º 39
0
#config.db.uri = "sqlite://hosts.sqlite"
config.db.pool_size = 10
config.db.check_reserved = ['all']


db = DAL(**config.db)

# logging
import logging
logger = logging.getLogger("web2py.app.blog")
logger.setLevel(logging.DEBUG)

#auth Rbac
from gluon.tools import Auth

auth = Auth(db, controller="initial", function="user")

#settings
auth.settings.remember_me_form = False
auth.settings.formstyle = "divs"
auth.settings.login_next = URL('initial', 'principal')
auth.settings.logout_next = URL('user', 'login?_next=')
auth.settings.registration_requires_verification = False
auth.settings.registration_requires_approval = False
#auth.settings.actions_disabled = ['register']
auth.messages.logged_in = 'Bem Vindo' 
auth.messages.logged_out = 'Até logo'
auth.messages.access_denied = 'Acesso negado! Contate o administrador'
auth.messages.invalid_email = 'email Inválido'
auth.messages.invalid_login = '******'
Ejemplo n.º 40
0
# -------------------------------------------------------------------------
# response.static_version = '0.0.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)
# -------------------------------------------------------------------------

# host names must be a list of allowed host names (glob syntax allowed)
auth = Auth(db,
            hmac_key=Auth.get_or_create_key(),
            controller="default",
            function="user")
auth.settings.login_next = URL('index')

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

# -------------------------------------------------------------------------
# configure email
# -------------------------------------------------------------------------

# -------------------------------------------------------------------------
# configure auth policy
# -------------------------------------------------------------------------
Ejemplo n.º 41
0
## (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 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
Ejemplo n.º 42
0
if False:
    from gluon import *
    from db import *
    from menu import *
    from tables import *
    from gluon.contrib.appconfig import AppConfig
    from gluon.tools import Auth, Service, PluginManager
    request = current.request
    response = current.response
    session = current.session
    cache = current.cache
    T = current.T
    db = DAL('sqlite://storage.sqlite')
    myconf = AppConfig(reload=True)
    auth = Auth(db)
    service = Service()
    plugins = PluginManager()
    from agiscore.gui.mic import MenuLateral, MenuMigas
    menu_lateral = MenuLateral(list())
    menu_migas = MenuMigas()

from gluon.storage import Storage
from agiscore.gui.mic import Accion, grid_simple

# TODO: remove
response.menu = []

menu_lateral.append(Accion(T('Tipos de pagos'),
                           URL('index'),
                           True),
Ejemplo n.º 43
0
                Field('is_atende', required=True, requires=IS_IN_SET(['sim', 'não']), widget=SQLFORM.widgets.radio.widget, label='Atende chamados?'), singular='Clientes', format='%(nome_fantasia)s')

# TABLE setor - crud - OK
db.define_table('setor',
                Field('nome', type='string', length=60, required=True, requires=[IS_NOT_EMPTY('Campo obrigatório!'), IS_LENGTH(60, error_message='Informe no maxímo 60 caracteres!')], notnull=True, label='Nome'),
                Field('cliente_id', 'reference cliente', label='Cliente'), singular='Setores', format='%(nome)s')

# 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'),
Ejemplo n.º 44
0
# -*- coding: utf-8 -*-

db = DAL('sqlite://storage.sqlite',
         migrate_enabled=False)  # if not, use SQLite or other DB

# 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 []

T.set_current_languages('ro', 'ro-ro')
T.force(session.lang)

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 = 'smtp.gmail.com:587'  # your SMTP server
mail.settings.sender = '*****@*****.**'  # your email
mail.settings.login = '******'  # your credentials or None

auth.settings.hmac_key = 'sha512:e68b4107-4595-4284-9cd1-ef04a2ed3205'  # 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 = 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
Ejemplo n.º 45
0
# (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 gluon.tools import Auth, Crud, Service, PluginManager
auth = Auth(db)
(crud, service, plugins) = (Crud(db), Service(), PluginManager())


# 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 = True
auth.settings.reset_password_requires_verification = True
Ejemplo n.º 46
0
## (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 gluon.tools import Auth, Crud, Service, PluginManager, prettydate
auth = Auth(db, hmac_key=Auth.get_or_create_key())
crud, service, plugins = Crud(db), Service(), PluginManager()

if settings.enable_captchas:
    ## Enable captcha's :-(
    from gluon.tools import Recaptcha
    auth.settings.captcha = Recaptcha(request,
        '6Lfb_t4SAAAAAB9pG_o1CwrMB40YPsdBsD8GsvlD',
        '6Lfb_t4SAAAAAGvAHwmkahQ6s44478AL5Cf-fI-x',
        options="theme:'blackglass'")

auth.settings.login_captcha = False
auth.settings.retrieve_password_captcha	= False
#auth.settings.retrieve_username_captcha	= False

Ejemplo n.º 47
0
 def __init__(self, db, controller, function):
     self.db = db
     Auth.__init__(self, db=db, controller=controller, function=function)
Ejemplo n.º 48
0
# response.optimize_js = 'concat,minify,inline'
## (optional) static assets folder versioning
# response.static_version = '0.0.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, 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
Ejemplo n.º 49
0
## (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 gluon.tools import Auth, Crud, Service, PluginManager, prettydate
auth = Auth(db, hmac_key=Auth.get_or_create_key())
crud, service, plugins = Crud(db), Service(), PluginManager()

## create all tables needed by auth if not custom tables

########################################
db.define_table('auth_user',
    Field('username', type='string',
          label=T('Username')),
    Field('first_name', type='string',
          label=T('First Name')),
    Field('last_name', type='string',
          label=T('Last Name')),
    Field('email', type='string',
          label=T('Email')),
    Field('password', type='password',
Ejemplo n.º 50
0
# -*- coding: utf-8 -*-
import os
import yaml

if False:
    from gluon import *
    #TODO:si se importan los modulos aqui dentro, todo va..¿cambiarlo en todos?
    from applications.init.modules import db_pages, db_pagepermissions, \
                                    db_pagemodules, db_basemodules, \
                                    db_eventlog, db_packages, db_pynuke
    from gluon.tools import *
    from gluon.tools import Auth
    db = DAL()
    auth = Auth(db)
    request, session, response, T, cache = current.request, current.session,\
                                current.response, current.t, current.cache
    db = current.db
    settings = current.settings
    auth = Auth(db, hmac_key=Auth.get_or_create_key())
    crud, service, plugins = Crud(db), Service(), PluginManager()

clPagNav = db_pages.Pages.Navigation()
clEventLog = db_eventlog.EventLog()
clBaseModules = db_basemodules.BaseModules()
clPack = db_packages.Packages()
clPynuke_nav = db_pynuke.PyNuke.Navigation()

strings_to_remove_from_url = settings.strings_to_remove_from_url


def user():
Ejemplo n.º 51
0
# response.optimize_css = 'concat,minify,inline'
# response.optimize_js = 'concat,minify,inline'
## (optional) static assets folder versioning
# response.static_version = '0.0.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(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
Ejemplo n.º 52
0
# (optional) static assets folder versioning
# -------------------------------------------------------------------------
# response.static_version = '0.0.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)
# -------------------------------------------------------------------------

# host names must be a list of allowed host names (glob syntax allowed)
auth = Auth(db, host_names=configuration.get('host.names'))

# -------------------------------------------------------------------------
# create all tables needed by auth, maybe add a list of extra fields
# -------------------------------------------------------------------------
auth.settings.extra_fields['auth_user'] = []
auth.define_tables(username=False, signature=False)

# -------------------------------------------------------------------------
# configure email
# -------------------------------------------------------------------------
mail = auth.settings.mailer
mail.settings.server = 'logging' if request.is_local else configuration.get(
    'smtp.server')
mail.settings.sender = configuration.get('smtp.sender')
mail.settings.login = configuration.get('smtp.login')
Ejemplo n.º 53
0
plugins = PluginManager()       # for configuring plugins
current.db = db                 # to access db from modules

#-------------------------------------------------------------
# get private data from secure file
#-------------------------------------------------------------
keydata = {}
with open('applications/paideia/private/app.keys', 'r') as keyfile:
    for line in keyfile:
        k, v = line.split()
        keydata[k] = v

#-------------------------------------------------------------
#configure authorization
#-------------------------------------------------------------
auth = Auth(db, hmac_key=Auth.get_or_create_key())  # authent/authorization

#-------------------------------------------------------------
# place auth in current so it can be imported by modules
#-------------------------------------------------------------

current.auth = auth

#-------------------------------------------------------------
#misc auth settings
#-------------------------------------------------------------
auth.settings.create_user_groups = False
auth.settings.label_separator = ''

#-------------------------------------------------------------
# Customizing auth tables
Ejemplo n.º 54
0
## (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 gluon.tools import Auth, Crud, Service, PluginManager, prettydate
auth = Auth(db, hmac_key=Auth.get_or_create_key())
crud, service, plugins = Crud(db), Service(), PluginManager()


from plugin_ckeditor import CKEditor
ckeditor = CKEditor(db)
#ckeditor.define_tables()

# a table for Country
db.define_table('country',
    Field('name','string', required=True),
    Field('iso2','string',required=True),
    Field('iso3','string',required=True),
    Field('iso_id','integer', required=False),
    )
Ejemplo n.º 55
0
# response.optimize_js = 'concat,minify,inline'
## (optional) static assets folder versioning
# response.static_version = '0.0.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, 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 '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
Ejemplo n.º 56
0
# response.static_version = '0.0.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, Service, PluginManager

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

# -------------------------------------------------------------------------
# create all tables needed by auth if not custom tables
# -------------------------------------------------------------------------

##pra onde o user vai depois do login
auth.settings.login_next = URL("home","index")

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

# -------------------------------------------------------------------------
# configure email
# -------------------------------------------------------------------------
Ejemplo n.º 57
0
## (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 gluon.tools import Auth, Crud, Service, PluginManager, prettydate
auth = Auth(db, hmac_key=Auth.get_or_create_key())
crud, service, plugins = Crud(db), Service(), PluginManager()

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

## 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
Ejemplo n.º 58
0
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)
#########################################################################

auth = Auth(db, hmac_key=Auth.get_or_create_key())
crud, service, plugins = Crud(db), Service(), PluginManager()

# Make the settings and database available in modules.
current.db = db
current.settings = settings
current.auth = auth

if settings.enable_captchas:
    ## Enable captcha's :-(
    from gluon.tools import Recaptcha

    auth.settings.captcha = Recaptcha(
        request,
        "6Lfb_t4SAAAAAB9pG_o1CwrMB40YPsdBsD8GsvlD",
        "6Lfb_t4SAAAAAGvAHwmkahQ6s44478AL5Cf-fI-x",
Ejemplo n.º 59
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()
Ejemplo n.º 60
0
## (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 gluon.tools import Auth, Crud, Service, PluginManager, prettydate
auth = Auth(db, hmac_key=Auth.get_or_create_key())
crud, service, plugins = Crud(db), Service(), PluginManager()

if settings.enable_captchas:
    ## Enable captcha's :-(
    from gluon.tools import Recaptcha
    auth.settings.captcha = Recaptcha(
        request,
        '6Lfb_t4SAAAAAB9pG_o1CwrMB40YPsdBsD8GsvlD',
        '6Lfb_t4SAAAAAGvAHwmkahQ6s44478AL5Cf-fI-x',
        options="theme:'blackglass'")

auth.settings.login_captcha = False
auth.settings.retrieve_password_captcha = False
#auth.settings.retrieve_username_captcha	= False