Merge pull request 'Write survey data to backend (solves #70)' (#72) from feature/WriteSurveyToDatabase into main

Reviewed-on: #72
This commit is contained in:
cami 2021-06-28 00:22:12 +00:00
commit 10766dc601

View file

@ -17,6 +17,10 @@ class User(db.Model):
password = db.Column(db.Text)
roles = db.Column(db.Text)
is_active = db.Column(db.Boolean, default=True, server_default='true')
age = db.Column(db.Integer)
gender = db.Column(db.Text)
education = db.Column(db.Text)
skills = db.Column(db.Text)
@property
def rolenames(self):
@ -128,7 +132,8 @@ def protected():
A protected endpoint. The auth_required decorator will require a header
containing a valid JWT
.. example::
$ curl http://localhost:5000/api/protected -X GET \
$ curl http://
localhost:5000/api/protected -X GET \
-H "Authorization: Bearer <your_token>"
"""
return {'message': f'protected endpoint (allowed user {flask_praetorian.current_user().username})'}
@ -155,8 +160,22 @@ def register():
@flask_praetorian.auth_required
def survey():
req = flask.request.get_json(force=True)
token = guard.read_token_from_header()
extracted_token = guard.extract_jwt_token(token)
id_req = extracted_token['id']
# get data from the survey and write it to the database
age = req.get('age', None)
gender = req.get('gender', None)
print(req)
education = req.get('education', None)
skills = req.get('skills', None)
user_db = User.query.filter_by(id=id_req).first()
user_db.age = age
user_db.gender = gender
user_db.education = education
user_db.skills = skills
db.session.commit()
ret = {'message': 'Umfrage freigestellt'}
return ret, 200