diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml
new file mode 100644
index 0000000..a55e7a1
--- /dev/null
+++ b/.idea/codeStyles/codeStyleConfig.xml
@@ -0,0 +1,5 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/main/__pycache__/mysql.cpython-310.pyc b/main/__pycache__/mysql.cpython-310.pyc
index 5675076..4c74144 100644
Binary files a/main/__pycache__/mysql.cpython-310.pyc and b/main/__pycache__/mysql.cpython-310.pyc differ
diff --git a/main/__pycache__/mysql.cpython-311.pyc b/main/__pycache__/mysql.cpython-311.pyc
index b66d6da..875b008 100644
Binary files a/main/__pycache__/mysql.cpython-311.pyc and b/main/__pycache__/mysql.cpython-311.pyc differ
diff --git a/main/client/Client.py b/main/client/Client.py
index d06561f..1614898 100644
--- a/main/client/Client.py
+++ b/main/client/Client.py
@@ -305,7 +305,7 @@ def reset_password(self, answer, new_password):
####################################################################
def main():
- SendMessage("1234","1234")
+ SecurityQuestion(userName="2222",question='1',answer='1',new_password='1234')
diff --git a/main/mysql.py b/main/mysql.py
index 3bead31..251a27c 100644
--- a/main/mysql.py
+++ b/main/mysql.py
@@ -217,7 +217,7 @@ def set_security_question(user_name, question, answer):
return False
@staticmethod
- def verify_security_answer(user_name, answer, new_password):
+ def verify_security_answer(user_name,answer, new_password):
try:
user = UserModel.get(UserModel.name == user_name)
security_question = SecurityQuestionModel.get(SecurityQuestionModel.user_id == user.id)
diff --git a/main/server/Server.py b/main/server/Server.py
index 6a05722..b39b420 100644
--- a/main/server/Server.py
+++ b/main/server/Server.py
@@ -195,8 +195,10 @@ def on_message(self, client, userdata, msg):
success = SecurityQuestionManage.set_security_question(user_name, question, answer)
if success == True:
code = 1
+ print("密保保存成功")
else:
code = 0
+ print("密保保存失败")
data = {
'action': 'set_question',
'code': code
@@ -218,11 +220,17 @@ def on_message(self, client, userdata, msg):
elif msg.topic == 'verify_security_answer':
user_name = data.get('userName')
answer = data.get('answer')
- newPassword = data.get('new_password')
+ newPassword = data.get('newPassword')
returnTopic = data.get('returnTopic')
- success = SecurityQuestionManage.verify_security_answer(user_name, answer, newPassword)
- if success: code = 1
- else: code = 0
+
+ print(user_name,"密码"+newPassword)
+ success = SecurityQuestionManage.verify_security_answer(user_name,answer, newPassword)
+ if success:
+ code = 1
+ print("密保验证成功")
+ else:
+ code = 0
+ print("密保验证失败")
data = {
'action': 'verify_security_answer',
'code': code
@@ -297,5 +305,6 @@ def main():
c=Like() #进程3,处理点赞
d=ChatAll() #进程4,处理所有消息
e=ChatSave() #进程5,处理消息保存
+ f=SecurityServer()
main()
\ No newline at end of file
diff --git a/su/myproject/mqtt/__pycache__/forms.cpython-310.pyc b/su/myproject/mqtt/__pycache__/forms.cpython-310.pyc
index 4b8882b..8a54ae5 100644
Binary files a/su/myproject/mqtt/__pycache__/forms.cpython-310.pyc and b/su/myproject/mqtt/__pycache__/forms.cpython-310.pyc differ
diff --git a/su/myproject/mqtt/__pycache__/views.cpython-310.pyc b/su/myproject/mqtt/__pycache__/views.cpython-310.pyc
index f92c3c8..f434946 100644
Binary files a/su/myproject/mqtt/__pycache__/views.cpython-310.pyc and b/su/myproject/mqtt/__pycache__/views.cpython-310.pyc differ
diff --git a/su/myproject/mqtt/client/Client.py b/su/myproject/mqtt/client/Client.py
index 50f590a..4613a96 100644
--- a/su/myproject/mqtt/client/Client.py
+++ b/su/myproject/mqtt/client/Client.py
@@ -159,6 +159,7 @@ def on_message(self, client, userdata, msg): # 接受数据
messages = eval(msg.payload.decode('utf-8'))
# 读取数据
self.messages=messages #返回一个字典的列表,['id':id,'senderID':senderID,'message':message]存到类中
+ print(messages)
def publishGetAllMessage(self):
@@ -241,6 +242,10 @@ def __init__(self, userName, question=None, answer=None, new_password=None):
self.question = question
self.answer = answer
self.clientStart()
+ self.rightQuestion=None
+ self.request_security_question()
+ time.sleep(1)
+ self.flag=False
if userName and question and answer and new_password:
self.reset_password(answer,new_password)
elif userName and question and answer:
@@ -262,9 +267,14 @@ def on_message(self, client, userdata, msg):
if data.get('action') == 'set_question':
print(data.get('code'))
elif data.get('action') == 'request_question':
+ self.rightQuestion=data.get('question')
print(f"Security Question: {data.get('question')}")
elif data.get('action') == 'verify_security_answer':
- print(data.get('code'))
+ if data.get('code')==1:
+ self.flag=True
+ print(f"密保验证成功,密码重制成功")
+ else:
+ print(f"密保验证失败")
return data
def set_security_question(self):
@@ -290,6 +300,9 @@ def request_security_question(self):
print(f'发布信息到 request_security_question 成功')
def reset_password(self, answer, new_password):
+ if self.rightQuestion!=self.question:
+ print("密保问题错误")
+ return
returnTopic = self.userName + "security"
data = {
'action': 'reset_password',
diff --git a/su/myproject/mqtt/client/__pycache__/Client.cpython-310.pyc b/su/myproject/mqtt/client/__pycache__/Client.cpython-310.pyc
index b36e243..24135d9 100644
Binary files a/su/myproject/mqtt/client/__pycache__/Client.cpython-310.pyc and b/su/myproject/mqtt/client/__pycache__/Client.cpython-310.pyc differ
diff --git a/su/myproject/mqtt/forms.py b/su/myproject/mqtt/forms.py
index 332da0e..53971af 100644
--- a/su/myproject/mqtt/forms.py
+++ b/su/myproject/mqtt/forms.py
@@ -5,4 +5,10 @@
class UserForm(forms.Form):
username = forms.CharField(max_length=100)
password = forms.CharField(widget=forms.PasswordInput)
- confirm_password = forms.CharField(widget=forms.PasswordInput, required=False)
\ No newline at end of file
+ confirm_password = forms.CharField(widget=forms.PasswordInput, required=False)
+
+class ForgetPasswordForm(forms.Form):
+ username = forms.CharField(max_length=150, required=True, widget=forms.TextInput(attrs={'placeholder': '用户名'}))
+ question = forms.CharField(max_length=255, required=True, widget=forms.TextInput(attrs={'placeholder': '密保问题'}))
+ answer = forms.CharField(max_length=255, required=True, widget=forms.TextInput(attrs={'placeholder': '密保答案'}))
+ password = forms.CharField(max_length=128, required=True, widget=forms.PasswordInput(attrs={'placeholder': '要重置的密码'}))
\ No newline at end of file
diff --git a/su/myproject/mqtt/views.py b/su/myproject/mqtt/views.py
index d2f3c51..0bdc8e2 100644
--- a/su/myproject/mqtt/views.py
+++ b/su/myproject/mqtt/views.py
@@ -72,7 +72,7 @@ def register(request):
#chat
def chat(request):
- username = u.userName # 从session中获取username
+ username = u.userName
if username:
messages.info(request, f"欢迎回来 {username} (●’◡’●)")
return render(request, 'chat.html')
@@ -105,4 +105,42 @@ def sendchat(request):
return JsonResponse({'status': 'success','message': '发送成功'})
return JsonResponse({'status': 'failed'})
+def setquestion(request):
+ if request.method == 'POST':
+ data = json.loads(request.body)
+ question = data.get('question')
+ answer = data.get('answer')
+ userName=u.userName
+ print("u.userName:"+u.userName)
+ print(question)
+ print(answer)
+ SecurityQuestion(u.userName,question=question,answer=answer)
+ time.sleep(2)
+ return JsonResponse({'status': 'success','message': '密保设置成功'})
+ return JsonResponse({'status': 'failed'})
+
+from .forms import ForgetPasswordForm
+
+def forgetpassword(request):
+ if request.method == 'POST':
+ form = ForgetPasswordForm(request.POST)
+ if form.is_valid():
+ username = form.cleaned_data['username']
+ question = form.cleaned_data['question']
+ answer = form.cleaned_data['answer']
+ password = form.cleaned_data['password']
+
+ s=SecurityQuestion(userName=username,question=question,answer=answer,new_password=password)
+ time.sleep(2)
+ if s.flag:
+ messages.error(request, '密码重置成功')
+ return redirect('login')
+ else:
+ messages.error(request, '用户名或密保错误或未设置密保,请重试')
+ return redirect('forgetpassword')
+
+
+ else:
+ form = ForgetPasswordForm()
+ return render(request, 'forgetpassword.html', {'form': form})
\ No newline at end of file
diff --git a/su/myproject/myproject/__pycache__/urls.cpython-310.pyc b/su/myproject/myproject/__pycache__/urls.cpython-310.pyc
index 47af138..3b09b60 100644
Binary files a/su/myproject/myproject/__pycache__/urls.cpython-310.pyc and b/su/myproject/myproject/__pycache__/urls.cpython-310.pyc differ
diff --git a/su/myproject/myproject/urls.py b/su/myproject/myproject/urls.py
index 73c3dc6..4b4033a 100644
--- a/su/myproject/myproject/urls.py
+++ b/su/myproject/myproject/urls.py
@@ -24,5 +24,7 @@
path('register/', views.register, name='register'),
path('getchats/', views.getchats, name='getchats'),
path('sendchat/', views.sendchat, name='sendchat'),
+ path('setquestion/', views.setquestion, name='setquestion'),
+ path('forgetpassword/',views.forgetpassword,name='forgetpassword')
]
diff --git a/su/myproject/templates/chat.html b/su/myproject/templates/chat.html
index c780c79..e716436 100644
--- a/su/myproject/templates/chat.html
+++ b/su/myproject/templates/chat.html
@@ -17,26 +17,46 @@
+
+
{% if messages %}
{% for message in messages %}
- - {{ message }}
+ -
+ {{ message }}
+
{% endfor %}
+
设置密保
{% endif %}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
WELCOME
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/su/myproject/templates/forgetpassword.html b/su/myproject/templates/forgetpassword.html
new file mode 100644
index 0000000..954d9c2
--- /dev/null
+++ b/su/myproject/templates/forgetpassword.html
@@ -0,0 +1,131 @@
+
+
+
+