Skip to content

Commit 51f48d1

Browse files
committed
Add email field to user model
1 parent 8e708de commit 51f48d1

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

lib/pbench/server/api/resources/db_models.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,16 @@ class UserModel(db.Model):
1414
lastName = db.Column(db.String(255), unique=False, nullable=False)
1515
password = db.Column(db.String(255), nullable=False)
1616
registered_on = db.Column(db.DateTime, nullable=False)
17-
# ToDo: decide if we want the email field
17+
email = db.Column(db.String(255), unique=False, nullable=False)
1818

19-
def __init__(self, username, firstName, lastName, password):
19+
def __init__(self, username, firstName, lastName, email, password):
2020
self.username = username
2121
self.firstName = firstName
2222
self.lastName = lastName
2323
self.password = bcrypt.generate_password_hash(
2424
password, app.config.get('BCRYPT_LOG_ROUNDS')
2525
).decode()
26+
self.email = email
2627
self.registered_on = datetime.datetime.now()
2728

2829
def __str__(self):

lib/pbench/server/api/resources/pbench_users.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,17 @@ class RegisterUser(Resource):
1414
def post(self):
1515
# get the post data
1616
post_data = request.get_json()
17-
# check if user already exists
18-
user = UserModel.query.filter_by(email=post_data.get('username')).first()
17+
# check if user already exist
18+
user = UserModel.query.filter_by(username=post_data.get('username')).first()
1919
if not user:
20+
2021
try:
2122
user = UserModel(
2223
username=post_data.get('username'),
2324
password=post_data.get('password'),
2425
firstName=post_data.get('firstName'),
2526
lastName=post_data.get('lastName'),
27+
email=post_data.get('email'),
2628
)
2729

2830
# insert the user
@@ -105,8 +107,8 @@ def post(self):
105107
if auth_header:
106108
auth_token = auth_header.split(" ")[1]
107109

108-
resp = UserModel.decode_auth_token(auth_token)
109-
if not isinstance(resp, str):
110+
user_id = UserModel.decode_auth_token(auth_token)
111+
if not isinstance(user_id, str):
110112
# Add the token to the blacklist
111113
blacklist.add(auth_token)
112114
response_object = {
@@ -118,7 +120,7 @@ def post(self):
118120
else:
119121
response_object = {
120122
'status': 'fail',
121-
'message': resp,
123+
'message': user_id,
122124
'status_code': 401
123125
}
124126
return make_response(jsonify(response_object))
@@ -154,9 +156,9 @@ def get(self):
154156
return make_response(jsonify(response_object))
155157

156158
if auth_token:
157-
resp = UserModel.decode_auth_token(auth_token)
158-
if not isinstance(resp, str):
159-
user = UserModel.query.filter_by(id=resp).first()
159+
user_id = UserModel.decode_auth_token(auth_token)
160+
if not isinstance(user_id, str):
161+
user = UserModel.query.filter_by(id=user_id).first()
160162
response_object = {
161163
'status': 'success',
162164
'data': {
@@ -169,7 +171,7 @@ def get(self):
169171
return make_response(jsonify(response_object))
170172
response_object = {
171173
'status': 'fail',
172-
'message': resp,
174+
'message': user_id,
173175
'status_code': 403
174176
}
175177
return make_response(jsonify(response_object))

0 commit comments

Comments
 (0)