更新登录

This commit is contained in:
RainSun 2021-02-08 21:09:02 +08:00
parent 3c99c1bf78
commit d79dec478b
10 changed files with 169 additions and 10 deletions

@ -73,14 +73,23 @@ deactivate
* [ ] 提供每个用户组下的个人课表以及个人总体课表
* [ ] 允许设置组级别的课程(全组个人课表及组课表可见)
* [ ] 数据库按课程存储字段sid, real_name, course, weeks, weeks_split, teacher, room, is_personal, day, period
* [ ] 登录的时候返回所有必要信息,剩下信息单独返回
* [ ] 组信息
* [ ] 刷新课表使用cookie加速
* [ ] 刷新成绩(使用账号密码
## 背景图片上传
* [ ] 上传图片id保存在数据库和个人信息一起
## 数据库字段
## log
* time
* type
* value
### config
* key
* value
### user
* uid 用户唯一识别码,教务下发
* invite_list 邀请内容
* cid 一卡通号
* sid 学号
@ -138,6 +147,7 @@ userInsertCrouse '用户自定义课程数据库插入失败', 107
userInsertAllCrouse '用户所有课程数据库插入失败', 108
insertRank '排名表数据库插入失败', 109
groupInsertCrouse '用户组课程数据库插入失败', 110
insertLog '系统操作记录数据库插入失败', 111
### find 3
findCookie 'cookie数据库查询失败', 300
findUser '学生信息数据库查询失败', 301
@ -145,6 +155,7 @@ findGroup '用户组信息数据库查询失败', 302
findRank '排名表数据库查询失败', 303
findUserCrouse '用户课程数据库查询失败', 304
findGroupCrouse '用户组课程数据库查询失败', 305
findLog '系统操作记录数据库查询失败', 306
### update 4
updateCookie 'cookie数据库更新失败', 400
updateAvatar '头像数据库更新失败', 401
@ -156,4 +167,14 @@ userDeleteAllCrouse '用户所有课程数据库删除失败', 502
groupDeleteAdmin '用户组侧移除管理数据库删除失败', 503
deleteGroup '解散用户组数据库删除失败', 504
userDeleteCrouse '用户自定义课程数据库删除失败', 505
groupDeleteCrouse '用户组课程数据库删除失败', 506
groupDeleteCrouse '用户组课程数据库删除失败', 506
## 接口错误代码
### /login
400 数据不合法
510 学生信息数据库查询失败
511 账号或密码错误
512 用户组信息数据库查询失败
513 请填写手机号
514 教务返回的错误
515 教务挂了

0
lib/functions.py Normal file

0
lib/process/__init__.py Normal file

101
lib/process/login.py Normal file

@ -0,0 +1,101 @@
from ..public.db import findUser
from ..public.utils import checkData, signCode, findGroup
from ..public.crawler import Crawler
import json
def check(request):
"""
校验数据
目标内容 cid,pwd,phone
"""
try:
data = request.json
if not checkData(data):
raise Exception
if not data.__contains__('cid'):
raise Exception
if not data.__contains__('pwd'):
raise Exception
return data, 200
except Exception as e:
print(e)
return '数据不合法', 400
def manageLogin(request):
"""
用户登录
"""
# 校验数据
check_res = check(request)
# 抛出错误
if check_res[-1] != 200:
return check_res
data = check_res[0]
# 查找用户
find_res = findUser(data['cid'])
# 抛出错误
if find_res[-1] != 200:
return find_res[0], 510
user_info = find_res[0]
# 无用户进行注册
if not user_info:
return sign(data['cid'], data['pwd'])
# 校验密码
if user_info['pwd'] != signCode(data['pwd']):
return '账号或密码错误', 511
# 接下来需要返回组信息,课表信息以及成绩信息
# 组信息
find_res = manageFindGroup(user_info['group_list'])
if find_res[-1] != 200:
return find_res
user_info['group_list'] = find_res[0]
# 课表信息以及成绩信息
crawler_res = manageCrawler(user_info['cid'], user_info['pwd'], user_info.get('phone'))
if crawler_res[-1] != 200:
return crawler_res
def manageFindGroup(group_list):
"""
根据组id查询组信息
"""
list = []
for group_id in group_list:
find_res = findGroup(group_id)
if find_res[-1] != 200:
return find_res[0], 512
list.append(find_res[0])
return list, 200
def manageCrawler(cid, pwd, phone):
"""
处理爬虫返回课表和成绩
"""
try:
c = Crawler()
init_res = c.defaultInit(cid, pwd, phone)
if init_res[-1] != 200:
return init_res
get_res = c.getOwnSchedule()
if get_res[-1] != 200:
return get_res
schedule = get_res[0]
get_res = c.getGrade()
if get_res[-1] != 200:
return get_res
grade = get_res[0]
return {
'grade': grade,
'schedule': schedule,
}, 200
except Exception as e:
print(e)
return '教务挂了', 515
def manageSign(cid, pwd, phone):
"""
用户注册
"""
pass

0
lib/public/__init__.py Normal file

@ -48,7 +48,7 @@ class Crawler(object):
flag = soup.find(name='title')
if(flag.text == "手机号设置"):
if self.__phone == '':
return '请填写手机号', 511
return '请填写手机号', 513
execution = soup.find_all(name='input')[1]['value']
formdata = {
'phone': self.__phone,
@ -65,7 +65,7 @@ class Crawler(object):
if soup.findAll(name='a')[4]['href'] != 'logout':
raise('账号或密码错误')
except:
return '账号或者密码错误', 510
return '账号或者密码错误', 511
r = self.__session.get(
url='https://mysso.cust.edu.cn/cas/login?service=https://jwgls1.cust.edu.cn/welcome', allow_redirects=False)
ticket = r.headers['Location'][42:]
@ -80,14 +80,14 @@ class Crawler(object):
data = json.loads(r.content.decode('utf-8'))
# 提示未建立教务信息
if data['state'] == 1:
return data['message'], 513
return data['message'], 514
self.real_name = data['data']['StudentDto']['XM']
self.sid = data['data']['StudentDto']['XH']
self.uid = data['data']['StudentDto']['SMXSJBXXID']
return self.getUserInfo(), 200
except Exception as e:
print(e)
return '教务挂了', 512
return '教务挂了', 515
# 获取成绩 -----------------------------------------------------------------------------
def getGrade(self):
@ -100,7 +100,7 @@ class Crawler(object):
)
data = json.loads(r.content.decode('utf-8'))
if data['state'] != 0:
return '教务挂了', 512
return '教务挂了', 515
# 分解数据并重命名
total = data['data']['GradeStatistics']
split = data['data']['GradeList']
@ -327,7 +327,7 @@ class Crawler(object):
)
data = json.loads(r.content.decode('utf-8'))
if data['state'] != 0:
return ('教务挂了', 512)
return ('教务挂了', 515)
return self.manageSchedule(data)
# 获取他人课表
@ -343,7 +343,7 @@ class Crawler(object):
)
data = json.loads(r.content.decode('utf-8'))
if data['state'] != 0:
return ('教务挂了', 512)
return ('教务挂了', 515)
return self.manageSchedule(data)
# 获取cookie

@ -198,6 +198,7 @@ def findGroup(group_id):
'user_list.cid':0,
'user_list.pwd':0,
'user_list.setting':0,
'user_list.last_update': 0,
}
}
])
@ -371,4 +372,29 @@ def findGroupCrouse(group_id):
return crouse_list, 200
except Exception as e:
print(e)
return '用户组课程数据库查询失败', 305
return '用户组课程数据库查询失败', 305
def insertLog(log):
"""
插入操作记录
"""
try:
col('log').insert_one(log)
return 'OK', 200
except Exception as e:
print(e)
return '系统操作记录数据库插入失败', 111
def findLog(has_read_page):
"""
查询操作记录默认50条分割
"""
skip = 50 * (has_read_page - 1)
log_list = []
try:
for i in col('log').find({}).limit(50).skip(skip):
log_list.append(i)
return log_list, 200
except Exception as e:
print(e)
return '系统操作记录数据库查询失败', 306

@ -25,4 +25,15 @@ def signCode(code):
md = md5()
md.update(d.encode('utf-8'))
r = md.hexdigest().upper()
return r
return r
def checkData(data):
"""
MD5校验数据
"""
d = data.copy()
try:
d.pop('sign')
except KeyError:
pass
return data['sign'] == signCode(d)