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()
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()
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() # importacion.rellena_beneficiarios()
# primarykey=['id'], # migrate='db.cohorte' # ) 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')
Field('observacion', default="", type="string"), Field('representante', 'reference usuario')) if not db(db.auth_membership.group_id == 4).select(): # Primer Usuario del Sistema id_usuario = db.usuario.insert(password=CRYPT()('admin')[0], first_name='admin', last_name='admin', email='*****@*****.**') # Roles cuidador = auth.add_group(role='Cuidador') maestro = auth.add_group(role='Maestro') representante = auth.add_group(role='Representante') admin = auth.add_group(role='Administrador') # Permisos para cada rol auth.add_permission(representante, 'Representante') auth.add_permission(maestro, 'Maestro') auth.add_permission(cuidador, 'Cuidador') auth.add_permission(admin, 'Representante') auth.add_permission(admin, 'Maestro') auth.add_permission(admin, 'Cuidador') auth.add_permission(admin, 'Administrador') # Dar privilegios de Administrador al usario creado auth.add_membership(admin, id_usuario)
primer_apellido='Bomberos', email_principal='*****@*****.**', genero='Masculino') db.bombero.insert(carnet=-1, cargo='Administrador', id_persona=id_persona, id_usuario=id_usuario) estudiante = auth.add_group(role='Estudiante', description='description') bombero = auth.add_group(role='Bombero', description='description') gerencia = auth.add_group(role='Gerencia', description='description') inspectoria = auth.add_group(role='Inspectoria', description='description') comandancia = auth.add_group(role='Comandancia', description='description') admin = auth.add_group(role='Administrador', description='description') auth.add_permission(estudiante, 'Estudiante') auth.add_permission(bombero, 'Estudiante') auth.add_permission(bombero, 'Bombero') auth.add_permission(gerencia, 'Estudiante') auth.add_permission(gerencia, 'Bombero') auth.add_permission(gerencia, 'Gerencia') auth.add_permission(inspectoria, 'Estudiante') auth.add_permission(inspectoria, 'Bombero') auth.add_permission(inspectoria, 'Gerencia') auth.add_permission(inspectoria, 'Inspectoria') auth.add_permission(comandancia, 'Estudiante') auth.add_permission(comandancia, 'Bombero')
''' Created on 2012-11-30 @author: fengclient ''' import sys sys.path.append('/data/web2py') from gluon.dal import DAL from gluon.tools import Auth if __name__ == '__main__': db = DAL('sqlite://../app_src/applications/bookit/databases/storage.sqlite') auth=Auth(db) g_manager_id=auth.add_group('Manager','can access the manage action/page') g_user_id=auth.add_group('User','can view and borrow') g_admin_id=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') pass
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 auth_user = authdb.auth_user auth_group = authdb.auth_group auth_membership = authdb.auth_membership
def construct_permissions(): """Automatically construct permissions hierarchy""" # logger = logzero.setup_logger(logfile="web2py.log", # formatter=logging.Formatter( # '%(asctime)s - %(levelname)-7s - %(funcName)s - %(message)s'), # disableStderrLogger=True) # logger.info("Constructing permissions system...") print("Constructing permissions system...") # # logger.info("Linking to db...") db = current.db auth = Auth(db) try: # logger.info("Creating user groups...") groupid_vbadmin = auth.add_group("VectorbiteAdmin", "Administrator group, has all permissions.") groupid_vdview = auth.add_group("VD Viewer", "Can view VecDyn.") groupid_vtview = auth.add_group("VT Viewer", "Can view VecTraits.") groupid_vdupload = auth.add_group("VD Uploader", "Can view and upload to VecDyn.") groupid_vtupload = auth.add_group("VT Uploader", "Can view and upload to VecTraits.") groupid_vdcurate = auth.add_group("VD Curator", "Can view, upload to, and curate VecDyn.") groupid_vtcurate = auth.add_group("VT Curator", "Can view, upload to, and curate VecTraits.") groupid_viewall = auth.add_group("View All", "Can view both databases.") # logger.info("Creating permissions...") # logger.debug("Adding permissions for Admin...") auth.add_permission(groupid_vbadmin, "view", "vecdyn") auth.add_permission(groupid_vbadmin, "upload", "vecdyn") auth.add_permission(groupid_vbadmin, "curate", "vecdyn") auth.add_permission(groupid_vbadmin, "view", "vectraits") auth.add_permission(groupid_vbadmin, "upload", "vectraits") auth.add_permission(groupid_vbadmin, "curate", "vectraits") # logger.debug("Adding permissions for View accounts...") auth.add_permission(groupid_vdview, "view", "vecdyn") auth.add_permission(groupid_vtview, "view", "vectraits") # logger.debug("Adding permissions for Upload accounts...") auth.add_permission(groupid_vdupload, "view", "vecdyn") auth.add_permission(groupid_vdupload, "upload", "vecdyn") auth.add_permission(groupid_vtupload, "view", "vectraits") auth.add_permission(groupid_vtupload, "upload", "vectraits") # logger.debug("Adding permissions for Curator accounts...") auth.add_permission(groupid_vdcurate, "view", "vecdyn") auth.add_permission(groupid_vdcurate, "upload", "vecdyn") auth.add_permission(groupid_vdcurate, "curate", "vecdyn") auth.add_permission(groupid_vtcurate, "view", "vectraits") auth.add_permission(groupid_vtcurate, "upload", "vectraits") auth.add_permission(groupid_vtcurate, "curate", "vectraits") # logger.debug("Adding permissions for Viewall account...") auth.add_permission(groupid_viewall, "view", "vecdyn") auth.add_permission(groupid_viewall, "view", "vectraits") # logger.info("Permission complete, comitting db...") db.commit() except Exception: # logger.exception("Encountered exception when constructing permissions system. Rolling back.") print("Encountered exception when constructing permissions system. Rolling back.") db.rollback() # logger.info("Permissions system created") return True