コード例 #1
0
ファイル: controller.py プロジェクト: Houssam-dev974/TEK1
 def add_task(self, username, title, task_id, status):
     model = Models()
     if (model.check_task_id(task_id[0]) == True):
         return (jsonify(error="task id already exists"))
     try:
         model.add_task_user(username, task_id[0], title[0], status)
     except:
         return (jsonify(error="internal error"))
     return jsonify(result="new task added")
コード例 #2
0
ファイル: controller.py プロジェクト: Houssam-dev974/TEK1
 def fetch_user_infos(self, name):
     model = Models()
     try:
         user = model.username_info(name)
         pwd = model.pwd_info(name)
         user_id = model.id_info(name)
         return jsonify(username=user[0], password=pwd[0], id=user_id[0])
     except:
         return (jsonify(error="internal error"))
コード例 #3
0
ファイル: controller.py プロジェクト: Houssam-dev974/TEK1
 def del_task(self, task_id):
     model = Models()
     if (model.check_task_id(task_id[0]) == False):
         return (jsonify(error="task id does not exist"))
     try:
         model.remove_task(task_id[0])
     except:
         return (jsonify(error="internal error"))
     return jsonify(result="task deleted")
コード例 #4
0
ファイル: controller.py プロジェクト: Houssam-dev974/TEK1
 def register(self, user, password, _id):
     model = Models()
     if (model.check_username(user[0]) == True):
         return (jsonify(error="account already exists"))
     try:
         model.add_data(_id[0], user[0], password[0])
     except Exception as e:
         print("Caught an exception : ", e)
         return (jsonify(error="internal error"))
     return (jsonify(result="account created"))
コード例 #5
0
ファイル: controller.py プロジェクト: Houssam-dev974/TEK1
 def signin(self, user, password):
     model = Models()
     try:
         if (model.check_username(user[0]) == True
                 and model.check_password(password[0]) == True):
             return (jsonify(result="signin successful"))
         else:
             return (jsonify(error="login or password does not match"))
     except:
         return (jsonify(error="internal error"))
コード例 #6
0
ファイル: controller.py プロジェクト: Houssam-dev974/TEK1
 def view_task(self):
     model = Models()
     try:
         if (model.find_task() == True):
             result = model.get_task()
             return (jsonify(result))
         else:
             abort(500)
     except:
         return (jsonify(error="internal error"))
コード例 #7
0
class Controller(object):
    def __init__(self, user_id):
        self.user_id = user_id
        self.username = None
        self.models = Models(user_id)

    def index_action(self):
        return render_template("index.html", username=self.username)

    def register_action(self):
        if request.method == 'POST':
            username = request.form['username']
            password = request.form['password']
            if (len(username) == 0 or len(password) == 0):
                return render_template("alerts/invalid_logs_reg.html")
            return self.models.register_model(username, password)
        return render_template("register.html", username=self.username)

    def signout_action(self):
        if self.models.user_id != -1:
            self.models.user_id = -1
            return render_template("alerts/logged_out.html",
                                   username=self.username)
        return render_template("/index.html", username=self.username)

    def signin_action(self):
        if request.method == 'POST':
            username = request.form['username']
            password = request.form['password']
            self.username = username
            if (len(username) == 0 or len(password) == 0):
                return render_template("alerts/invalid_logs.html")
            return self.models.sign_in_model(username, password)
        return render_template("signin.html")

    def display_task_action(self):
        result = self.models.display_task_model()
        return render_template("tasks_view.html",
                               tables=result,
                               username=self.username)

    def add_task_action(self):
        if request.method == 'POST':
            task = request.form['task']
            begin = request.form['begin']
            end = request.form['end']
            if (task and begin and end):
                self.models.task_create_model(task, begin, end)
        return self.display_task_action()
コード例 #8
0
def new_model():
    if not current_user.is_authenticated:
        flash("You have to login first")
        return render_template('index.html', title=_('Home'))

    form = ModelForm()
    if form.add_target.data:
        form.model_targets.append_entry('')
    elif form.remove_target.data:
        form.model_targets.pop_entry()
    elif request.form and form.validate_on_submit():
        flash("A new model is under construct!")
        targets = ""
        for target in form.model_targets.data:
            targets += target + "#"
        targets = targets[:-1]  # delete the last '#'
        now = datetime.now().strftime("%Y%m%d%H%M")
        data = {'name': form.model_name.data + now, 'targets': targets}
        r = requests.post("http://localhost:9999", data=data)

        flash(r.text)

        model = Models(model_name=form.model_name.data,
                       model_target=targets,
                       author=current_user,
                       model_path=osp.join(ServerConfig.MODEL_PATH,
                                           form.model_name.data + now),
                       timestamp=datetime.now())
        db.session.add(model)
        db.session.commit()
        return redirect(url_for('main.index', title="Home"))

    return render_template('model/new_model.html',
                           form=form,
                           title=_('Create_model'))
