Skip to content

Commit

Permalink
linted
Browse files Browse the repository at this point in the history
  • Loading branch information
jason490 committed Aug 1, 2024
1 parent 54f74dd commit 29e5914
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 20 deletions.
32 changes: 21 additions & 11 deletions api/pollination/files.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# flake8: noqa
# pylint: skip-file
'''
Contains the table representations of the database
Contains the File class and routes
'''
import random
import string
from pollination import db

import os
import sys
Expand All @@ -13,7 +14,7 @@
from io import BytesIO
from flask import request, jsonify, send_from_directory
from flask_login import current_user, login_required
from pollination import app
from pollination import app, db
from pollination.user import User


Expand All @@ -36,20 +37,26 @@ class File(db.Model):
file_name = db.Column(db.Text)
user = db.Relationship('User', back_populates='file')

@app.route('/api/image/process', methods=['POST'])
@app.route('/api/image/delete', methods=['POST'])
@login_required
def process():
file = request.files['image']
if file.filename == "":
return jsonify({"Invalid": "Please have a filename"})
def delete():
'''
Deletes the image
'''
data = request.json

if (data is None):
return jsonify({"Invalid": "No data sent"})

db.session.scalars(db.select(File).filter_by(alt_id=data.get("id")))

return jsonify({"Success": "Deleted file"})

@app.route('/api/image/upload', methods=['POST'])
@login_required
def upload():
'''
Saves the image to a file and runs the image
ADD MAX IMAGE SIZE
ADD extension type
'''
image_data = re.sub('^data:image/.+;base64,', '', request.data.decode('utf-8'))
im = Image.open(BytesIO(base64.b64decode(image_data)))
Expand All @@ -70,7 +77,7 @@ def upload():

@app.route('/api/image/get/<search_query>', methods=['GET'])
@login_required
def pls(search_query):
def get_image(search_query):
'''
Sends user images not working
'''
Expand Down Expand Up @@ -101,5 +108,8 @@ def get_all():
return jsonify({"Success": "worked", "data": data})

def __repr__(self):
'''
formats the File class when printing
'''
return f"File('{self.location}', '{self.bug_name}', \
'{self.file_name}')"
21 changes: 12 additions & 9 deletions api/pollination/user.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# flake8: noqa
# pylint: skip-file
'''
Contains the table representations of the database
Contains the user class and routes
'''
from uuid import uuid4
from flask_login import UserMixin
from pollination import db
from pollination import login_manager

from flask import request, jsonify
from flask_login import login_user, current_user, logout_user
from flask_login import login_required
from pollination import app, bcrypt
from pollination import app, bcrypt, db
from pollination import login_manager


@login_manager.user_loader
Expand Down Expand Up @@ -57,13 +57,15 @@ def register():
if (data.get('password') is None):
return jsonify({"Invalid": "Incorrect username or password"}), 401

user = db.session.scalars(db.select(User).filter_by(username=data['username'])).first()
user = db.session.scalars(db.select(User).filter_by(
username=data['username'])).first()

if (user is not None):
return jsonify({"Invalid": "Username already exists"})

# Create the User
pw_hash = bcrypt.generate_password_hash(data['password']).decode('utf-8')
pw_hash = bcrypt.generate_password_hash(
data['password']).decode('utf-8')
user = User(username=data['username'], password=pw_hash)
db.session.add(user)
db.session.commit()
Expand All @@ -85,14 +87,15 @@ def login():
return jsonify({"Invalid": "Incorrect username or password"}), 401

user: User = db.session.scalars(db.select(User)
.filter_by(username=data['username'])).first()
.filter_by(username=data['username'])).first()

if (user is None or user.password is None):
# save value as a cookie
return jsonify({"Invalid": "Incorrect username or password"}), 401
# return "Invalid"

pass_check = bcrypt.check_password_hash(user.password, data['password'])
pass_check = bcrypt.check_password_hash(
user.password, data['password'])
if (pass_check is False):
return jsonify({"Invalid": "Incorrect username or password"}), 401
# return "Invalid"
Expand Down

0 comments on commit 29e5914

Please sign in to comment.