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")
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")
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)
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))
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!'
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))
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!'
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))
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})
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})
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 user_to_dict(self, user: us.User): dict_formatted = {} if user: dict_formatted['user_id'] = user.get_userID() dict_formatted['first_name'] = user.get_first_name() dict_formatted['last_name'] = user.get_last_name() dict_formatted['admin'] = str(user.get_admin()) dict_formatted['business_unit'] = user.get_business_unit() dict_formatted['email'] = user.get_email() dict_formatted['password'] = "******" dict_formatted['access_rights_pillars'] = json.dumps( user.get_access_rights_pillars()) dict_formatted['role_manager'] = user.get_role_manager() return dict_formatted
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"
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)
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")
def insert_user_db(self, user: us.User): local = False access_rights_pillars = json.dumps(user.get_access_rights_pillars()) access_rights_pillars = access_rights_pillars.replace('"', "'") # Creates Table db_utils.DataBaseUtils.execute_sql( db_utils.DataBaseUtils, sql_statement=sql_stmt.DataBaseSQL. create_User_table_sql(sql_stmt.DataBaseSQL), local=local) # Inserts data db_utils.DataBaseUtils.execute_sql(db_utils.DataBaseUtils, sql_statement=sql_stmt.DataBaseSQL. insert_user_values( sql_stmt.DataBaseSQL, userID=user.get_userID(), first_name=user.get_first_name(), last_name=user.get_last_name(), email=user.get_email(), password=user.get_password(), business_unit=user.get_business_unit(), access_rights_pillars=access_rights_pillars, admin=user.get_admin(), role_manager=user.get_role_manager()), local=local)
def users(): user = User() users = user.search_all_users() return render_template('/users.html', users=users)
def get_users_db(token): if token != token_padrao_get_db: return jsonify({'response': 'Token Invalido'}) user = User() return user.generate_sql_insert_users()