Esempio n. 1
0
def usuarioServicioCrearUsuario():
    try:
        bdapp = database.Connection()
        body = request.json
        email = body['email']
        query = """SELECT email FROM tausuario WHERE email='%s'""" % email
        response = bdapp.queryfetchone(query)
        if response['status']:
            if response['data']:
                return jsonify({'msg': 'Email Exist'}), 409
            else:
                serverMail = mailing.Conecction()
                code = funciones.randomString(40)
                redirect = 'http://localhost/kinecitas/#/validar/' + code
                html_content = '<strong>Validar <a target="_blank" href="' + redirect + '">VALIDAR CORREO</a></strong>'

                responseMail = serverMail.sendMail(email, 'Validar email',
                                                   html_content)
                print(responseMail)
                query = """INSERT INTO tausuario 
                            VALUES(default,'%s','kinecitas','%s',1,'A','')
                            """ % (email, code)
                response = bdapp.queryInsert(query)
                if response['status']:
                    return jsonify(response['data'])
                else:
                    return jsonify({'MySql Error': response['data']}), 500
        else:
            return jsonify({'MySql Error': response['data']}), 500
    except Exception as e:
        print("Log => " + str(e))
        return jsonify({'msg': str(e)}), 500
    finally:
        bdapp.close()
Esempio n. 2
0
def usuarioServicioValidarUsuario():
    try:
        bdapp = database.Connection()
        body = request.json
        code = body['code']
        password = body['password']
        query = """SELECT id FROM tausuario WHERE codigo='%s'""" % code
        response = bdapp.queryfetchone(query)
        if response['status']:
            if response['data']:
                idUsuario = int(response['data']['id'])
                hash = funciones.hash_password(password)
                print(hash)
                query = """UPDATE tausuario SET password='******' WHERE id=%i""" % (
                    hash, idUsuario)
                response = bdapp.queryUpdate(query)
                if response['status']:
                    return jsonify(response['data']), 201
                else:
                    return jsonify({'MySql Error': response['data']}), 500
            else:
                return jsonify({'msg': 'Codigo No valido'}), 204
        else:
            return jsonify({'MySql Error': response['data']}), 500
    except Exception as e:
        print("Log => " + str(e))
        return jsonify({'msg': str(e)}), 500
    finally:
        bdapp.close()
Esempio n. 3
0
def kinecitaServicioModificarKinecita():
    try:
        bdapp = database.Connection()
        body = request.json
        id = body['id']
        telefono = body['telefono']
        nombres = body['nombres']
        edad = body['edad']
        pais = body['pais']
        etnia = body['etnia']
        query = """UPDATE takinesiologa 
                    SET telefono='%s',
                        nombre = '%s',
                        edad = %i,
                        etnia_id = %i,
                        pais_id = %i
                    WHERE usuario_id=%i    
                    """ % (telefono, nombres, int(edad), int(etnia), int(pais),
                           int(id))
        response = bdapp.queryUpdate(query)
        if response['status']:
            return jsonify(response['data'])
        else:
            return jsonify({'MySql Error takinesiologa':
                            response['data']}), 500
    except Exception as e:
        print("Log => " + str(e))
        return jsonify({'msg': str(e)}), 500
    finally:
        bdapp.close()
Esempio n. 4
0
def securityServiceTokenValid(token):
    try:
        bdapp = database.Connection()
        query = "select id,email from tausuario where token='%s'"
        response = bdapp.queryfetchone(query % (token))
        if (response['data']):
            return {'status': True, 'data': response['data']}
        else:
            return {'status': False, 'data': 'Token Invalid'}
    except Exception as e:
        return {'status': False, 'data': str(e)}
    finally:
        bdapp.close()
Esempio n. 5
0
def usuarioServicioLoginUsuario():
    try:
        bdapp = database.Connection()
        body = request.json
        email = body['email']
        password = body['password']
        query = """SELECT password FROM tausuario WHERE email='%s'""" % email
        response = bdapp.queryfetchone(query)
        if response['status']:
            if response['data']:
                password_store = response['data']['password']
                valido = funciones.verify_password(password_store, password)
                if valido:
                    query = """SELECT a.id,a.email,a.perfil_id,b.nombre redirect
                            FROM tausuario a
                            JOIN gnusuarioperfil b on b.id=a.perfil_id
                            where email='%s'
                            """ % email
                    response = bdapp.queryfetchone(query)
                    if response['status']:
                        token = "asdasdasd"
                        query = """UPDATE tausuario SET token='%s' WHERE id=%i""" % (
                            token, response['data']['id'])
                        update = bdapp.queryUpdate(query)
                        if update['status']:
                            response['data']['token'] = token
                            print(response['data'])
                            return jsonify(response['data'])
                        else:
                            return jsonify({'MySql Error':
                                            update['data']}), 500
                    else:
                        return jsonify({'MySql Error': response['data']}), 500
                else:
                    return jsonify({'msg': 'Credenciales Incorrectas'}), 409
            else:
                return jsonify({'msg': 'Email no Existe'}), 204
        else:
            return jsonify({'MySql Error': response['data']}), 500
    except Exception as e:
        print("Log => " + str(e))
        return jsonify({'msg': str(e)}), 500
    finally:
        bdapp.close()
Esempio n. 6
0
def kinecitaServicioVerKinecita(id):
    try:
        bdapp = database.Connection()
        query = """SELECT a.id,a.telefono,a.nombre,a.edad,a.etnia_id,b.nombre etnia_nombre,a.pais_id,c.nombre pais_nombre
                FROM takinesiologa a
                JOIN taetnia b on b.id=a.etnia_id
                JOIN tapais c on c.id=a.pais_id
                WHERE a.usuario_id=%i""" % id
        response = bdapp.queryfetchone(query)
        result = {}
        if response['status']:
            return jsonify(response['data'])
        else:
            return jsonify({'MySql Error tapais': response['data']}), 500
    except Exception as e:
        print("Log => " + str(e))
        return jsonify({'msg': str(e)}), 500
    finally:
        bdapp.close()
Esempio n. 7
0
def kinecitaServicioCrearKinecita():
    try:
        bdapp = database.Connection()
        body = request.json
        id = body['id']
        telefono = body['telefono']
        nombres = body['nombres']
        edad = body['edad']
        pais = body['pais']
        etnia = body['etnia']
        query = "INSERT INTO takinesiologa VALUES(DEFAULT,'%s','%s',%i,'NO',%i,%i,%i,'A')" % (
            telefono, nombres, int(edad), int(etnia), int(pais), int(id))
        response = bdapp.queryInsert(query)
        if response['status']:
            return jsonify(response)
        else:
            return jsonify({'MySql Error tapais': response['data']}), 500
    except Exception as e:
        print("Log => " + str(e))
        return jsonify({'msg': str(e)}), 500
    finally:
        bdapp.close()
Esempio n. 8
0
def kinecitaServiceFormDatos():
    try:
        bdapp = database.Connection()
        query = "SELECT id,nombre FROM tapais WHERE estado='A'"
        response = bdapp.queryfetchall(query)
        result = {}
        if response['status']:
            result['paises'] = response['data']
            query = "select id,nombre from taetnia where estado='A'"
            response = bdapp.queryfetchall(query)
            if response['status']:
                result['etnias'] = response['data']
                return jsonify(result)
            else:
                return jsonify({'MySql Error taetnia': response['data']}), 500
        else:
            return jsonify({'MySql Error tapais': response['data']}), 500
    except Exception as e:
        print("Log => " + str(e))
        return jsonify({'msg': str(e)}), 500
    finally:
        bdapp.close()