コード例 #1
0
ファイル: testdb.py プロジェクト: withanage/bancal
def crea_usuario():
    from gluon.validators import CRYPT
    from gluon.tools import Auth
    db = current.db
    auth = Auth(db)

    db.Sede.insert(name="Sede de pruebas")
    id_almacen = db.Almacen.insert(name="AlmacenTest 1")
    db.Almacen.insert(name="AlmacenTest 2")
    db.Estanteria.insert(name="Estanteria Test", almacen=id_almacen)

    my_crypt = CRYPT(key=auth.settings.hmac_key)
    crypted_passwd = my_crypt('password_malo')[0]
    db.commit()
    db.auth_user.insert(email='*****@*****.**',
                        first_name='Administrator',
                        password=crypted_passwd)
    auth.add_group('admins', 'Administradores de la aplicación')
    auth.add_membership(1, 1)
    auth.add_permission(1, 'admins', db.auth_user)

    db.Beneficiario.insert(name="Beneficiario 1",
                           tipobeneficiario="ASOCIACIONES")
    db.Colaborador.insert(name="Donante 1", Donante=True)
    db.commit()
コード例 #2
0
def update_values(fields, id):
    cruzid = fields['email'].split('@')[0]
    auth = Auth(db, host_names=myconf.get('host.names'))

    ucsc_users = db((db.ucsc_user.cruzid == cruzid)).select()

    professors = db((db.ucsc_faculty_member.cruzid == cruzid)).select()

    isProfessor = True if len(professors) > 0 else False

    if isProfessor:
        auth.add_membership('professor', user_id=id)
    else:
        auth.add_membership('student', user_id=id)

    if len(ucsc_users) > 0:
        ucsc_user = db((db.ucsc_user.cruzid == cruzid)).select()[0]
        first_name = ucsc_user.first_name + " " + ucsc_user.middle_name
        last_name = ucsc_user.last_name
        db(db.auth_user.id == id).update(first_name=first_name,
                                         last_name=last_name)

    else:
        print "USER NOT FOUND IN UCSC USERS DB"
    return
コード例 #3
0
ファイル: testdb.py プロジェクト: QuicketSolutions/web2py
def create_users():
    from gluon.validators import CRYPT
    from gluon.tools import Auth
    db = current.db
    auth = Auth(db)

    my_crypt = CRYPT(key=auth.settings.hmac_key)
    crypted_passwd = my_crypt('password')[0]
    db.commit()
    db.auth_user.insert(email='*****@*****.**',
                        first_name='Administrator',
                        password=crypted_passwd)
    auth.add_group('admins', 'Application Administrators')
    auth.add_membership(1, 1)
    auth.add_permission(1, 'admins', db.auth_user)

    db.commit()
コード例 #4
0
ファイル: db.py プロジェクト: withanage/bancal
        db.Sede.insert(name="Sede de pruebas")
        db.Almacen.insert(name="AlmacenTest")
        my_crypt = CRYPT(key=auth.settings.hmac_key)
        crypted_passwd = my_crypt('password_malo')[0]
        db.commit()
        # k = db.auth_user.insert(email='*****@*****.**', first_name='Administrator',
        #                         password=crypted_passwd, almacen=1)
        k = db.auth_user.insert(email='*****@*****.**', first_name='Administrator',
                                password=crypted_passwd)
        if str(k) != '1':
            db.executesql('update auth_user set id=1 where id=' + str(k))

        k = auth.add_group('admins', 'Administradores de la aplicación')
        if str(k) != '1':
            db.executesql('update auth_group set id=1 where id=' + str(k))
        auth.add_membership(1, 1)
        auth.add_permission(1, 'admins', db.auth_user)
        db.commit()

    # Temporal, para importar datos de bb.dd. anterior ###
    import importacion

    locs = db().select(db.poblacion.ALL, limitby=(0, 1))
    if not locs:
        # importacion.rellena_familias()
        # importacion.rellena_subfamilias()
        # importacion.rellena_alimentos()
        importacion.rellena_paises()
        importacion.rellena_provincias()
        importacion.rellena_localidades()
        # importacion.rellena_colaboradores()
コード例 #5
0
ファイル: db.py プロジェクト: aabv21/SisPIO
#     )


if not db(db.usuario.username == 'admin').select():
    id_usuario = db.usuario.insert(username='******', password=CRYPT()('admin')[0], first_name='SisPIO', last_name='Admin', email='*****@*****.**')

    estudiante = auth.add_group(role='Estudiante', description='description')
    profesor = auth.add_group(role='Profesor', description='description')
    representante_liceo = auth.add_group(role='Representante_liceo', description='description')
    representante_sede = auth.add_group(role='Representante_sede', description='description')
    admin = auth.add_group(role='Administrador', description='description')

    auth.add_permission(estudiante, 'Estudiante')

    auth.add_permission(profesor, 'Estudiante')
    auth.add_permission(profesor, 'Profesor')

    auth.add_permission(representante_liceo, 'Estudiante')
    auth.add_permission(representante_liceo, 'Representante_liceo')

    auth.add_permission(representante_sede, 'Estudiante')
    auth.add_permission(representante_sede, 'Representante_sede')

    auth.add_permission(admin, 'Estudiante')
    auth.add_permission(admin, 'Representante_liceo')
    auth.add_permission(admin, 'Profesor')
    auth.add_permission(admin, 'Representante_sede')
    auth.add_permission(admin, 'Administrador')

    auth.add_membership(admin, id_usuario)
コード例 #6
0
ファイル: cognito.py プロジェクト: chinapandaman/pandaCognito
class Cognito(object):
    def __init__(self):
        self.db = DAL(
            current.config.get("cognito_db.uri"),
            pool_size=current.config.get("cognito_db.pool_size"),
            migrate_enabled=current.config.get("cognito_db.migrate"),
            check_reserved=["all"],
        )

        self.auth = Auth(db=self.db,
                         host_names=current.config.get("host.names"))

        self.auth.settings.create_user_groups = None

        # TODO: extend this during implementation
        self.auth.settings.extra_fields["auth_user"] = [
            Field("user_attributes", type="json")
        ]

        self.auth.define_tables(username=True, signature=True)

    def add_user_to_group(self, username, group_name):
        user = self.db(self.db.auth_user.username == username).select()
        if not len(user):
            raise HTTP(400, "UserNotFoundException")

        group = self.db(self.db.auth_group.role == group_name).select()

        if len(group):
            self.auth.add_membership(group.first().id, user.first().id)

        return None

    def create_group(self, group_name, description):
        if len(self.db(self.db.auth_group.role == group_name).select()):
            raise HTTP(400, "GroupExistsException")

        result = self.auth.add_group(role=group_name, description=description)

        group = self.db(self.db.auth_group.id == result).select().first()

        return {
            "Group": {
                "GroupName": group["role"],
                "Description": group["description"],
                "LastModifiedDate": group["modified_on"],
                "CreationDate": group["created_on"],
            }
        }

    def delete_group(self, group_name):
        self.db(self.db.auth_group.role == group_name).delete()

        return None

    def sign_up(self, username, password, user_attributes):
        result = self.auth.register_bare(username=username, password=password)

        if not result:
            raise HTTP(400, "UsernameExistsException")

        result.update_record(user_attributes=user_attributes)

        return {
            "UserConfirmed":
            not self.auth.settings.registration_requires_verification,
            "UserSub": result.id,
        }
コード例 #7
0
response.optimize_js = 'concat,minify,inline'
response.static_version = '1.0.0'

from gluon.tools import Auth, Crud, Service, PluginManager, Mail, prettydate
auth = Auth(db)
auth.define_tables(username=False)
crud = Crud(db)

auth.settings.extra_fields['auth_user'] = ([
    Field('user_type', requires=IS_IN_SET(['admin', 'salesman', 'visitor']))
])

auth.settings.login_next = URL('index')
auth.settings.register_next = URL('user', args='login')
auth.settings.register_onaccept.append(lambda form: auth.add_membership(
    'visitor',
    db(db.auth_user.email == form.vars.email).select().first().id))
auth.settings.registration_requires_approval = True
auth.settings.create_user_groups = False

db.auth_user._format = '%(first_name)s %(last_name)s'

db.define_table('fields', Field('name'), format='%(name)s')
db.fields.name.requires = [IS_NOT_EMPTY(), IS_NOT_IN_DB(db, 'fields.name')]
db.fields.name.label = T('Element oferty')

db.define_table('firms',
                Field('name'),
                Field('address'),
                Field('city'),
                Field('zip'),
コード例 #8
0
                Field('id_inventario', db.inventario),
                Field('fecha_prestacion', 'datetime'),
                Field('fecha_devolucion', 'time'))

if (db(db.auth_group).isempty()):
    auth.add_group('admin', 'admin')
    auth.add_group('supervisor', 'supervisor')
    auth.add_group('user_basic', 'user_basic')

#Revisar esto
if not db().select(db.auth_user.ALL).first():
    id_user = db.auth_user.insert(
        username='******',
        password=db.auth_user.password.validate('admin')[0],
        email='*****@*****.**',
        first_name='admin',
        last_name='Administrator',
    )
    auth.del_membership(auth.id_group('user_basic'), id_user)
    auth.add_membership(auth.id_group('admin'), id_user)

    id_user = db.auth_user.insert(
        username='******',
        password=db.auth_user.password.validate('supervisor')[0],
        email='*****@*****.**',
        first_name='supervior',
        last_name='Supervisor',
    )
    auth.del_membership(auth.id_group('user_basic'), id_user)
    auth.add_membership(auth.id_group('supervisor'), id_user)
