Beispiel #1
0
def update_user_conn(*user_id):
    from datetime import datetime
    from orm.model.ucar.persona import Persona

    for id in user_id:
        now = datetime.now().strftime("%d-%m-%Y %H:%M:%S")
        Persona.update(conexion=now).where(Persona.id == id).execute()
def actualizar_perfil():
    try:
        data = dict(request.get_json())
        query = Persona.select().where(Persona.id == data['id'])
        if query.exists():
            #update_user_conn([data['userId']])
            if data['password'] == "":
                nrows = (Persona.update(
                    nombre=data['nombre'],
                    apellido=data['apellido'],
                    email=data['email'],
                    institucion=data['institucion']).where(
                        Persona.id == data['id']).execute())
            else:
                nrows = (Persona.update(
                    nombre=data['nombre'],
                    apellido=data['apellido'],
                    email=data['email'],
                    institucion=data['institucion'],
                    password=data['password']).where(
                        Persona.id == data['id']).execute())
            #update_user_conn([data['id']])
            return {"status": "ok", "message": "Perfil Modificado!"}
        return {'status': 'error', 'message': 'Esa persona no existe!'}
    except:
        return {'status': 'error', 'message': 'Error de conexion!'}
def usuario_registrar():
    try:
        data = dict(request.get_json())
        query = Cliente.select().where(Cliente.email == data['email'])
        if query.exists():
            new = Persona(**data)
            new.save()
            return {"status": "ok", "message": "usuario creado"}
        return {'status': 'error', 'message': 'Email no admitido!'}
    except:
        return {'status': 'error', 'message': 'Error de conexion!'}
    return {'status': 'error', 'message': 'usuario no creado'}
Beispiel #4
0
def SubirFoto():
    try:
        data = dict(request.get_json())
        query = Persona.select().where(Persona.id == data['userId'])
        if query.exists():
            update_user_conn([data['userId']])
            foto = open(
                "/opt/rh/httpd24/root/var/www/ucar/html/env2/fotos/aux", "w")
            foto.write(data['imgData'])
            foto.close()
            sub.run([
                "/opt/rh/httpd24/root/var/www/ucar/html/env2/scripts/decode.sh",
                "/opt/rh/httpd24/root/var/www/ucar/html/env2/fotos/aux",
                "/opt/rh/httpd24/root/var/www/ucar/html/env2/fotos/" +
                str(data['userId'])
            ])
            sub.run([
                "/opt/rh/httpd24/root/var/www/ucar/html/env2/scripts/rename.sh",
                "/opt/rh/httpd24/root/var/www/ucar/html/env2/fotos/" +
                str(data['userId'])
            ])
            return {"status": "ok", "message": "Foto Subida!"}
        else:
            return {"status": "error", "message": "Esa persona no existe!"}
    except:
        return {"status": "error", "message": "Error Interno"}
Beispiel #5
0
def usuario_listar():
    data = []
    try:
        query = Persona.select()
        for result in query.dicts():
            data.append(result)
    except:
        return {"status": "error", "message": "Error de conexion!"}
    return jsonify(data)
def usuario_recuperar_cuenta():
    data = request.args.get('email')
    if data:
        query = Persona.select(Persona.password).where(Persona.email == data)
        if query.exists():
            regex = '^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$'
            if search(regex, data):
                pw = str(uuid1())[0:5]
                query = (Persona.update({
                    Persona.password:
                    md5(pw.encode()).hexdigest()
                }).where(Persona.email == data).execute())
                if query:
                    ucar_sendemail(data, f'password {pw}')
                    return {'status': 'ok', 'message': 'email enviado'}
                return {'status': 'error', 'message': 'error al actualizar'}
            return {'status': 'error', 'message': 'email no valido'}
        return {'status': 'error', 'message': 'email no encontrado'}
    return {'status': 'error', 'message': 'falta parametro'}
def usuario_datos():
	data = []
	try:
		query = Persona.select().where(Persona.email == request.args.get("email"))
		if query:
			for result in query.dicts():
				data.append(result)
		else:
			return {"status":"error","message":"Esa Persona no existe!"}
	except:
		return {"status":"error","message":"Error de conexion!"}
	return jsonify(data[0])
Beispiel #8
0
def usuario_identificar():
    query = Select(None)
    try:
        data = dict(request.get_json())
        query = Persona.select(Persona.id, Persona.email, Persona.password)\
         .where((Persona.email == data['email']) & (Persona.password == data['password']))
        if query.exists():
            update_user_conn([query[0].id])
            return {'status': 'ok', 'message': f'{query[0].id}'}
    except:
        return {"status": "error", "message": "pg select"}
    return {
        'status': 'error',
        'message': 'El usuario no se encuentra registrado!'
    }