Exemplo n.º 1
0
from flask import session, url_for, request
from functools import wraps

from filoLogic.SessionLogic import SessionLogic
from filoModules.Returns import Returns
from filoModules.Debug import Debug
from filoRoutes import LandingRoutes as rLanding
from filoRoutes import UserRoutes as rUser
from filoRoutes import AuthRoutes as rAuth
from filoModules.Models.Session import Session as m_Session

debug = Debug("Decorators")


def needs_to_be_guest(f):
    @wraps(f)
    def decorated_function(*args, **kwargs):
        debug.print_v("on needs_to_be_guest()")
        logic_resp = SessionLogic.get()
        if not logic_resp.success:
            debug.print_e(f"needs_to_be_guest: {logic_resp.content}")
            return Returns.return_message("Error connecting to the database!",
                                          "Please try again later!", 5,
                                          rLanding.index.route_path)
        User_Session = logic_resp.addon_data
        User_Session: m_Session
        if User_Session.logged_in:
            debug.print_w(f"needs_to_be_guest: already registered")
            return Returns.return_message("You are already registered!", "", 0,
                                          rUser.index.route_path)
        return f(*args, **kwargs)
Exemplo n.º 2
0
from flask import Blueprint, render_template, session, redirect, render_template
from filoModules.Debug import Debug
from filoRoutes import LandingRoutes as r
from filoRoutes import AuthRoutes as rAuth
from filoRoutes import AdminRoutes as rAdmin
import config

LandingView = Blueprint("LandingView", __name__)

debug = Debug("LandingView")


@LandingView.route(r.index.route_path)
def index():
    debug.print_v("on index()")
    debug.print_v(f"Version: {config.get_version()}")
    return render_template("webapp/index.html", config=config)
Exemplo n.º 3
0
from flask import Blueprint, render_template, session, redirect, render_template, url_for, request
from filoLogic.UserLogic import ViewUserLogic
from filoModules.Debug import Debug
from filoModules.Returns import Returns
from filoModules import Decorators
from filoRoutes import UserRoutes as r
from filoRoutes import AuthRoutes as rAuth
from filoLogic.SessionLogic import SessionLogic
from filoModules.Models.Session import Session as m_Session
from filoModules.Models.Findlock import Findlock as m_Findlock
UserView = Blueprint("UserView", __name__)

debug = Debug("UserView")



@UserView.route(r.add_friend.route_path, methods=r.add_friend.http_types)
@Decorators.needs_to_be_logged_in
@Decorators.update_session
def add_friend():
    if request.method == 'GET':
        return render_template("webapp/user/confirm.html")

    logic_resp = SessionLogic.get()
    if not logic_resp.success:
        return Returns.return_message("Something went wrong!", logic_resp.content, 2, r.index.route_path)
    _session = logic_resp.addon_data
    _session: m_Session
    print(request.form)
    logic_resp = ViewUserLogic.add_friend(_session, request.form)
    if not logic_resp.success:
Exemplo n.º 4
0
from filoLogic.AdminLogic import ViewAdminLogic, AdminLogic
from filoModules.Debug import Debug
from filoModules.Returns import Returns
from filoRoutes import AdminRoutes as r
from filoModules.Models.User import User as m_User
from filoModules.Models.User import UserEntries as m_UserEntries
from filoModules.Models.Findlock import Findlock as m_Findlock
from filoModules.Models.Findlock import FindlockEntries as m_FindlockEntries
from filoModules import Decorators

import uuid
import time

AdminView = Blueprint("AdminView", __name__)
debug = Debug("AdminView")

@AdminView.route(r.logs.route_path, methods=r.logs.http_types)
@Decorators.needs_to_be_logged_in
@Decorators.needs_to_be_admin
def logs():
    logic_resp = ViewAdminLogic.get_raw_logs()
    if not logic_resp.success:
        return render_template("admin/logs.html", logs=f"Error. {logic_resp.content}")
    return render_template("admin/logs.html", logs=logic_resp.addon_data)

@AdminView.route(r.view_logs.route_path, methods=r.view_logs.http_types)
@Decorators.needs_to_be_logged_in
@Decorators.needs_to_be_admin
def view_logs():
    return render_template("admin/view_logs.html", AdminRoutes=r)
Exemplo n.º 5
0
from filoViews.UserView import UserView
from filoViews.AdminView import AdminView

from filoLogic.UserLogic import UserLogic
from filoLogic.RestLogic import RestLogic

from filoModules.Database.Handler import Handler
from filoModules.Database.User import User as db_User
from filoModules.Database.Findlock import Findlock as db_Findlock
from filoModules.Models.GpsLocation import GpsLocation as m_GpsLocation
from filoModules.Models.Findlock import Findlock as m_Findlock
from filoModules.Models.Findlock import FindlockUpdateTypes as m_FindlockUpdateTypes
from filoModules.Debug import Debug
from werkzeug.exceptions import HTTPException

