Merge pull request 'Write survey data to backend (solves #70)' (#72) from feature/WriteSurveyToDatabase into main
Reviewed-on: #72
This commit is contained in:
commit
10766dc601
1 changed files with 21 additions and 2 deletions
|
@ -17,6 +17,10 @@ class User(db.Model):
|
||||||
password = db.Column(db.Text)
|
password = db.Column(db.Text)
|
||||||
roles = db.Column(db.Text)
|
roles = db.Column(db.Text)
|
||||||
is_active = db.Column(db.Boolean, default=True, server_default='true')
|
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
|
@property
|
||||||
def rolenames(self):
|
def rolenames(self):
|
||||||
|
@ -128,7 +132,8 @@ def protected():
|
||||||
A protected endpoint. The auth_required decorator will require a header
|
A protected endpoint. The auth_required decorator will require a header
|
||||||
containing a valid JWT
|
containing a valid JWT
|
||||||
.. example::
|
.. example::
|
||||||
$ curl http://localhost:5000/api/protected -X GET \
|
$ curl http://
|
||||||
|
localhost:5000/api/protected -X GET \
|
||||||
-H "Authorization: Bearer <your_token>"
|
-H "Authorization: Bearer <your_token>"
|
||||||
"""
|
"""
|
||||||
return {'message': f'protected endpoint (allowed user {flask_praetorian.current_user().username})'}
|
return {'message': f'protected endpoint (allowed user {flask_praetorian.current_user().username})'}
|
||||||
|
@ -155,8 +160,22 @@ def register():
|
||||||
@flask_praetorian.auth_required
|
@flask_praetorian.auth_required
|
||||||
def survey():
|
def survey():
|
||||||
req = flask.request.get_json(force=True)
|
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)
|
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'}
|
ret = {'message': 'Umfrage freigestellt'}
|
||||||
return ret, 200
|
return ret, 200
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue