Ejemplo n.º 1
0
    def __init__(self, DALDatabase):
        self.DALDatabase = DALDatabase
        self.DALDatabase.define_table(
            'internal_messages',
            Field('senders',
                  'reference auth_user',
                  notnull=True,
                  requires=IS_IN_DB(self.DALDatabase,
                                    self.DALDatabase.auth_user)),
            Field('subject', 'string', requires=IS_NOT_EMPTY()),
            Field('text_message', 'string', requires=IS_NOT_EMPTY()),
            Field('message_sent', 'boolean', default=False),
            Field('send_on', 'datetime', requires=IS_EMPTY_OR(IS_DATETIME())),
            Field('written_on',
                  'datetime',
                  default=datetime.now(),
                  requires=IS_EMPTY_OR(IS_DATETIME())))

        self.DALDatabase.define_table(
            'internal_messages_recipients',
            Field('internal_messages',
                  'reference internal_messages',
                  notnull=True,
                  requires=IS_IN_DB(self.DALDatabase,
                                    self.DALDatabase.internal_messages)),
            Field('recipients',
                  'reference auth_user',
                  notnull=True,
                  requires=IS_IN_DB(self.DALDatabase,
                                    self.DALDatabase.auth_user)),
            Field('message_read', 'boolean', default=False),
        )
Ejemplo n.º 2
0
    def __init__(self,
                 projectConfig,
                 DALDatabase,
                 i18nTranslator=None,
                 logger_api=None):
        self.DALDatabase = DALDatabase
        self.logger_api = logger_api
        self.DALDatabase.define_table(
            'client', Field('token', 'text'),
            Field('auth_user',
                  'reference auth_user',
                  requires=IS_EMPTY_OR(
                      IS_IN_DB(self.DALDatabase, self.DALDatabase.auth_user))),
            Field('date_created',
                  'datetime',
                  default=datetime.now(),
                  requires=IS_EMPTY_OR(IS_DATETIME())),
            Field('last_resign', 'datetime', default=datetime.now()),
            Field('remember_me', 'boolean', default=False),
            Field('locked', 'boolean', default=False))

        self.DALDatabase.define_table(
            'captcha', Field('token', 'text'), Field('form_identify',
                                                     'string'),
            Field('user_agent', 'string'), Field('ip', 'string'),
            Field('date_created',
                  'datetime',
                  default=datetime.now(),
                  requires=IS_DATETIME()),
            Field('client',
                  'reference client',
                  requires=IS_EMPTY_OR(
                      IS_IN_DB(self.DALDatabase, self.DALDatabase.client))))

        self.DALDatabase.define_table(
            'google_captcha', Field('token', 'text'),
            Field('form_identify', 'string'), Field('user_agent', 'string'),
            Field('ip', 'string'),
            Field('date_created',
                  'datetime',
                  default=datetime.now(),
                  requires=IS_DATETIME()),
            Field('client',
                  'reference client',
                  requires=IS_EMPTY_OR(
                      IS_IN_DB(self.DALDatabase, self.DALDatabase.client))))

        self.DALDatabase.define_table(
            'csrf', Field('token', 'text'), Field('form_identify', 'string'),
            Field('user_agent', 'string'), Field('ip', 'string'),
            Field('date_created',
                  'datetime',
                  default=datetime.now(),
                  requires=IS_DATETIME()),
            Field('client',
                  'reference client',
                  requires=IS_EMPTY_OR(
                      IS_IN_DB(self.DALDatabase, self.DALDatabase.client))))
Ejemplo n.º 3
0
def multiple_form_example():
    name = Field('name', requires=IS_NOT_EMPTY())
    forms = [
        Form([Field('name', requires=IS_NOT_EMPTY())],
             form_name='1', formstyle=FormStyleBulma),
        Form([Field('name', requires=IS_NOT_EMPTY())],
             form_name='2', keep_values=True, formstyle=FormStyleBulma),
        Form([Field('name', requires=IS_NOT_EMPTY()),
              Field('age','integer')], 
             form_name='3', formstyle=FormStyleBulma),
        Form([Field('name', requires=IS_NOT_EMPTY()),
              Field('insane','boolean')], 
             form_name='4', formstyle=FormStyleBulma),
        Form([Field('name', requires=IS_NOT_EMPTY()),
              Field('color',requires=IS_IN_SET(['red','blue','gree']))], 
             form_name='5', formstyle=FormStyleBulma),
        Form([Field('name', requires=IS_NOT_EMPTY()),
              Field('favorite_thing', requires=IS_IN_DB(db, 'thing.id', 'thing.name'))], 
             form_name='6', formstyle=FormStyleBulma)]
    messages = []
    for form in forms:
        if form.accepted:
            messages.append('form %s accepted with: %s ' % (form.form_name, form.vars))
        elif form.errors:
            messages.append('form %s has errors: %s ' % (form.form_name, form.errors))
    return dict(forms=forms, messages=messages)