debug = Debug("app.py")
debug.print_v("=" * 16)
debug.print_v("= Filo Server")
debug.print_v("=" * 16)

app = Flask(__name__)
app_blueprints = [RestView, LandingView, AuthView, UserView, AdminView]
for b in app_blueprints:
    app.register_blueprint(b)

app.config.from_object(config.get_flask_conf_obj())
Session(app)

debug.reset_log()

Exemplo n.º 6
0
from flask import Blueprint, render_template, request, url_for, session

from filoLogic.AuthLogic import ViewAuthLogic

from filoModules.Debug import Debug
from filoModules.Returns import Returns
from filoModules import Decorators
from filoRoutes import AuthRoutes as r
from filoRoutes import UserRoutes as rUser
from filoRoutes import AuthRoutes as rAuth
from filoRoutes import LandingRoutes as rLanding
from filoModules.Models.Session import Session as m_Session

AuthView = Blueprint("AuthView", __name__)

debug = Debug("AuthView")


@AuthView.route(r.google_verify.route_path, methods=r.google_verify.http_types)
@Decorators.needs_to_be_guest
def google_verify():
    return "ok?"


@AuthView.route(r.facebook_login.route_path,
                methods=r.facebook_login.http_types)
@Decorators.needs_to_be_guest
def facebook_login():
    logic_resp = ViewAuthLogic.facebook_login(request.form)
    if logic_resp.success:
        return "yes"
Exemplo n.º 7
0
 def __init__(self, collection_name):
     self.client = pymongo.MongoClient(config.get_mongo_config().get_url())
     self.collection_name = collection_name
     self.collection = self.client['filo'][collection_name]
     self.debug = Debug(f"DbHandler({collection_name})", enabled=False)
Exemplo n.º 8
0
class Handler:  # method/constructor overloading: a
    def __init__(self, collection_name):
        self.client = pymongo.MongoClient(config.get_mongo_config().get_url())
        self.collection_name = collection_name
        self.collection = self.client['filo'][collection_name]
        self.debug = Debug(f"DbHandler({collection_name})", enabled=False)

    def find_all(self):
        self.debug.print_v(f"Finding it all! col:{self.collection_name}")
        return self.collection.find({})

    def drop_all(self):
        self.debug.print_w(f"Dropping whole database!")
        return self.client.drop_database('filo')

    def drop_col(self):
        self.debug.print_w(f"Dropping col:{self.collection_name}")
        return self.collection.drop()

    def find_one(self, search_dict: dict):
        self.debug.print_v(
            f"Searching for dict ({search_dict}) in '{self.collection_name}'")
        return self.collection.find_one(search_dict)

    def insert_one(self, insert_dict: dict):
        self.debug.print_v(
            f"Inserting dict ({insert_dict}) in '{self.collection_name}'")
        return self.collection.insert_one(insert_dict)

    def update_one(self, query: dict, new_values: dict):
        self.debug.print_v(
            f"Updating dict ({query}) with '{new_values}' in '{self.collection_name}'"
        )
        return self.collection.update_one(query, new_values)

    def delete_one(self, delete_dict: dict):
        self.debug.print_v(
            f"Deleting dict ({delete_dict}) in '{self.collection_name}'")
        return self.collection.delete_one(delete_dict)
Exemplo n.º 9
0
from flask import jsonify, render_template
from filoModules.Debug import Debug


debug = Debug("Returns")
class Returns:
    @staticmethod
    def return_message(title, content, r_time, r_url):
        debug.print_d(f"Returning message | title:{title},content:{content},r_time:{r_time},r_url:{r_url}")
        return render_template("webapp/alert.html",
            title=str(title),
            content=str(content),
            r_time=str(r_time),
            r_url=str(r_url)
        )
Exemplo n.º 10
0
from flask import Blueprint, render_template, session, redirect, request, jsonify

from filoLogic.RestLogic import ViewRestLogic
from filoModules.Models.ApiReturn import ApiReturn
from filoModules.Debug import Debug
from filoRoutes import RestRoutes as r
from filoModules import Decorators
import json

from filoRoutes import AdminRoutes, AuthRoutes, LandingRoutes, RestRoutes, UserRoutes

RestView = Blueprint("RestView", __name__)
debug = Debug("RestView")


@RestView.route(r.get_last_location.route_path,
                methods=r.get_last_location.http_types)
def get_last_location(device_uuid):
    logic_resp = ViewRestLogic.get_findlock_location(device_uuid)
    if not logic_resp.success:
        return ApiReturn.f_error(logic_resp.content).toFlask()
    return jsonify(logic_resp.addon_data)


@RestView.route(r.get_name_by_uuid.route_path,
                methods=r.get_name_by_uuid.http_types)
def get_name_by_uuid(i_uuid):
    logic_resp = ViewRestLogic.get_name_by_uuid(i_uuid)
    if not logic_resp.success:
        return ApiReturn.f_error(logic_resp.content).toFlask()
    return ApiReturn.f_success(logic_resp.content).toFlask()