예제 #1
0
파일: api02.py 프로젝트: enanlara/2TsServer
def editUser():
    if session.get('token') is None:
        return render_template(
            '/login.html',
            message="You have to login to access this module",
            alertlevel="warning")
    user = User()

    id = request.form['id1']
    nome = request.form['name']
    email = request.form['email']
    senha = request.form['password']
    permissao = request.form['permission']

    users = user.search_all_users()

    try:
        response = user.edit_user(id, nome, email, senha, permissao)
        if response == False:
            return render_template('/users.html',
                                   message="Error while editing user",
                                   alertlevel="danger",
                                   users=users)
        else:
            return render_template('/users.html',
                                   message="User successfully edited",
                                   alertlevel="success",
                                   users=users)

    except Exception as e:
        return render_template(
            '/users.html',
            message=
            "A database error has occurred. Contact your system administrator",
            alertlevel="danger")
예제 #2
0
파일: api02.py 프로젝트: enanlara/2TsServer
def post_login():
    email = request.form['email']
    password = request.form['password']

    user = User()
    try:
        response = user.autenticate(email, password)
        if response == False:
            return render_template(
                '/login.html',
                message="You have entered an invalid username or password",
                alertlevel="danger")
        else:
            cria_sessao(response.id, response.name, response.email,
                        response.permission, response.token)
            return render_template('/inicial.html',
                                   message="Welcome",
                                   alertlevel="success",
                                   user=response)
    except Exception as e:
        print(e)
        return render_template(
            '/login.html',
            message=
            "A database error has occurred. Contact your system administrator",
            alertlevel="danger")
예제 #3
0
파일: api02.py 프로젝트: enanlara/2TsServer
def deleteUser():
    if session.get('token') is None:
        return render_template(
            '/login.html',
            message="You have to login to access this module",
            alertlevel="warning")
    userId = request.form['userId']
    user = User()
    try:
        response = user.delete_user(userId)
        users = user.search_all_users()
        if response == True:
            return render_template('/usersgrid.html',
                                   message="User deleted sucessfully",
                                   alertlevel="success",
                                   users=users)
        else:
            return render_template('/usersgrid.html',
                                   message="Error deleting user",
                                   alertlevel="warning",
                                   users=users)
    except Exception as e:
        return render_template(
            '/usersgrid.html',
            message=
            "A database error has occurred. Contact your system administrator",
            alertlevel="danger",
            users=users)
예제 #4
0
파일: api02.py 프로젝트: enanlara/2TsServer
def logar(email, password):
    user = User()
    response = user.autenticate(email, password)
    if response == False:
        return jsonify({'response': 'Nenhum usuario encontrado'})
    elif response == 'ERRO':
        return jsonify({'response': 'Ocorreu um erro no servidor'})
    else:
        return json.dumps(para_dict(response))
예제 #5
0
파일: api02.py 프로젝트: enanlara/2TsServer
def usersgrid():
    users = User()
    users = users.search_all_users()
    if session.get('token') is None:
        return render_template(
            '/login.html',
            message="You have to login to access this module",
            alertlevel="warning")
    return render_template('/usersgrid.html', users=users)
def findUser():
    id = request.form['id']
    user = User()
    users = user.search_all_users()
    try:
        response = user.search_user_by_id(id)
        if response == False:
            return "Erro ao buscar usuário"
        else:
            return render_template('/users.html', users=users, user1=response)

    except Exception as e:
        return 'Erro no servidor. Contate o analista responsável!'
예제 #7
0
파일: api02.py 프로젝트: enanlara/2TsServer
def search_things_over_by_location(token, loca_id):
    # valida token
    user = User()
    resp = user.verify_token(token)
    if resp == False:
        return jsonify({'response': 'Token Invalido'})
    elif resp == 'ERRO':
        return jsonify({'response': 'Erro ao verificar token'})

    thingsXLocation = ThingsXLocation()
    response = thingsXLocation.search_things_over_by_location(loca_id)
    if response == False:
        return jsonify({'response': 'Nenhum objeto encontrado'})
    elif response == 'ERRO':
        return jsonify({'response': 'Ocorreu um erro no servidor'})
    else:
        return json.dumps(para_dict(response))
예제 #8
0
파일: api02.py 프로젝트: enanlara/2TsServer
def search_locations(token):
    # valida token
    user = User()
    resp = user.verify_token(token)
    if resp == False:
        return jsonify({'response': 'Token Invalido'})
    elif resp == 'ERRO':
        return jsonify({'response': 'Erro ao verificar token'})

    location = Locations()
    response = location.search_all_locations()
    if response == False:
        return jsonify({'response': 'Nenhuma localizacao encontrada'})
    elif response == 'ERRO':
        return jsonify({'response': 'Ocorreu um erro no servidor'})
    else:
        return json.dumps(para_dict(response))
예제 #9
0
파일: api02.py 프로젝트: enanlara/2TsServer
def search_all_things_actives(token):
    # valida token
    user = User()
    resp = user.verify_token(token)
    if resp == False:
        return jsonify({'response': 'Token Invalido'})
    elif resp == 'ERRO':
        return jsonify({'response': 'Erro ao verificar token'})

    things = Things()
    response = things.search_all_things_actives()
    if response == False:
        return jsonify({'response': 'Nenhum objeto encontrado'})
    elif response == 'ERRO':
        return jsonify({'response': 'Ocorreu um erro no servidor'})
    else:
        return json.dumps(para_dict(response))