Ejemplo n.º 4
0
def example_multiple_forms():
    name = Field("name", requires=IS_NOT_EMPTY())
    forms = [
        Form(
            [Field("name", requires=IS_NOT_EMPTY())],
            form_name="1",
            formstyle=FormStyleDefault,
        ),
        Form(
            [Field("name", requires=IS_NOT_EMPTY())],
            form_name="2",
            keep_values=True,
            formstyle=FormStyleDefault,
        ),
        Form(
            [Field("name", requires=IS_NOT_EMPTY()),
             Field("age", "integer")],
            form_name="3",
            formstyle=FormStyleDefault,
        ),
        Form(
            [
                Field("name", requires=IS_NOT_EMPTY()),
                Field("insane", "boolean")
            ],
            form_name="4",
            formstyle=FormStyleDefault,
        ),
        Form(
            [
                Field("name", requires=IS_NOT_EMPTY()),
                Field("color", requires=IS_IN_SET(["red", "blue", "green"])),
            ],
            form_name="5",
            formstyle=FormStyleDefault,
        ),
        Form(
            [
                Field("name", requires=IS_NOT_EMPTY()),
                Field("favorite_hero",
                      requires=IS_IN_DB(db, "person.id", "person.name")),
            ],
            form_name="6",
            formstyle=FormStyleDefault,
        ),
    ]
    messages = []
    for form in forms:
        if form.accepted:
            messages.append("form %s accepted with: %s " %
                            (form.form_name, form.vars))
        elif form.errors:
            messages.append("form %s has errors: %s " %
                            (form.form_name, form.errors))
    return dict(forms=forms, messages=messages)
Ejemplo n.º 5
0
 def __init__(self, projectConfig, DALDatabase):
     self.DALDatabase = DALDatabase
     self.DALDatabase.define_table(
         'auth_cas', Field('email', 'string', notnull=True, unique=True),
         Field('password_hash',
               'string',
               notnull=True,
               requires=IS_NOT_EMPTY()))
     self.DALDatabase.auth_cas.email.requires = [
         IS_EMAIL(),
         IS_NOT_IN_DB(self.DALDatabase,
                      self.DALDatabase.auth_cas.email,
                      error_message="Email already in database.")
     ]
     self.DALDatabase.define_table(
         'cas_activity',
         Field('auth_cas',
               'reference auth_cas',
               requires=IS_IN_DB(self.DALDatabase,
                                 self.DALDatabase.auth_cas)),
         Field('request', 'text'), Field('activity', 'string'),
         Field('date_activity', 'datetime', default=datetime.now()))
     self.DALDatabase.define_table(
         'apps_authorization', Field('app_name', 'string'),
         Field('auth_cas',
               'reference auth_cas',
               requires=IS_IN_DB(self.DALDatabase,
                                 self.DALDatabase.auth_cas)),
         Field('origin', 'string'),
         Field('authorization', 'text', requires=IS_NOT_EMPTY()))
     self.DALDatabase.apps_authorization.app_name.requires = [
         IS_NOT_EMPTY(),
         IS_NOT_IN_DB(self.DALDatabase,
                      self.DALDatabase.apps_authorization.app_name,
                      error_message="Email already in database.")
     ]
