@@ -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