def post(self): """Returns list of pending requests from the database""" if request.method == "POST": response_json = request.get_json() password = response_json["password"] if ApiManagerUtils.check_admin_pass(password): table = Requests() values = [] try: rows = table.query.filter_by().all() except SQLAlchemyError: return BARUtils.error_exit("Internal server error"), 500 [ values.append({ "first_name": row.first_name, "last_name": row.last_name, "email": row.email, "telephone": row.telephone, "contact_type": row.contact_type, "notes": row.notes, }) for row in rows ] return BARUtils.success_exit(values) else: return BARUtils.error_exit("Forbidden"), 403
def post(self): """Returns list of pending requests from the database """ if request.method == 'POST': response_json = request.get_json() password = response_json['password'] if ApiManagerUtils.check_admin_pass(password): table = Requests() values = [] try: rows = table.query.filter_by().all() except SQLAlchemyError: return BARUtils.error_exit('Internal server error'), 500 [ values.append({ 'first_name': row.first_name, 'last_name': row.last_name, 'email': row.email, 'telephone': row.telephone, 'contact_type': row.contact_type, 'notes': row.notes }) for row in rows ] return BARUtils.success_exit(values) else: return BARUtils.error_exit('Forbidden'), 403
def post(self): if request.method == 'POST': response_json = request.get_json() df = pandas.DataFrame.from_records([response_json]) con = db.get_engine(bind='summarization') try: reqs = Requests() users = Users() row_req = reqs.query.filter_by(email=df.email[0]).first() row_users = users.query.filter_by(email=df.email[0]).first() if row_req is None and row_users is None: df.to_sql('requests', con, if_exists='append', index=False) else: return BARUtils.error_exit('E-mail already in use'), 409 except SQLAlchemyError: return BARUtils.error_exit('Internal server error'), 500
def post(self): """Delete a request from the database""" if request.method == "POST": response_json = request.get_json() password = response_json["password"] if ApiManagerUtils.check_admin_pass(password): response_json = request.get_json() table = Requests() try: el = table.query.filter_by( email=response_json["email"]).one() except SQLAlchemyError: return BARUtils.error_exit("Internal server error"), 500 db.session.delete(el) db.session.commit() # table.query.filter_by(email=response_json['email']).delete() return BARUtils.success_exit(True) else: return BARUtils.error_exit("Forbidden"), 403
def post(self): """Approve a request from the database and add it to the Users table """ if request.method == 'POST': response_json = request.get_json() email = response_json['email'] password = response_json['password'] if ApiManagerUtils.check_admin_pass(password): table = Requests() values = [] try: rows = table.query.filter_by(email=email).all() except SQLAlchemyError: return BARUtils.error_exit('Internal server error'), 500 key = uuid.uuid4().hex [ values.append({ 'first_name': row.first_name, 'last_name': row.last_name, 'email': row.email, 'telephone': row.telephone, 'contact_type': row.contact_type, 'date_added': datetime.now(), 'status': 'user', 'api_key': key, 'uses_left': 25 }) for row in rows ] df = pandas.DataFrame.from_records([values[0]]) con = db.get_engine(bind='summarization') try: df.to_sql('users', con, if_exists='append', index=False) el = table.query.filter_by(email=email).one() db.session.delete(el) except SQLAlchemyError: return BARUtils.error_exit('Internal server error'), 500 return BARUtils.success_exit(key) else: return BARUtils.error_exit('Forbidden'), 403
def post(self): if request.method == "POST": response_json = request.get_json() df = pandas.DataFrame.from_records([response_json]) con = db.get_engine(bind="summarization") try: reqs = Requests() users = Users() row_req = reqs.query.filter_by(email=df.email[0]).first() row_users = users.query.filter_by(email=df.email[0]).first() if row_req is None and row_users is None: df.to_sql("requests", con, if_exists="append", index=False) if ApiManagerUtils.send_email(): return BARUtils.success_exit("Data added, email sent") else: return BARUtils.success_exit( "Data added, email failed") else: return BARUtils.error_exit("E-mail already in use"), 409 except SQLAlchemyError: return BARUtils.error_exit("Internal server error"), 500
def post(self): """Approve a request from the database and add it to the Users table""" if request.method == "POST": response_json = request.get_json() email = response_json["email"] password = response_json["password"] if ApiManagerUtils.check_admin_pass(password): table = Requests() values = [] try: rows = table.query.filter_by(email=email).all() except SQLAlchemyError: return BARUtils.error_exit("Internal server error"), 500 key = uuid.uuid4().hex [ values.append({ "first_name": row.first_name, "last_name": row.last_name, "email": row.email, "telephone": row.telephone, "contact_type": row.contact_type, "date_added": datetime.now(), "status": "user", "api_key": key, "uses_left": 25, }) for row in rows ] df = pandas.DataFrame.from_records([values[0]]) con = db.get_engine(bind="summarization") try: df.to_sql("users", con, if_exists="append", index=False) el = table.query.filter_by(email=email).one() db.session.delete(el) except SQLAlchemyError: return BARUtils.error_exit("Internal server error"), 500 return BARUtils.success_exit(key) else: return BARUtils.error_exit("Forbidden"), 403