Ejemplo n.º 6
0
    def __init__(self, db):
        self.db = db
        self.db.define_table('phanterpwagallery', Field('folder'),
                             Field('filename'), Field('alias_name'),
                             Field('content_type'))

        self.db.define_table(
            'auth_user_phanterpwagallery',
            Field('phanterpwagallery', 'reference phanterpwagallery'),
            Field('auth_user',
                  'reference auth_user',
                  requires=IS_EMPTY_OR(IS_IN_DB(self.db, self.db.auth_user))),
            Field('subfolder'),
            Field('last_update',
                  'datetime',
                  default=datetime.now(),
                  requires=IS_EMPTY_OR(IS_DATETIME())))
Ejemplo n.º 7
0
    def __init__(self,
                 projectConfig,
                 DALDatabase,
                 i18nTranslator=None,
                 logger_api=None):
        self.DALDatabase = DALDatabase
        default_language = projectConfig["PROJECT"].get(
            "default_language", "en-US")
        self.logger_api = logger_api
        self.DALDatabase.define_table(
            'auth_user',
            Field('first_name',
                  'string',
                  notnull=True,
                  requires=IS_NOT_EMPTY(),
                  phanterpwa={
                      'group': 'group1',
                      '_class': 'p-col w1p100 w4p70 e-float_right'
                  }),
            Field('last_name',
                  'string',
                  notnull=True,
                  requires=IS_NOT_EMPTY(),
                  phanterpwa={
                      'group': 'group1',
                      '_class': 'p-col w1p100 w4p70 e-float_right'
                  }),
            Field('email',
                  'string',
                  notnull=True,
                  unique=True,
                  phanterpwa={
                      'group': 'group1',
                      '_class': 'p-col w1p100 w4p70 e-float_right'
                  }),
            Field('email_activated', 'boolean', default=False),
            Field('fone_number', 'string', phanterpwa={'out_of_form': True}),
            Field('fone_number_activated', 'boolean', default=False),
            Field('password_hash',
                  'string',
                  notnull=True,
                  requires=IS_NOT_EMPTY(),
                  phanterpwa={'out_of_form': True}),
            Field('login_attempts', 'integer', default=0),
            Field(
                'datetime_next_attempt_to_login',
                'datetime',
                requires=IS_EMPTY_OR(IS_DATETIME()),
                phanterpwa={
                    'validators':
                    ['IS_EMPTY_OR', 'IS_DATETIME:yyyy-MM-dd HH:mm:ss'],
                    # '_class': 'p-col w1p100 w4p40',
                    # 'section': 'Identidade'
                }),
            Field('temporary_password',
                  'text',
                  phanterpwa={'out_of_form': True}),  # it's used in the debug
            Field('temporary_password_hash',
                  'text',
                  phanterpwa={'out_of_form': True}),

            # datetime_next_attempt_to_login
            Field('temporary_password_expire',
                  'datetime',
                  requires=IS_EMPTY_OR(IS_DATETIME()),
                  phanterpwa={
                      'validators':
                      ['IS_EMPTY_OR', 'IS_DATETIME:yyyy-MM-dd HH:mm:ss']
                  }),
            Field('timeout_to_resend_temporary_password_mail',
                  'datetime',
                  requires=IS_EMPTY_OR(IS_DATETIME()),
                  phanterpwa={
                      'validators':
                      ['IS_EMPTY_OR', 'IS_DATETIME:yyyy-MM-dd HH:mm:ss']
                  }),
            Field('activation_code_by_mobile', 'string', default=0),
            Field('activation_code', 'string', default=0),
            Field('activation_attempts', 'integer', default=0),
            Field('timeout_to_resend_activation_email',
                  'datetime',
                  requires=IS_EMPTY_OR(IS_DATETIME()),
                  phanterpwa={
                      'validators':
                      ['IS_EMPTY_OR', 'IS_DATETIME:yyyy-MM-dd HH:mm:ss']
                  }),

            # wait_time_to_try_activate_again
            Field('datetime_next_attempt_to_activate',
                  'datetime',
                  requires=IS_EMPTY_OR(IS_DATETIME()),
                  phanterpwa={
                      'validators':
                      ['IS_EMPTY_OR', 'IS_DATETIME:yyyy-MM-dd HH:mm:ss']
                  }),
            Field('permit_mult_login', 'boolean', default=True),
            Field('activated', 'boolean', default=False, notnull=True),
            Field('websocket_opened',
                  'boolean',
                  default=False,
                  notnull=True,
                  phanterpwa={'out_of_form': True}),
            Field('locale', 'string', default=default_language),
            Field('two_factor_login', 'boolean', default=False))

        def delete_upload_folder(s):
            upload_folder = os.path.join(projectConfig["PROJECT"]["path"],
                                         "backapps", "api", "uploads")
            target = os.path.join(upload_folder,
                                  "user_{0}".format(s.select().first().id))
            if os.path.exists(target) and os.path.isdir(target):
                try:
                    shutil.rmtree(target)
                except Exception:
                    if self.logger_api:
                        self.logger_api.error(
                            "Problem on delete folder: \"{0}\"".format(target),
                            exc_info=True)
            else:
                if self.logger_api:
                    self.logger_api.warning(
                        "Ther folder \"{0}\" not exists".format(target))

        self.DALDatabase.auth_user._before_delete.append(
            lambda s: delete_upload_folder(s))

        self.DALDatabase.auth_user.email.requires = [
            IS_EMAIL(),
            IS_NOT_IN_DB(self.DALDatabase,
                         self.DALDatabase.auth_user.email,
                         error_message="Email already in database.")
        ]
        self.DALDatabase.auth_user.fone_number.requires = [
            IS_EMPTY_OR(
                IS_NOT_IN_DB(
                    self.DALDatabase,
                    self.DALDatabase.auth_user.fone_number,
                    error_message="Mobile number already in database."))
        ]
        self.DALDatabase.define_table('auth_group', Field('role', 'string'),
                                      Field('grade', 'integer', default=0),
                                      Field('description', 'text'))

        self.DALDatabase.define_table(
            'auth_membership',
            Field('auth_user',
                  'reference auth_user',
                  requires=IS_IN_DB(self.DALDatabase,
                                    self.DALDatabase.auth_user)),
            Field('auth_group',
                  'reference auth_group',
                  requires=IS_IN_DB(self.DALDatabase,
                                    self.DALDatabase.auth_group)))

        self.DALDatabase.define_table(
            'auth_activity',
            Field('auth_user',
                  'reference auth_user',
                  requires=IS_IN_DB(self.DALDatabase,
                                    self.DALDatabase.auth_user)),
            Field('request', 'text'), Field('activity', 'string'),
            Field('date_activity', 'datetime', default=datetime.now()))

        self.DALDatabase.define_table(
            'email_user_list',
            Field('auth_user',
                  'reference auth_user',
                  requires=IS_IN_DB(self.DALDatabase,
                                    self.DALDatabase.auth_user)),
            Field('email', 'string', notnull=True),
            Field('datetime_changed', 'datetime', default=datetime.now()))

        self.DALDatabase.define_table(
            'social_auth', Field('social_name', 'string'),
            Field('request_state', 'text'), Field('client_token', 'text'),
            Field('datetime_created', 'datetime', default=datetime.now()),
            Field('origin', 'text'), Field('used', 'boolean', default=False),
            Field('user_credentials', 'text'))

        self.DALDatabase.define_table(
            'two_factor_login',
            Field('auth_user',
                  'reference auth_user',
                  requires=IS_IN_DB(self.DALDatabase,
                                    self.DALDatabase.auth_user)),
            Field('two_factor_url', 'text'), Field('two_factor_code'),
            Field('datetime_changed', 'datetime', default=datetime.now()))

        self.DALDatabase.email_user_list.email.requires = [IS_EMAIL()]

        if self.DALDatabase(self.DALDatabase.auth_group).isempty():
            self.DALDatabase.auth_group.insert(
                role="root",
                grade=100,
                description="Administrator of application (Developer)")
            self.DALDatabase.auth_group.insert(
                role="administrator",
                grade=10,
                description="Super user of site")
            self.DALDatabase.auth_group.insert(role="user",
                                               grade=1,
                                               description="Default user")
            self.DALDatabase.commit()

        if self.DALDatabase(self.DALDatabase.auth_membership).isempty():
            if self.DALDatabase.auth_user[1]:
                id_role = self.DALDatabase(self.DALDatabase.auth_group.role ==
                                           'root').select().first()
                if id_role:
                    self.DALDatabase.auth_membership.insert(
                        auth_user=1, auth_group=id_role.id)
                    self.DALDatabase.commit()