コード例 #9
0
ファイル: db.py プロジェクト: fengclient/bookit
g_user_id=auth.id_group('User') or auth.add_group('User','can view and borrow')
g_admin_id=auth.id_group('Admin') or auth.add_group('Admin','everything')

auth.add_permission(g_manager_id,'access to manage')
auth.add_permission(g_manager_id,'access to borrow')

auth.add_permission(g_user_id,'access to borrow')

auth.add_permission(g_admin_id,'access to manage')
auth.add_permission(g_admin_id,'access to borrow')
auth.add_permission(g_admin_id,'access to admin')

rows = db(auth.settings.table_user.email == '*****@*****.**').select()
if rows:
    user_admin_id=rows.first().id
    auth.add_membership(g_admin_id,user_admin_id)

## if you need to use OpenID, Facebook, MySpace, Twitter, Linkedin, etc.
## register with janrain.com, write your domain:api_key in private/janrain.key
from gluon.contrib.login_methods.rpx_account import use_janrain
use_janrain(auth,filename='private/janrain.key')

#########################################################################
## Define your tables below (or better in another model file) for example
##
## >>> db.define_table('mytable',Field('myfield','string'))
##
## Fields can be 'string','text','password','integer','double','boolean'
##       'date','time','datetime','blob','upload', 'reference TABLENAME'
## There is an implicit 'id integer autoincrement' field
## Consult manual for more options, validators, etc.
コード例 #10
0
ファイル: db.py プロジェクト: vampolo/milo-reloaded
auth.settings.extra_fields[auth.settings.table_user_name] = [
        Field('milo_user', db.users, requires = IS_IN_DB(db,'users.id',db.users._format),
            unique=True, notnull=False, writable=False, readable=False, default=lambda: db.users.insert(webuser=True))]


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

## privilege group
rsc_group = auth.add_group(role = 'rsc')
auth.settings.everybody_group_id = rsc_group
dis_group = auth.add_group(role = 'disabled')
destr_group = auth.add_group(role = 'destr')

## manual privilege management
auth.add_membership('rsc',9)
auth.add_membership('admin',9)


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

## configure auth policy
auth.settings.registration_requires_verification = True
auth.settings.registration_requires_approval = False
auth.settings.reset_password_requires_verification = True
コード例 #11
0
ファイル: 1_models_users.py プロジェクト: LoupX/fayol
auth.settings.expiration = 18000


try:
    if db(db.auth_group).isempty():
        god_group_id = auth.add_group('GOD', 'Administrador del sistema')
        auth.add_group('Administrador', 'Administrador local')
        auth.add_group('Gerente', 'Gerente de sucursal')
        auth.add_group('Vendedor de mostrador', 'Vendedor de mostrador'),
        auth.add_group('Almacenista', 'Encargado de almacen')
        auth.add_group('Cajero', '')
    else:
        god_group_id = db(db.auth_group.role=='GOD').select().first()
        god_group_id = god_group_id.id

    if db(db.auth_user).isempty():
        password = db.auth_user.password.validate('qazWSX11')[0]
        data = dict()
        data['first_name'] = 'Yisus'
        data['last_name'] = 'Craist'
        data['username'] = '******'
        data['password'] = password
        data['email'] = '*****@*****.**'
        god_user_id = db.auth_user.insert(**data)
        auth.add_membership(god_group_id, god_user_id)
except:
    db.rollback()
    raise HTTP(503)
else:
    db.commit()
コード例 #12
0
    vels_admin_group = auth.add_group('vels_admin', 'can change settings, can view statistics')
    vels_tutor_group = auth.add_group('vels_tutor', 'can view settings, can view statistics')

    # create initial admin
    fname = "vels_admin"
    lname = "vels_admin"
    email = "*****@*****.**"
    username = "******"
    passwd = "vels_admin"
    hashed_passwd = authdb.auth_user.password.requires[0](passwd)[0]

    initial_admin = authdb.auth_user.insert(first_name=fname,last_name=lname,email=email,
                        password=hashed_passwd, username=username)

    # make initial admin member of group vels_admins
    auth.add_membership(vels_admin_group, initial_admin)

    ##########################################################
    # set the permissions for each group
    ##########################################################
    auth.add_permission(vels_admin_group, 'edit data')
    auth.add_permission(vels_admin_group, 'view data')
    auth.add_permission(vels_admin_group, 'manage users')

    auth.add_permission(vels_tutor_group, 'view data')
    ##########################################################

    # use @auth.requires_permission('view data') for example as function decorator

else:
    pass