コード例 #9
0
 def handle_register(self, request):
     try:
         username = request.args["username"]
         password = request.args["password"]
         salt = "BEST_SALT" + username
         hash = hashlib.sha512()
         hash.update(salt.encode())
         hash.update(password.encode())
         password = hash.hexdigest()
         if self.is_connected(session) == True:
             return jsonify({"error": "internal error"})
         models = Models()
         if models.account_exist(username):
             return jsonify({"error": "account already exists"})
         models.create_account(username, password)
         return jsonify({"result": "account created"})
     except:
         return jsonify({"error": "internal error"})
コード例 #10
0
ファイル: controller.py プロジェクト: Houssam-dev974/TEK1
 def mod_task(self, task_id, status):
     model = Models()
     # if (model.check_task_id_exist(task_id[0]) == False):
     #     return (jsonify(error="task id does not exist"))
     # try:
     #     model.modify_task(task_id[0], status)
     # except:
     #     return (jsonify(error="internal error"))
     return jsonify(result="update done")
コード例 #11
0
 def handle_signin(self, request):
     try:
         username = request.args["username"]
         password = request.args["password"]
         salt = "BEST_SALT" + username
         hash = hashlib.sha512()
         hash.update(salt.encode())
         hash.update(password.encode())
         password = hash.hexdigest()
         if self.is_connected(session) == True:
             return jsonify({"error": "internal error"})
         models = Models()
         if models.pwd_and_usr_match(username, password):
             session['logged_in'] = True
             session['username'] = username
             return jsonify({"result": "signin successful"})
         return jsonify({"error": "login or password does not match"})
     except:
         return jsonify({"error": "internal error"})
コード例 #12
0
 def handle_user_task_id_post(self, id, request):
     try:
         if "logged_in" not in session or session[
                 'logged_in'] != True or "username" not in session:
             return jsonify({"error": "you must be logged in"})
         models = Models()
         if not models.task_exist(id):
             return jsonify({"error": "task id does not exist"})
         if not self.user_has_task(id, session['username']):
             return jsonify({"error": "not your task lmao"})
         if "title" not in request.args or "begin" not in request.args or "end" not in request.args or "status" not in request.args:
             return jsonify({"error": "internal error"})
         title = request.args["title"]
         begin = request.args["begin"]
         end = request.args["end"]
         status = request.args["status"]
         models.update_task(id, title, begin, end, status)
         return jsonify({"result": "update done"})
     except:
         return jsonify({"error": "internal error"})
コード例 #13
0
ファイル: index.py プロジェクト: motomaniak/ecommerce-python
 def post(self):
     json_data = request.get_json(force=True)
     product_schema = ProductsSchema()
     product = Models.Products(name=json_data['name'],
                               description=json_data['description'],
                               image=json_data['image'],
                               quantity=json_data['quantity'],
                               price=json_data['price'],
                               category_id=json_data['category_id'])
     product.add()
     return product_schema.dump(product)
コード例 #14
0
 def handle_user_task_id_get(self, id):
     try:
         if "logged_in" not in session or session[
                 'logged_in'] != True or "username" not in session:
             return jsonify({"error": "you must be logged in"})
         models = Models()
         if not models.task_exist(id):
             return jsonify({"error": "task id does not exist"})
         if not self.user_has_task(id, session['username']):
             return jsonify({"error": "not your task lmao"})
         task = models.get_task_info(id)
         return jsonify({
             "result": {
                 "title": str(task[1]),
                 "begin": str(task[2]),
                 "end": str(task[3]),
                 "status": self.id_to_status(int(task[4]))
             }
         })
     except:
         return jsonify({"error": "internal error"})
コード例 #15
0
 def handle_user_task(self):
     try:
         if "logged_in" not in session or session[
                 'logged_in'] != True or "username" not in session:
             return jsonify({"error": "you must be logged in"})
         models = Models()
         tasks_id = []
         tasks = []
         for i in models.get_user_tasks(
                 models.get_usr_id(session["username"])[0][0]):
             tasks_id.append(i[1])
         for i in tasks_id:
             tmp = models.get_task_info(i)
             tasks.append({
                 str(i): {
                     "title": str(tmp[1]),
                     "begin": str(tmp[2]),
                     "end": str(tmp[3]),
                     "status": self.id_to_status(int(tmp[4]))
                 }
             })
         return jsonify({"result": {"tasks": tasks}})
     except:
         return jsonify({"error": "internal error"})
コード例 #16
0
 def handle_user_task_del(self, id):
     try:
         if "logged_in" not in session or session[
                 'logged_in'] != True or "username" not in session:
             return jsonify({"error": "you must be logged in"})
         models = Models()
         if not models.task_exist(id):
             return jsonify({"error": "task id does not exist"})
         if not self.user_has_task(id, session['username']):
             return jsonify({"error": "not your task lmao"})
         models.delete_task_link(id)
         models.delete_task(id)
         return jsonify({"result": "task deleted"})
     except:
         return jsonify({"error": "internal error"})
