def logout(): try: token = request.headers['Authorization'] print(token) if DBSessions.select().where(DBSessions.token == token).count() == 1: DBSessions.delete().where(DBSessions.token == token).execute() return "Ok" return "Error" except: return "Error"
def login(email, password, ip): answer = '' result = DBUser.select(DBUser.id).where((DBUser.email == email) & (DBUser.password == hashlib.sha256(password.encode('utf-8')).hexdigest())) if result and result.count() == 1: for item in result: answer = uuid4() DBSessions.create(id = item.id, token = answer) else: print("No info") print("--",answer) return {'token':str(answer)}
def get_place_id_server(id): try: token = request.headers['Authorization'] if DBSessions.select().where(DBSessions.token == token).count() == 1: return get_place(id) return "Error" except: return "Error"
def add_place_server(): try: token = request.headers['Authorization'] print(DBSessions.select().where(DBSessions.token == token).count()) if DBSessions.select().where(DBSessions.token == token).count() == 1: return add_place( request.json["name"], request.json["description"], request.json["lat"], request.json["lng"], request.json.get('image'), request.json["type"] ) else: return "Error" except: return "Error"
def get_route_places_server(id): response.headers['Content-type'] = 'application/json' try: token = request.headers['Authorization'] if DBSessions.select().where(DBSessions.token == token).count() == 1: return get_route_places(id) return "Error" except: return "Error"
def remove_route_server(id): try: token = request.headers['Authorization'] if DBSessions.select().where(DBSessions.token == token).count() == 1: # request.forms.get("title") return remove_route( id ) return "Error" except: return "Error"
def add_route_server(): try: token = request.headers['Authorization'] if DBSessions.select().where(DBSessions.token == token).count() == 1: return add_route( request.json["name"], request.json["description"], request.json["total_places"], request.json["places"], request.json.get('image') ) else: return "Error" except: return "Error"