Skip to content
Snippets Groups Projects
Commit dc9177c2 authored by Eirik Martin Danielsen's avatar Eirik Martin Danielsen :speech_balloon:
Browse files

Merge branch '35-remove-dead-code-and-cleanup' of...

Merge branch '35-remove-dead-code-and-cleanup' of https://git.gvk.idi.ntnu.no/HermanDyrkorn/salamander-api into 35-remove-dead-code-and-cleanup

merging
parents 1be4b471 8e2a41b0
Branches
No related tags found
1 merge request!38Resolve "remove dead code and cleanup"
......@@ -14,11 +14,10 @@ LONGITUDE_REGEX = "^(\\+|-)?(?:180(?:(?:\\.0{1,6})?)|(?:[0-9]|[1-9][0-9]|1[0-7][
# location endpoint
class LocationEndpoint(Resource):
decorators = [limiter.limit("10/minute")]
decorators = [limiter.limit("60/minute")]
@staticmethod
@jwt_required
@limiter.limit("10/minute")
def post():
data = request.form
if "name" in data and "radius" in data and "latitude" in data and "longitude" in data:
......
......@@ -27,6 +27,6 @@ class Login(Resource):
else:
return jsonify({'message': 'not accepted by admin', 'status': 400})
else:
return jsonify({'message': 'login failed, wrong email or password', 'status': 200})
return jsonify({'message': 'login failed, wrong email or password', 'status': 400})
else:
return jsonify({"message": "data provided was incorrect", 'status': 200})
return jsonify({"message": "data provided was incorrect", 'status': 400})
......@@ -24,6 +24,7 @@ class AdminManageUser(Resource):
return jsonify({"users": user_list, "status": 200})
else:
return jsonify({"message": "no access", "status": 400})
@staticmethod
@jwt_required
def post():
......@@ -57,16 +58,17 @@ class AdminManageUser(Resource):
@staticmethod
@jwt_required
def put():
data = request.form
user_id = get_jwt_identity()
user = db.session.query(User).filter_by(id=user_id).first()
if user.admin:
if "id" in data and user_id != data['id']:
user = db.session.query(User).filter_by(id=data['id']).first()
new_pasword = get_random_string(5)
password_hash = bcrypt.generate_password_hash(new_pasword)
new_password = get_random_string(5)
password_hash = bcrypt.generate_password_hash(new_password)
user.pwd = password_hash
db.session.commit()
return jsonify({"new_password": new_pasword, "status": 200})
return jsonify({"new_password": new_password, "status": 200})
else:
return jsonify({"message": "wrong data", "status": 400})
......
......@@ -6,7 +6,7 @@ from flask_jwt_extended import get_jwt_identity, jwt_required
class AdminPendingUsers(Resource):
decorators = [limiter.limit("30/minute")]
decorators = [limiter.limit("60/minute")]
@staticmethod
@jwt_required
......
......@@ -10,7 +10,7 @@ from image_encoder.image_encoder import *
# get all images on a specific salamander based on id
class SalamanderEndpoint(Resource):
decorators = [limiter.limit("5/minute")]
decorators = [limiter.limit("60/minute")]
@staticmethod
@jwt_required
......
......@@ -11,7 +11,7 @@ from shutil import move
class SalamanderClass(Resource):
decorators = [limiter.limit("10/minute")]
decorators = [limiter.limit("60/minute")]
@staticmethod
@jwt_required
......
......@@ -10,7 +10,7 @@ from image_encoder.image_encoder import *
# get one specific image on a specific salamander based on s_id and i_id
class SalamanderImageEndpoint(Resource):
decorators = [limiter.limit("5/minute")]
decorators = [limiter.limit("60/minute")]
@staticmethod
@jwt_required
......
......@@ -7,7 +7,7 @@ from api.models.dbmodels import Location, User, Salamander, SalamanderGrowth
# get all salamanders on a specific location
class SalamandersEndpoint(Resource):
decorators = [limiter.limit("5/minute")]
decorators = [limiter.limit("60/minute")]
@staticmethod
@jwt_required
......@@ -21,8 +21,10 @@ class SalamandersEndpoint(Resource):
if salamanders:
salamander_list = []
for salamander in salamanders:
growth = db.session.query(SalamanderGrowth).filter_by(salamander_id=salamander.id).all()
ret = {"id": salamander.id, "sex": salamander.sex, "individuals": len(growth), "species": salamander.species, "date": salamander.last_date}
number_of_images = db.session.query(SalamanderGrowth).filter_by(salamander_id=salamander.id).all()
last_date = db.session.query(SalamanderGrowth).filter_by(salamander_id=salamander.id).order_by(SalamanderGrowth.date.desc()).first()
print(last_date)
ret = {"id": salamander.id, "sex": salamander.sex, "individuals": len(number_of_images), "species": salamander.species, "date": last_date.date}
salamander_list.append(ret)
return jsonify({"salamanders": salamander_list, 'status': 200})
else:
......
......@@ -10,7 +10,7 @@ EMAIL_REGEX = "^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$"
class UserEndpoint(Resource):
decorators = [limiter.limit("3/minute")]
decorators = [limiter.limit("30/minute")]
@staticmethod
def post():
......
......@@ -6,7 +6,7 @@ from api.models.dbmodels import User
class VerifyPassword(Resource):
decorators = [limiter.limit("10/minute")]
decorators = [limiter.limit("30/minute")]
@staticmethod
@jwt_required
......
......@@ -18,7 +18,6 @@ class Salamander(db.Model):
location_id = db.Column(db.Integer, db.ForeignKey('location.id'), nullable=False)
uid = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
first_date = db.Column(db.DateTime, default=datetime.now)
last_date = db.Column(db.DateTime, default=datetime.now)
class Location(db.Model):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment