added unique id
Browse files- ChitChat/common/utils.py +1 -1
- ChitChat/models.py +2 -0
- ChitChat/resources/routes.py +4 -4
- instance/site.db +0 -0
ChitChat/common/utils.py
CHANGED
@@ -20,7 +20,7 @@ def getChatHistory(user):
|
|
20 |
|
21 |
def saveChatHistory(user, chat_history_ids):
|
22 |
location = current_app.config.get('SAVE_FOLDER')
|
23 |
-
file_name = location +
|
24 |
if chat_history_ids.shape[-1] > 100:
|
25 |
user.history = None
|
26 |
db.session.commit()
|
|
|
20 |
|
21 |
def saveChatHistory(user, chat_history_ids):
|
22 |
location = current_app.config.get('SAVE_FOLDER')
|
23 |
+
file_name = location + user.user_id + '.pt'
|
24 |
if chat_history_ids.shape[-1] > 100:
|
25 |
user.history = None
|
26 |
db.session.commit()
|
ChitChat/models.py
CHANGED
@@ -1,8 +1,10 @@
|
|
1 |
from ChitChat import db
|
2 |
from datetime import datetime
|
|
|
3 |
|
4 |
class ChatHistory(db.Model):
|
5 |
id = db.Column(db.Integer, primary_key = True)
|
|
|
6 |
username = db.Column(db.String(10), unique = True, nullable = False)
|
7 |
email = db.Column(db.String(100), nullable = False)
|
8 |
password = db.Column(db.String(60), nullable = False)
|
|
|
1 |
from ChitChat import db
|
2 |
from datetime import datetime
|
3 |
+
import uuid
|
4 |
|
5 |
class ChatHistory(db.Model):
|
6 |
id = db.Column(db.Integer, primary_key = True)
|
7 |
+
user_id = db.Column(db.String(), unique = True, nullable = False, default = str(uuid.uuid4()))
|
8 |
username = db.Column(db.String(10), unique = True, nullable = False)
|
9 |
email = db.Column(db.String(100), nullable = False)
|
10 |
password = db.Column(db.String(60), nullable = False)
|
ChitChat/resources/routes.py
CHANGED
@@ -16,11 +16,11 @@ class UserLogin(Resource):
|
|
16 |
user = ChatHistory.query.filter_by(email = userInfo['email']).first()
|
17 |
|
18 |
if user is None:
|
19 |
-
return {'status' : "Account doesn't exist", 'user_id' :
|
20 |
elif bcrypt.check_password_hash(pw_hash = user.password, password = userInfo['password']):
|
21 |
-
return {'status' : "login successful", 'user_id' : user.
|
22 |
else:
|
23 |
-
return {'status' : "Invalid password", 'user_id' :
|
24 |
api.add_resource(UserLogin, '/login/')
|
25 |
|
26 |
class RegisterUser(Resource):
|
@@ -43,7 +43,7 @@ api.add_resource(RegisterUser, '/register/')
|
|
43 |
|
44 |
class ChatBot(Resource):
|
45 |
def post(self, user_id):
|
46 |
-
user = ChatHistory.query.filter_by(
|
47 |
userInput = request.json['user']
|
48 |
if user is None:
|
49 |
return {'error' : "User doesn't exist"}, 400
|
|
|
16 |
user = ChatHistory.query.filter_by(email = userInfo['email']).first()
|
17 |
|
18 |
if user is None:
|
19 |
+
return {'status' : "Account doesn't exist", 'user_id' : None}
|
20 |
elif bcrypt.check_password_hash(pw_hash = user.password, password = userInfo['password']):
|
21 |
+
return {'status' : "login successful", 'user_id' : user.user_id}
|
22 |
else:
|
23 |
+
return {'status' : "Invalid password", 'user_id' : None}
|
24 |
api.add_resource(UserLogin, '/login/')
|
25 |
|
26 |
class RegisterUser(Resource):
|
|
|
43 |
|
44 |
class ChatBot(Resource):
|
45 |
def post(self, user_id):
|
46 |
+
user = ChatHistory.query.filter_by(user_id = user_id).first()
|
47 |
userInput = request.json['user']
|
48 |
if user is None:
|
49 |
return {'error' : "User doesn't exist"}, 400
|
instance/site.db
CHANGED
Binary files a/instance/site.db and b/instance/site.db differ
|
|