def editUser():
    id = request.form['id1']
    nome = request.form['name']
    email = request.form['email']
    senha = request.form['password']
    permissao = request.form['permission']

    user = User()
    try:
        response = user.edit_user(id, nome, email, senha, permissao)
        if response == False:
            return "Erro ao atualizar usuário"
        else:
            return "Usuario atualizado com sucesso"

    except Exception as e:
        return 'Erro no servidor. Contate o analista responsável!'
예제 #11
0
파일: api02.py 프로젝트: enanlara/2TsServer
def edit_things(token, num_patr, location_c, situation, state, note, location):
    # verifica validade do token
    user = User()
    resp = user.verify_token(token)
    if resp == False:
        return jsonify({'response': 'Token Invalido'})
    elif resp == 'ERRO':
        return jsonify({'response': 'Erro ao verificar token'})
    else:
        user_id = resp.id

    thingsSynchronization = ThingsSynchronization()
    response = thingsSynchronization.synchronize_things(
        num_patr, situation, state, note, user_id, location_c, location)
    if response == True:
        return jsonify({"response": "OK"})
    else:
        return jsonify({"response": response})
예제 #12
0
파일: api02.py 프로젝트: enanlara/2TsServer
def synchronize_location(token, location, num_patr):
    # verifica validade do token
    user = User()
    resp = user.verify_token(token)
    if resp == False:
        return jsonify({'response': 'Token Invalido'})
    elif resp == 'ERRO':
        return jsonify({'response': 'Erro ao verificar token'})
    else:
        user_id = resp.id

    thingsSynchronization = ThingsSynchronization()
    response = thingsSynchronization.synchronize_location(
        num_patr, location, user_id)
    if response == True:
        return jsonify({'response': 'true'})
    else:
        return jsonify({'response': response})
예제 #13
0
파일: api02.py 프로젝트: enanlara/2TsServer
def active_thing_by_num(token, num):
    # valida token
    user = User()
    resp = user.verify_token(token)
    if resp == False:
        return jsonify({'response': 'Token Invalido'})
    elif resp == 'ERRO':
        return jsonify({'response': 'Erro ao verificar token'})

    things = Things()
    exits = things.search_things_by_num1(num)
    if exits:
        response = things.active_things_by_num1(num)
        if response == False:
            return jsonify(
                {'response': 'Ocorreu um erro ao ativar a etiqueta'})
        else:
            return jsonify({'response': 'true'})
    else:
        return jsonify({'response': 'Objeto não encontrado'})
def adduser():
    nome = request.form['name']
    email = request.form['email']
    senha = request.form['password']
    permissao = request.form['permission']
    token = ''.join(
        random.choice(string.ascii_uppercase + string.digits)
        for _ in range(9))

    user = User()

    try:
        response = user.insert_new_user(nome, email, senha, token, permissao)
        if response == True:
            return "sucesso"
        else:
            return "Erro ao cadastrar usuário."

    except Exception as e:
        return 'Erro no servidor. Contate o analista responsável!'
def post_login():
    email = request.form['email']
    password = request.form['password']

    user = User()
    try:
        response = user.autenticate(email, password)
        if response == False:
            return render_template(
                '/login.html',
                message="You have entered an invalid username or password")
        else:
            session.pop('user', None)
            session['token'] = response.token
            session['id'] = response.id
            session['name'] = response.name
            session['user'] = request.form['email']
            session['permission'] = response.permission
            return render_template('/inicial.html', message=session['name'])
    except Exception as e:
        print(e)
        return "Erro no servidor. Contate o Analista"
예제 #16
0
파일: api02.py 프로젝트: enanlara/2TsServer
def findUser():
    if session.get('token') is None:
        return render_template(
            '/login.html',
            message="You have to login to access this module",
            alertlevel="warning")
    id = request.form['userId']
    user = User()
    users = user.search_all_users()
    try:
        response = user.search_user_by_id(id)
        if response == False:
            return render_template('/users.html',
                                   message="Error finding user",
                                   alertlevel="danger")
        else:
            return render_template('/users.html', users=users, user1=response)

    except Exception as e:
        return render_template(
            '/users.html',
            message=
            "A database error has occurred. Contact your system administrator",
            alertlevel="danger")
예제 #17
0
파일: api02.py 프로젝트: enanlara/2TsServer
def adduser():
    if session.get('token') is None:
        return render_template(
            '/login.html',
            message="You have to login to access this module",
            alertlevel="warning")
    user = User()
    nome = request.form['name']
    email = request.form['email']
    senha = request.form['password']
    permissao = request.form['permission']
    token = ''.join(
        random.choice(string.ascii_uppercase + string.digits)
        for _ in range(9))

    try:
        response = user.insert_new_user(nome, email, senha, token, permissao)
        users = user.search_all_users()
        if response == True:
            return render_template('/users.html',
                                   message="User added successfully",
                                   alertlevel="success",
                                   users=users)
        else:
            return render_template('/users.html',
                                   message="Error adding user",
                                   alertlevel="danger",
                                   users=users)

    except Exception as e:
        return render_template(
            '/users.html',
            message=
            "A database error has occurred. Contact your system administrator",
            alertlevel="danger",
            users=users)
예제 #18
0
파일: api02.py 프로젝트: enanlara/2TsServer
def get_users_db(token):
    if token != token_padrao_get_db:
        return jsonify({'response': 'Token Invalido'})

    user = User()
    return user.generate_sql_insert_users()
def users():
    user = User()
    users = user.search_all_users()

    return render_template('/users.html', users=users)