예제 #1
0
    def __init__(self, environment, config_file=None, init_all=True):
        """Constructor.

        Args:
            environment: dict, dictionary defining environment as returned by
                    gluon/shell.py def env
            config_file: string, name of file used for configuration settings
                If None, this is set as per application. See _settings_loader()
                method.
        """
        self.environment = environment
        self.config_file = config_file
        self._server_mode = None

        self.local_settings = Settings()
        self.settings_loader = self._settings_loader()

        if init_all:
            # The order of these is intentional. Some depend on each other.
            self.DAL = self.environment['DAL']
            self.db = self._db()
            self.mail = self._mail()
            self.auth = self._auth()
            self.crud = self._crud()
            self.service = self._service()

        if self.settings_loader and 'response' in self.environment:
            self.settings_loader.import_settings(group='response',
                    storage=self.environment['response'])
예제 #2
0
 def __init__(self, api_key=None, sender=None):
     settings = self.settings = Settings()
     settings.api_key = api_key
     settings.sender = sender
     settings.track_opens = True
     settings.track_clicks = True
     settings.lock_keys = True
     self.result = {}
     self.error = None
예제 #3
0
    def __init__(self, db=None, hmac_key=None, signature=True):
        self.db = db
        session = current.session
        auth = session.auth
        self.user_groups = auth and auth.user_groups or {}
        now = current.request.now
        # if we have auth info
        #    if not expired it, used it
        #    if expired, clear the session
        # else, only clear auth info in the session
        if auth:
            delta = datetime.timedelta(days=0, seconds=auth.expiration)
            if auth.last_visit and auth.last_visit + delta > now:
                self.user = auth.user
                # this is a trick to speed up sessions to avoid many writes
                if (now - auth.last_visit).seconds > (auth.expiration // 10):
                    auth.last_visit = now
            else:
                self.user = None
                if session.auth:
                    del session.auth
                session.renew(clear_session=True)
        else:
            self.user = None
            if session.auth:
                del session.auth

        settings = self.settings = Settings(self.__class__.default_settings)
        settings.update(
            extra_fields={},
            hmac_key=hmac_key,
        )
        settings.lock_keys = True
        messages = self.messages = Messages(current.T)
        messages.update(self.default_messages)
        messages.lock_keys = True
        if signature is True:
            self.define_signature()
        else:
            self.signature = signature or None
예제 #4
0
파일: mail.py 프로젝트: x91111/web3py
    def __init__(self, server=None, sender=None, login=None, tls=True):

        settings = self.settings = Settings()
        settings.server = server
        settings.sender = sender
        settings.login = login
        settings.tls = tls
        settings.timeout = 60  # seconds
        settings.hostname = None
        settings.ssl = False
        settings.cipher_type = None
        settings.gpg_home = None
        settings.sign = True
        settings.sign_passphrase = None
        settings.encrypt = True
        settings.x509_sign_keyfile = None
        settings.x509_sign_certfile = None
        settings.x509_sign_chainfile = None
        settings.x509_nocerts = False
        settings.x509_crypt_certfiles = None
        settings.debug = False
        settings.lock_keys = True
        self.result = {}
        self.error = None
예제 #5
0
        --- Esta funcion retorna un diccinario con las
        --- conecciones a bases de datos'''

    dbs = {}
    for (key, value) in global_env.items():
        cond = isinstance(value, DAL)
        if cond:
            dbs[key] = value
    return dbs


databases = get_databases()
db = databases.values()[0]  # tomamos solo una base de datos por ahora.
tables = sorted(db.tables)
settings = Settings()


#-------- Configuracion de roles  ---------------

#Configuraciones por defecto --- settings -> dic()
settings.superuser_role = "plugin_admin_plus_superuser"
settings.reader_role    = "plugin_admin_plus_reader",
settings.editor_role    = "plugin_admin_plus_editor"
settings.creator_role   = "plugin_admin_plus_creator"
settings.deleter_role   = "plugin_admin_plus_deleter"


#se almacenan las configuraciones en un diccionario llamado roles
settings.roles = roles = {}
roles[settings.superuser_role] = T('Los superuser pueden, crear leer actualizar y eliminar registros en todas \
    dbs = {}
    for (key, value) in global_env.items():
        cond = False
        try:
            cond = isinstance(value, GQLDB)
        except:
            cond = isinstance(value, SQLDB)
        if cond:
            dbs[key] = value
    return dbs


databases = get_databases(None)
db = databases.values()[0]  # Take only one database for now.
tables = sorted(db.tables)
settings = Settings()

try:
    auth
except NameError:
    from gluon.tools import Auth
    auth = Auth(db)
    auth.define_tables()

auth_tables = [str(auth.settings.table_user),
               str(auth.settings.table_group),
               str(auth.settings.table_membership),
               str(auth.settings.table_permission),
               str(auth.settings.table_event),
               str(auth.settings.table_cas)
              ]
예제 #7
0
    def __init__(self, api):
        """
      auth=Auth(globals(), db)

      - environment is there for legacy but unused (awful)
      - db has to be the database where to create tables for authentication

      """
        controller = 'default'
        cas_provider = None

        self.db = None
        self.environment = current
        request = current.request
        session = current.session
        auth = session.auth
        if auth and auth.last_visit and auth.last_visit + \
                 datetime.timedelta(days=0, seconds=auth.expiration) > request.now:
            self.user = auth.user
            # this is a trick to speed up sessions
            if (request.now - auth.last_visit).seconds > (auth.expiration /
                                                          10):
                auth.last_visit = request.now
        else:
            self.user = None
            session.auth = None
        settings = self.settings = Settings()

        # ## what happens after login?

        # ## what happens after registration?

        settings.hideerror = False
        settings.cas_domains = [request.env.http_host]
        settings.cas_provider = cas_provider
        settings.extra_fields = {}
        settings.actions_disabled = []
        settings.reset_password_requires_verification = False
        settings.registration_requires_verification = False
        settings.registration_requires_approval = True
        settings.alternate_requires_registration = False
        settings.create_user_groups = False

        settings.controller = controller
        settings.login_url = self.url('user', args='login')
        settings.logged_url = self.url('user', args='profile')
        settings.download_url = self.url('download')
        settings.mailer = None
        settings.login_captcha = None
        settings.register_captcha = None
        settings.retrieve_username_captcha = None
        settings.retrieve_password_captcha = None
        settings.captcha = None
        settings.expiration = 3600  # one hour
        settings.long_expiration = 3600 * 30 * 24  # one month
        settings.remember_me_form = False
        settings.allow_basic_login = False
        settings.allow_basic_login_only = False
        settings.on_failed_authorization = \
           self.url('user',args='not_authorized')

        settings.on_failed_authentication = lambda x: redirect(x)

        settings.formstyle = 'table3cols'
        settings.label_separator = ': '

        # ## table names to be used

        settings.password_field = 'password'
        settings.table_user_name = 'auth_user'
        settings.table_group_name = 'auth_group'
        settings.table_membership_name = 'auth_membership'
        settings.table_permission_name = 'auth_permission'
        settings.table_event_name = 'auth_event'
        settings.table_cas_name = 'auth_cas'

        # ## if none, they will be created

        settings.table_user = None
        settings.table_group = None
        settings.table_membership = None
        settings.table_permission = None
        settings.table_event = None
        settings.table_cas = None

        # ##

        settings.showid = False

        # ## these should be functions or lambdas

        settings.login_next = self.url('index')
        settings.login_onvalidation = []
        settings.login_onaccept = []
        settings.login_methods = [self]
        settings.login_form = self
        settings.login_email_validate = True
        settings.login_userfield = "username"

        settings.logout_next = self.url('index')
        settings.logout_onlogout = lambda x: None

        settings.register_next = self.url('index')
        settings.register_onvalidation = []
        settings.register_onaccept = []
        settings.register_fields = None

        settings.verify_email_next = self.url('user', args='login')
        settings.verify_email_onaccept = []

        settings.profile_next = self.url('index')
        settings.profile_onvalidation = []
        settings.profile_onaccept = []
        settings.profile_fields = None
        settings.retrieve_username_next = self.url('index')
        settings.retrieve_password_next = self.url('index')
        settings.request_reset_password_next = self.url('user', args='login')
        settings.reset_password_next = self.url('user', args='login')

        settings.change_password_next = self.url('index')
        settings.change_password_onvalidation = []
        settings.change_password_onaccept = []

        settings.retrieve_password_onvalidation = []
        settings.reset_password_onvalidation = []

        settings.hmac_key = None
        settings.lock_keys = True

        # ## these are messages that can be customized
        messages = self.messages = Messages(current.T)
        messages.login_button = 'Login'
        messages.register_button = 'Register'
        messages.password_reset_button = 'Request reset password'
        messages.password_change_button = 'Change password'
        messages.profile_save_button = 'Save profile'
        messages.submit_button = 'Submit'
        messages.verify_password = '******'
        messages.delete_label = 'Check to delete:'
        messages.function_disabled = 'Function disabled'
        messages.access_denied = 'Insufficient privileges'
        messages.registration_verifying = 'Registration needs verification'
        messages.registration_pending = 'Registration is pending approval'
        messages.login_disabled = 'Login disabled by administrator'
        messages.logged_in = 'Logged in'
        messages.email_sent = 'Email sent'
        messages.unable_to_send_email = 'Unable to send email'
        messages.email_verified = 'Email verified'
        messages.logged_out = 'Logged out'
        messages.registration_successful = 'Registration successful'
        messages.invalid_email = 'Invalid email'
        messages.unable_send_email = 'Unable to send email'
        messages.invalid_login = '******'
        messages.invalid_user = '******'
        messages.invalid_password = '******'
        messages.is_empty = "Cannot be empty"
        messages.mismatched_password = "******"
        messages.verify_email = 'A user wishes to join Syndicate.\nDetails:\n   Username: %(username)s\n   Email: %(email)s'
        messages.verify_email_subject = 'Email verification'
        messages.username_sent = 'Your username was emailed to you'
        messages.new_password_sent = 'A new password was emailed to you'
        messages.password_changed = 'Password changed'
        messages.retrieve_username = '******'
        messages.retrieve_username_subject = 'Username retrieve'
        messages.retrieve_password = '******'
        messages.retrieve_password_subject = 'Password retrieve'
        messages.reset_password = \
           'Click on the link http://...reset_password/%(key)s to reset your password'
        messages.reset_password_subject = 'Password reset'
        messages.invalid_reset_password = '******'
        messages.profile_updated = 'Profile updated'
        messages.new_password = '******'
        messages.old_password = '******'
        messages.group_description = \
           'Group uniquely assigned to user %(id)s'

        messages.register_log = 'User %(id)s Registered'
        messages.login_log = 'User %(id)s Logged-in'
        messages.login_failed_log = None
        messages.logout_log = 'User %(id)s Logged-out'
        messages.profile_log = 'User %(id)s Profile updated'
        messages.verify_email_log = 'User %(id)s Verification email sent'
        messages.retrieve_username_log = 'User %(id)s Username retrieved'
        messages.retrieve_password_log = 'User %(id)s Password retrieved'
        messages.reset_password_log = 'User %(id)s Password reset'
        messages.change_password_log = 'User %(id)s Password changed'
        messages.add_group_log = 'Group %(group_id)s created'
        messages.del_group_log = 'Group %(group_id)s deleted'
        messages.add_membership_log = None
        messages.del_membership_log = None
        messages.has_membership_log = None
        messages.add_permission_log = None
        messages.del_permission_log = None
        messages.has_permission_log = None
        messages.impersonate_log = 'User %(id)s is impersonating %(other_id)s'

        messages.label_first_name = 'First name'
        messages.label_last_name = 'Last name'
        messages.label_username = '******'
        messages.label_email = 'E-mail'
        messages.label_password = '******'
        messages.label_registration_key = 'Registration key'
        messages.label_reset_password_key = 'Reset Password key'
        messages.label_registration_id = 'Registration identifier'
        messages.label_role = 'Role'
        messages.label_description = 'Description'
        messages.label_user_id = 'User ID'
        messages.label_group_id = 'Group ID'
        messages.label_name = 'Name'
        messages.label_table_name = 'Table name'
        messages.label_record_id = 'Record ID'
        messages.label_time_stamp = 'Timestamp'
        messages.label_client_ip = 'Client IP'
        messages.label_origin = 'Origin'
        messages.label_remember_me = "Remember me (for 30 days)"
        messages['T'] = current.T
        messages.verify_password_comment = 'please input your password again'
        messages.lock_keys = True

        self.user = None
        self.api = api
        self.maint_email = api.config.MD_MAIL_SUPPORT_ADDRESS

        # disable stuff for now
        settings.actions_disabled.append('retrieve_username')
        settings.actions_disabled.append('retrieve_password')
        settings.actions_disabled.append('request_reset_password')
        settings.actions_disabled.append('profile')
        settings.actions_disabled.append('change_password')