コード例 #17
0
 def handle_user_task_add(self, request):
     try:
         if "logged_in" not in session or session[
                 'logged_in'] != True or "username" not in session:
             return jsonify({"error": "you must be logged in"})
         models = Models()
         if "title" not in request.args or "begin" not in request.args or "end" not in request.args or "status" not in request.args:
             return jsonify({"error": "internal error"})
         title = request.args["title"]
         begin = request.args["begin"]
         end = request.args["end"]
         status = request.args["status"]
         id = models.add_task(title, begin, end, status)
         models.link_task_usr(id,
                              models.get_usr_id(session["username"])[0][0])
         return jsonify({"result": "new task added"})
     except:
         return jsonify({"error": "internal error"})
コード例 #18
0
        def get_auth_token():
            data = request.get_json()
            requiredParams = {'Account', 'Password'}
            if data.keys() & requiredParams != requiredParams:
                return make_result(code=Code.NOT_ENOUGH_PARAM)
            else:
                try:
                    user = Models.user.query.filter_by(
                        Account=data['Account'],
                        Password=data['Password']).first()
                    if user is None:
                        return make_result(code=Code.NO_DATA)
                    else:
                        user_agent = request.user_agent
                        status_data = {
                            'ip': request.remote_addr,
                            'msg': user_agent.string,
                            'platform': user_agent.platform,
                            'browser': user_agent.browser,
                            'version': user_agent.version,
                            'content': 'POST /login',
                            'Account': user.Account
                        }
                        status = Models.status(status_data)
                        db.session.add(status)
                        db.session.commit()

                        g.user = user
                        token = g.user.generate_auth_token()
                        result = {
                            'user': user.to_dict(),
                            'token': token.decode('ascii')
                        }
                        return make_result(code=Code.SUCCESS, data=result)
                except:
                    return make_result(code=Code.MYSQL_ERROR)
コード例 #19
0
ファイル: views.py プロジェクト: gitfiar/flaskapp
def add():
    if request.method == 'POST':
        form = AddForm()
        Model = Models(
            Name=request.form['Name'],
            Data=request.form['Data'],
            Slgon=request.form['Slgon'],
            Hometown=request.form['Hometown'],
            Job=request.form['Job'],
            Video=request.form['Video'],
            Pictures=request.form['Pictures'],
            Thumbnail=request.form['Thumbnail'],
        )
        try:
            db.session.add(Model)
            db.session.commit()
            print( 'add ok')
        except :
            db.session.rollback()
        db.session.close()
        return render_template('form.html',form=form )
    else:
        form = AddForm()
        return render_template('form.html',form=form )
コード例 #20
0
 def __init__(self, user_id):
     self.user_id = user_id
     self.username = None
     self.models = Models(user_id)
コード例 #21
0
from flask_api import FlaskAPI
from flask import request, jsonify
from app.models import Models

app = FlaskAPI(__name__)

models = Models()


@app.route('/api/v1/', methods=["GET"])
def index():
    message = {"My diary": {"Message": "Welcome to my diary"}}

    res = {"Message": message}
    return jsonify(res), 200


@app.route('/api/v1/entries', methods=["POST"])
def adding():
    """POST"""
    title = request.data.get('title', "")
    content = request.data.get('content', "")
    models.add(title, content)
    return jsonify({"title": title, "content": content}), 201


@app.route('/api/v1/entries', methods=["GET"])
def get_entries():
    """ALL ENTRIES"""
    entries_in_model = models.all_entries()
    return jsonify(models.all_entries()), 200
コード例 #22
0
 def __init__(self):
     model = Models()
     self.comics = model.comics
コード例 #23
0
ファイル: index.py プロジェクト: motomaniak/ecommerce-python
 def get(self, id):
     order_schema = Models.OrdersSchema(many=True)
     order = Models.OrderDetails.get(id)
     result = Models.OrderDetailsSchema(many=True).dump(order)
     return result
コード例 #24
0
ファイル: index.py プロジェクト: motomaniak/ecommerce-python
 def get(self, id):
     order_schema = Models.OrdersSchema(many=True)
     orders = Models.Orders.get(id)
     result = order_schema.dump(orders)
     return result
コード例 #25
0
 def __init__(self):
     model = Models()
     self.authors = model.authors
コード例 #26
0
 def user_has_task(self, id, username):
     models = Models()
     usr_id = models.get_usr_id(username)[0][0]
     return models.usr_has_task(usr_id, id)
コード例 #27
0
ファイル: index.py プロジェクト: motomaniak/ecommerce-python
 def get(self):
     customer_id = get_jwt_identity()
     cart_shema = Models.CartSchema()
     cart = Models.Orders.get_cart(customer_id)
     result = cart_shema.dump(cart)
     return result
コード例 #28
0
ファイル: index.py プロジェクト: motomaniak/ecommerce-python
 def get(self, id):
     reviews_schema = Models.ReviewsSchema(many=True)
     reviews = Models.Reviews.get_reviews_by_product(id)
     result = reviews_schema.dump(reviews)
     return result
コード例 #29
0
ファイル: controller.py プロジェクト: Houssam-dev974/TEK1
 def fetch_all_user_tasks(self, username):
     model = Models()
     result = model.all_tasks(username)
     return (result)
コード例 #30
0
ファイル: index.py プロジェクト: motomaniak/ecommerce-python
 def get(self):
     categories = Models.Categories.get_all()
     results = Models.CategoriesSchema(many=True).dump(categories)
     return results