Compare commits

..

No commits in common. "eb074e5dd5f3290419c1c7f7d5070ef4538efc69" and "dae0ce21be6ed04ad5ef2f1010dcff80fef3f9e3" have entirely different histories.

7 changed files with 3 additions and 51 deletions

0
app.py Normal file
View File

View File

@ -1,2 +0,0 @@
import views

0
app/init.py Normal file
View File

View File

@ -64,7 +64,6 @@
data: data.field, // 表单数据 data: data.field, // 表单数据
dataType: 'json', dataType: 'json',
success: function (response) { success: function (response) {
console.log(response)
if (response.success) { if (response.success) {
window.location.href = '/attendance-reminder'; // 或者你的成功页面 window.location.href = '/attendance-reminder'; // 或者你的成功页面
} else { } else {

View File

@ -1,45 +0,0 @@
import unittest
from app.views import *
from db.database_manager import DatabaseManager # 确保你可以导入DatabaseManager
class LoginTestCase(unittest.TestCase):
def setUp(self):
# 设置 Flask 测试模式
app.testing = True
self.client = app.test_client()
def test_login_get(self):
# 测试 GET 请求返回登录页面
response = self.client.get('/login')
self.assertEqual(response.status_code, 200)
self.assertIn('text/html', response.content_type)
def test_successful_login_post(self):
# 测试有效的登录 POST 请求
with self.client:
response = self.client.post('/login', data={
'number': 'G0001',
'password': '1'
})
# 根据你的应用逻辑调整断言
self.assertEqual(response.status_code, 200)
def test_invalid_login_post(self):
# 测试无效的登录 POST 请求
response = self.client.post('/login', data={
'number': 'admin',
'password': 'admin'
})
# 将返回的数据解析为JSON
json_data = response.get_json()
# 确认JSON响应中的值
self.assertEqual(response.status_code, 200)
self.assertFalse(json_data['success'])
self.assertEqual(json_data['message'], "无效的用户名或密码")
# 运行测试
if __name__ == '__main__':
unittest.main()

View File

@ -97,7 +97,7 @@ def login():
session['role'] = check_identity(number) session['role'] = check_identity(number)
session['name'] = result['name'] session['name'] = result['name']
return jsonify(success=True, message="登录成功") return jsonify(success=True, message="登录成功")
elif not result.get('status'): elif not result['status']:
# 用户被禁用的情况 # 用户被禁用的情况
return jsonify(success=False, message="账户已被禁用") return jsonify(success=False, message="账户已被禁用")
else: else:

View File

@ -77,7 +77,7 @@ class DatabaseManager:
return {'valid': True, 'status': status, 'name': name} return {'valid': True, 'status': status, 'name': name}
# 密码不匹配或用户不存在,返回登录失败 # 密码不匹配或用户不存在,返回登录失败
return {'valid': False, 'status': True} return {'valid': False}
def get_menu(self, role): def get_menu(self, role):
sql = "SELECT menu_name,path FROM menu_items WHERE role=%s ORDER BY `order`" sql = "SELECT menu_name,path FROM menu_items WHERE role=%s ORDER BY `order`"