def post(self): args = self.parser.parse_args() device_id = args['device_id'] mac = args['mac'] classid = args['classid'] payload = util.parser_token(request.headers['Authorization']) device_check_val = deviceCheck(payload,device_id) if device_check_val: #是本人 time_check_val = isLessonTime(classid) if time_check_val: #时间正确 room_check_val = inClassRoom(classid,mac) if room_check_val: #在教室内 leave_check_val = isAskLeaveBeforeSign(payload.username,classid) if leave_check_val: return sign_result(error,msg='已经请假过了,不用签到',error_code=error_code.sign_leave_before_error) elif isinstance(leave_check_val,bool): repeat_check_val = isSignRepeat(payload.username,classid) if repeat_check_val: return sign_result(error,msg='重复签到',error_code=error_code.sign_repeat_error) elif isinstance(repeat_check_val,bool): if sign(payload.username,classid):#没有重复签到 return sign_result(success,msg='签到成功') elif isinstance(room_check_val,bool): return sign_result(failed,msg='签到地点错误',error_code=error_code.sign_room_error) elif isinstance(time_check_val,bool): return sign_result(failed,msg='签到时间不对',error_code=error_code.sign_time_error) elif isinstance(device_check_val,bool): #失败检查失败 return sign_result(failed,msg='不是本人设备',error_code=error_code.sign_device_error) return sign_result(error,msg='未知错误',error_code=error_code.unknow_error)
def wrapper(*args, **kwargs): if not request.headers.get('Authorization'): return base_result(failed, msg='no token', error_code=error_code.token_no_exist_error) token = request.headers['Authorization'] # print(token) payload = util.parser_token(token) if payload is None: return base_result(failed, msg='no token', error_code=error_code.token_no_exist_error) print('[' + payload.identify + ']' + payload.username + ' auth in ' + str(datetime.fromtimestamp(payload.timestamp))) nowtime = int(datetime.now().timestamp()) if not payload: return base_result(failed, msg='illegal token', error_code=error_code.token_illegal_error) if nowtime - payload.timestamp > configs.app.exprire: return base_result(failed, msg='expire token', error_code=error_code.token_expire_error) else: return func(*args, **kwargs)
def get(self,start_year,semester): """ 获取课表 :return: """ payload = util.parser_token(request.headers['Authorization']) if payload.identify == Identify.STUDENT.value:#学生类型 student = Student.objects(account=payload.username).first() if not student.syllabus.get(start_year+'0'+str(semester)): #数据库中没有这一学期的课表 ret_val = util.get_syllabus_page(payload.username,student.password,start_year,semester) if not ret_val.status == Status.SUCCESS.value: return syllabus_result(failed,msg=ret_val.msg) parser = util.SyllabusParser(ret_val.content) #从学分制获取课表 raw_lessons = parser.parse().lessons lessons = list() for data in raw_lessons: #将课程保存到数据库中,同时保持单例性 lesson_id = data[0] Lesson().save_from_rawdata(data,start_year,semester) lessons.append(Lesson.objects(lesson_id=lesson_id).first()) syllabus = Syllabus(year=start_year,semester=semester,lessons=lessons) student.syllabus[str(start_year)+'0'+str(semester)] = syllabus student.save() return syllabus_result(success,'got syllabus from credit',syllabus=lessons) else: syllabus = student.syllabus.get(start_year+'0'+str(semester)).lessons return syllabus_result(success,'got syllabus from database',syllabus=syllabus) else: teacher = get_teacher(account=payload.username) if not teacher: return syllabus_result(error,'不存在该用户') syllabus = getUserSyllabus(teacher,start_year,semester) if syllabus is None: return syllabus_result(failed,'not exist syllabus') return syllabus_result(success,'数据库中有课表数据',syllabus=syllabus)
def put(self): payload = util.parser_token(request.headers['Authorization']) username = payload.username args = self.parser.parse_args() leave_date = datetime.strptime(args['leave_date'], '%Y%m%d') leave_type = args['leave_type'] leave_reason = args['leave_reason'] classid = args['classid'] leaveid = mkLeaveId(username, classid, leave_date) time_check_val = leaveTimeCheck(classid, leave_date) if time_check_val: repeat_check_val = isAskLeaveRepeat(leaveid) if repeat_check_val: return leave_result(failed, msg='重复请假', error_code=error_code.leave_repeat_error) elif isinstance(repeat_check_val, bool): if askLeave(leaveid, username, classid, leave_type, leave_reason, leave_date): return leave_result(success, msg='请假成功,等待老师同意') elif isinstance(time_check_val, bool): return leave_result(failed, msg='时间有问题', error_code=error_code.leave_time_error) return leave_result(failed, msg='未知错误', error_code=error_code.unknow_error)
def wrapper(*args, **kwargs): payload = util.parser_token(request.headers['Authorization']) if payload.identify == Identify.STUDENT.value: return base_result( failed, msg="该接口只允许教师访问", error_code=error_code.identify_only_teacher_error) return func(*args, **kwargs)
def put(self): args = self.parser.parse_args() deviceId = args['deviceid'] payload = util.parser_token(request.headers['Authorization']) if isDeviceExist(deviceId): return base_result(failed,msg='设备已经被绑定',error_code=error_code.device_bind_exist_error) bindDevice(payload.username,deviceId) return base_result(success,msg='绑定成功')
def put(self): args = self.parser.parse_args() deviceId = args['deviceid'] payload = util.parser_token(request.headers['Authorization']) if isDeviceExist(deviceId): return base_result(failed, msg='设备已经被绑定', error_code=error_code.device_bind_exist_error) bindDevice(payload.username, deviceId) return base_result(success, msg='绑定成功')
def put(self,classid): args = self.parser.parse_args() title = args['title'] content = args['content'] deadline = args['deadline'] payload = util.parser_token(request.headers['Authorization']) if not homeworkDeadlineCheck(deadline): return base_result(failed,msg='截止日期出错',error_code=error_code.identify_homework_deadline_error) makeHomework(payload.username,classid,title,content,deadline) return base_result(success,msg='成功发布作业')
def post(self,classid): payload = util.parser_token(request.headers['Authorization']) repeat_check_val = isLikeLessonBefore(payload.username,classid) if repeat_check_val: return lesson_like_result(failed,msg="重复点赞",error_code=error_code.like_lesson_repeat_error) elif isinstance(repeat_check_val,bool): like_ret = likeLesson(payload.username,classid) if like_ret: return lesson_like_result(success,msg="点赞成功") elif isinstance(like_ret,bool): return lesson_like_result(failed,msg="点赞失败",error_code=error_code.like_lesson_failed_error) return lesson_like_result(error,msg="未知错误",error_code=error_code.unknow_error)
def put(self, classid): args = self.parser.parse_args() title = args['title'] content = args['content'] deadline = args['deadline'] payload = util.parser_token(request.headers['Authorization']) if not homeworkDeadlineCheck(deadline): return base_result( failed, msg='截止日期出错', error_code=error_code.identify_homework_deadline_error) makeHomework(payload.username, classid, title, content, deadline) return base_result(success, msg='成功发布作业')
def wrapper(*args,**kwargs): if not request.headers.get('Authorization'): return base_result(failed,msg='no token',error_code=error_code.token_no_exist_error) token = request.headers['Authorization'] # print(token) payload = util.parser_token(token) if payload is None: return base_result(failed,msg='no token',error_code=error_code.token_no_exist_error) print('['+payload.identify+']'+payload.username+' auth in '+str(datetime.fromtimestamp(payload.timestamp))) nowtime = int(datetime.now().timestamp()) if not payload: return base_result(failed,msg='illegal token',error_code=error_code.token_illegal_error) if nowtime - payload.timestamp > configs.app.exprire: return base_result(failed,msg='expire token',error_code=error_code.token_expire_error) else: return func(*args,**kwargs)
def post(self): args = self.parser.parse_args() device_id = args['device_id'] mac = args['mac'] classid = args['classid'] payload = util.parser_token(request.headers['Authorization']) device_check_val = deviceCheck(payload, device_id) if device_check_val: #是本人 time_check_val = isLessonTime(classid) if time_check_val: #时间正确 room_check_val = inClassRoom(classid, mac) if room_check_val: #在教室内 leave_check_val = isAskLeaveBeforeSign( payload.username, classid) if leave_check_val: return sign_result( error, msg='已经请假过了,不用签到', error_code=error_code.sign_leave_before_error) elif isinstance(leave_check_val, bool): repeat_check_val = isSignRepeat( payload.username, classid) if repeat_check_val: return sign_result( error, msg='重复签到', error_code=error_code.sign_repeat_error) elif isinstance(repeat_check_val, bool): if sign(payload.username, classid): #没有重复签到 return sign_result(success, msg='签到成功') elif isinstance(room_check_val, bool): return sign_result(failed, msg='签到地点错误', error_code=error_code.sign_room_error) elif isinstance(time_check_val, bool): return sign_result(failed, msg='签到时间不对', error_code=error_code.sign_time_error) elif isinstance(device_check_val, bool): #失败检查失败 return sign_result(failed, msg='不是本人设备', error_code=error_code.sign_device_error) return sign_result(error, msg='未知错误', error_code=error_code.unknow_error)
def get(self, start_year, semester): """ 获取课表 :return: """ payload = util.parser_token(request.headers['Authorization']) if payload.identify == Identify.STUDENT.value: #学生类型 student = Student.objects(account=payload.username).first() if not student.syllabus.get(start_year + '0' + str(semester)): #数据库中没有这一学期的课表 ret_val = util.get_syllabus_page(payload.username, student.password, start_year, semester) if not ret_val.status == Status.SUCCESS.value: return syllabus_result(failed, msg=ret_val.msg) parser = util.SyllabusParser(ret_val.content) #从学分制获取课表 raw_lessons = parser.parse().lessons lessons = list() for data in raw_lessons: #将课程保存到数据库中,同时保持单例性 lesson_id = data[0] Lesson().save_from_rawdata(data, start_year, semester) lessons.append(Lesson.objects(lesson_id=lesson_id).first()) syllabus = Syllabus(year=start_year, semester=semester, lessons=lessons) student.syllabus[str(start_year) + '0' + str(semester)] = syllabus student.save() return syllabus_result(success, 'got syllabus from credit', syllabus=lessons) else: syllabus = student.syllabus.get(start_year + '0' + str(semester)).lessons return syllabus_result(success, 'got syllabus from database', syllabus=syllabus) else: teacher = get_teacher(account=payload.username) if not teacher: return syllabus_result(error, '不存在该用户') syllabus = getUserSyllabus(teacher, start_year, semester) if syllabus is None: return syllabus_result(failed, 'not exist syllabus') return syllabus_result(success, '数据库中有课表数据', syllabus=syllabus)
def post(self,start_year,semester): args = self.parser.parse_args() classid = args['classid'] payload = util.parser_token(request.headers['Authorization']) if isStudent(payload): person = get_student(account=payload.username) else: person = get_teacher(account=payload.username) ret = addLesson(person,payload.username,start_year,semester,classid) if ret: syllabus = getUserSyllabus(person,start_year,semester) return syllabus_result(success,'添加成功',syllabus=syllabus) elif isinstance(ret,bool): return syllabus_result(failed,'添加失败') return syllabus_result(error,'服务器未知错误')
def post(self, start_year, semester): args = self.parser.parse_args() classid = args['classid'] payload = util.parser_token(request.headers['Authorization']) if isStudent(payload): person = get_student(account=payload.username) else: person = get_teacher(account=payload.username) ret = addLesson(person, payload.username, start_year, semester, classid) if ret: syllabus = getUserSyllabus(person, start_year, semester) return syllabus_result(success, '添加成功', syllabus=syllabus) elif isinstance(ret, bool): return syllabus_result(failed, '添加失败') return syllabus_result(error, '服务器未知错误')
def post(self, classid): payload = util.parser_token(request.headers['Authorization']) repeat_check_val = isLikeLessonBefore(payload.username, classid) if repeat_check_val: return lesson_like_result( failed, msg="重复点赞", error_code=error_code.like_lesson_repeat_error) elif isinstance(repeat_check_val, bool): like_ret = likeLesson(payload.username, classid) if like_ret: return lesson_like_result(success, msg="点赞成功") elif isinstance(like_ret, bool): return lesson_like_result( failed, msg="点赞失败", error_code=error_code.like_lesson_failed_error) return lesson_like_result(error, msg="未知错误", error_code=error_code.unknow_error)
def put(self): payload = util.parser_token(request.headers['Authorization']) username = payload.username args = self.parser.parse_args() leave_date = datetime.strptime(args['leave_date'],'%Y%m%d') leave_type = args['leave_type'] leave_reason = args['leave_reason'] classid = args['classid'] leaveid = mkLeaveId(username,classid,leave_date) time_check_val = leaveTimeCheck(classid,leave_date) if time_check_val: repeat_check_val = isAskLeaveRepeat(leaveid) if repeat_check_val: return leave_result(failed,msg='重复请假',error_code=error_code.leave_repeat_error) elif isinstance(repeat_check_val,bool): if askLeave(leaveid,username,classid,leave_type,leave_reason,leave_date): return leave_result(success,msg='请假成功,等待老师同意') elif isinstance(time_check_val,bool): return leave_result(failed,msg='时间有问题',error_code=error_code.leave_time_error) return leave_result(failed,msg='未知错误',error_code=error_code.unknow_error)
def get(self): payload = util.parser_token(request.headers['Authorization']) return base_result(success,msg=getDeviceIds(payload.username))
def get(self): payload = util.parser_token(request.headers['Authorization']) return base_result(success, msg=getDeviceIds(payload.username))
def wrapper(*args,**kwargs): payload = util.parser_token(request.headers['Authorization']) if payload.identify == Identify.TEACHER.value: return base_result(failed,msg="该接口只允许学生访问",error_code=error_code.identify_only_student_error) return func(*args,**kwargs)