def create_student(self): # 创建学生 while True: name = self.input_check('学生的姓名') # 执行方法,判断用户名是否存在 ret = Personal.username_exist(name) if ret == False: print('用户已存在,请重新输入!') continue pwd = self.input_check('学生的密码') sex = self.input_check('学生的性别(M男|F女)', 'sex') sex = sex.upper() age = self.input_check('学生的年龄', 'int', 256) # 执行方法,执行选择课程信息 course = self.choice_courses() # 执行方法,查看课程对应的班级 classes_list = Course.course_classes(course) if classes_list == []: print('当前课程没有班级,请创建班级') continue print('当前课程对应的班级如下:') for k, v in enumerate(classes_list): print(str(k + 1) + '. ', v) classes_id = input('请输入班级编号: ').strip() if classes_id.isdigit(): classes_id = int(classes_id) if classes_id in range(1, len(classes_list) + 1): classes = classes_list[classes_id - 1] else: print('班级编号输入错误,请重新输入') continue # 写入登录文件 password = get_pwd(name, pwd) ret1 = Personal.write_auth_file(name, password, 'Student') if ret1: # 写入学生详细信息文件 s1_info = { 'name': name, 'sex': sex, 'age': age, 'course': course, 'score': 0, 'classes': classes } ret2 = Personal.write_user_details(s1_info, 'student') if ret2: Logger.logger.info('%s 创建了%s学生' % (self.info['username'], name)) # 记录日志 print(Prompt.display('添加成功!信息为:', 'green')) print('姓名:{} 性别:{} 年龄:{} 课程:{} 成绩:0 班级:{}'.format( name, sex, age, course, classes)) break else: print('写入学生详细信息失败!') continue else: print('写入用户注册文件失败!') continue
def create_course(self): # 创建课程 while True: course = self.input_check('课程名') # 执行方法,判断课程名是否存在 ret = Course.course_exist(course) if ret is False: print('课程名已经存在,请重新输入!') continue cycle = self.input_check('周期(单位:月)', 'int', 36) price = self.input_check('价格(单位:人民币)', 'int', 1000000) self.ses_school() # 显示学校列表 school_list = School.school_info() city_id = self.input_check('学校编号', 'int', len(school_list) + 1) city = school_list[int(city_id) - 1] # 写入课程详细信息 course_f = MyPickle(settings.file_name['course']) try: t1_course = { 'name': course, 'cycle': cycle, 'price': price, 'city': city } course_f.dump(t1_course) Logger.logger.info('%s 创建了%s课程' % (self.info['username'], course)) # 记录日志 print(Prompt.display('添加课程成功!信息为:', 'green')) print('课程: {} 周期: {}个月 价格: ¥{} 城市: {}'.format( course, cycle, price, city)) break except Exception: print('添加课程失败!') continue
def create_school(self): while True: self.ses_school() name = self.input_check('新学校名') if name.isdigit(): print(Prompt.display('学校名不能为数字!', 'red')) continue ret = School.school_exist(name) if ret is False: #print('学校名已存在,请重新输入!') print(Prompt.display('学校名已存在,请重新输入!', 'red')) continue s_info = {'name': name} ret2 = School.write_school(s_info) if ret2: Logger.logger.info('%s 创建了%s学校' % (self.info['username'], name)) # 记录日志 print(Prompt.display('添加成功!信息为:', 'green')) print('学校名:{}'.format(name)) break else: print(Prompt.display('写入学校细信息失败!', 'red')) continue
def login(self): # 判断失败次数是否小于等于最大失败次数 while self.auth_dic['failures'] <= self.auth_dic['maximum']: username = input('请输入登录用户名: ').strip() if not username: print(Prompt.display('用户名不能为空!', 'red')) continue password = input('请输入登录密码: ').strip() if not password: print(Prompt.display('密码不能为空!', 'red')) continue en_pwd = self.get_pwd(username, password) # 获取加密密码 # 判断用户名和密码是否一致 res = self.user_auth(username, en_pwd) if res['msg']: print(Prompt.display('登陆成功!', 'green')) Logger.logger.info('%s 登陆成功' % username) # 修改初始变量 self.auth_dic['username'] = username self.auth_dic['status'] = True self.auth_dic['role'] = res['role'] return {'username': username, 'role': res['role']} # 返回字典给调用者 else: chance = self.auth_dic['maximum'] - self.auth_dic[ 'failures'] # 剩余失败次数 print(Prompt.display('用户或密码错误,请重新输入!您还有%s次机会!' % chance, 'red')) self.auth_dic['failures'] += 1 # 失败次数加1 Logger.logger.info( '%s 登陆失败%s次' % (username, self.auth_dic['maximum'] - chance)) # 判断失败次数大于最大次数时,直接退出! if self.auth_dic['failures'] > self.auth_dic['maximum']: self.auth_dic['flag'] = False return False
def create_classes(self): # 创建班级 while True: classes = self.input_check('班级名') # 执行方法,判断班级名是否存在 ret = Classes.classes_exist(classes) if ret is False: print('班级名已经存在,请重新输入!') continue # 执行方法,执行选择课程信息 course = self.choice_courses() # 查看课程对应的老师列表 teacher_list = Course.course_teacher(course) if teacher_list == []: print('当前课程没有老师,请创建老师') continue else: print('当前课程对应的老师如下:') for k, v in enumerate(teacher_list): print(str(k + 1) + '. ', v) teacher_id = input('请输入老师的编号: ').strip() if teacher_id.isdigit(): teacher_id = int(teacher_id) if teacher_id in range(len(teacher_list) + 1): # 写入班级详细信息 classes_f = MyPickle(settings.file_name['classes']) try: t1_classes = { 'name': classes, 'course': course, 'teacher': teacher_list[teacher_id - 1] } classes_f.dump(t1_classes) Logger.logger.info( '%s 创建了%s班级' % (self.info['username'], classes)) # 记录日志 print(Prompt.display('添加班级成功!信息为:', 'green')) print('名字: {} 课程: {} 老师: {}'.format( classes, course, teacher_list[teacher_id - 1])) break except Exception: print('添加班级失败!') continue else: print('输入老师的编号不正确,请重新输入!') continue
def create_teacher(self): # 创建老师 while True: name = self.input_check('老师的姓名') # 执行方法,判断用户名是否存在 ret = Personal.username_exist(name) if ret is False: print('用户已存在,请重新输入!') continue pwd = self.input_check('老师的密码') sex = self.input_check('老师的性别(M男|F女)', 'sex') sex = sex.upper() age = self.input_check('老师的年龄', 'int', 256) # 执行方法,执行选择课程操作 course = self.choice_courses() # 获取加密的密码 password = get_pwd(name, pwd) ret1 = Personal.write_auth_file(name, password, 'Teacher') if ret1: # 写入老师详细信息文件 t1_info = { 'name': name, 'sex': sex, 'age': age, 'course': course } ret2 = Personal.write_user_details(t1_info, 'teacher') if ret2: Logger.logger.info('%s 创建了%s老师' % (self.info['username'], name)) # 记录日志 print(Prompt.display('添加成功!信息为:', 'green')) print('姓名:{} 性别:{} 年龄:{} 课程:{}'.format( name, sex, age, course)) break else: print('写入老师详细信息失败!') continue else: print('写入用户注册文件失败!') continue
def user_auth(username, password): ''' #判断用户名和密码是否匹配 :param username: 用户名 :param password: 密码 :return: True 匹配成功 False 匹配失败 ''' if not username or not password: print(Prompt.display('用户名或者密码不能为空!', 'red')) return False user = MyPickle(settings.file_name['user']) read_user = user.load() for i in read_user: if username == i['username'] and password == i['password']: result = {'msg': True, 'role': i['role']} return result else: return {'msg': False, 'role': None}
def interlacing_color(operate_lst): # 隔行换色 diff = 0 # 差值 if len(operate_lst) > len(Prompt.colour_list): # 当菜单列表长度大于颜色列表长度时 diff = len(operate_lst) - len(Prompt.colour_list) # 菜单列表长度-颜色列表长度 colour_list = list(Prompt.colour_list) new_list = colour_list # 新的颜色列表 if diff >= 0: # 当菜单列表长度大于等于颜色列表长度时 for i in range(diff + 1): new_list.append(colour_list[i]) # 添加颜色,使颜色列表等于菜单列表长度 count = -1 # 颜色列表索引值,默认为-1 for key, item in enumerate(operate_lst, 1): # 获取每个角色类的operate_lst静态属性,显示的序列号从1开始 count += 1 # 索引加1 ret = Prompt.display('{}.\t{}'.format(key, item[0]), new_list[count]) # 按照列表顺序显示颜色 print(ret)
def main(self): #print('您好: {} 同学 欢迎使用校园后台管理系统!\n'.format(self.name)) print( Prompt.display( '您好: {} 同学 欢迎使用校园后台管理系统!\n'.format(self.info['username']), 'purple_red'))
def manage_classes(self): # 修改班级学员成绩 classes_list = self.classes_info() if classes_list == []: print('当前没有教学班级!') else: while True: print('当前管理的班级为:') for k, v in enumerate(classes_list, 1): print('{}.\t{}'.format(k, v['name'])) classes_id = input('请输入班级编号,或输入b返回菜单 ').strip() if classes_id.upper() == 'B': break if classes_id.isdigit(): classes_id = int(classes_id) if classes_id in range(1, len(classes_list) + 1): classes = classes_list[classes_id - 1]['name'] student_list = self.student_info(classes) if student_list == []: print('当前班级没有学生!') continue else: print('===================================') print('{} 班级学员列表如下:'.format(classes)) for k, v in enumerate(student_list): print( '{}.\t姓名:{} 性别:{} 年龄:{} 成绩:{} 班级:{} 课程:{}'. format(k + 1, v['name'], v['sex'], v['age'], v['score'], v['classes'], v['course'])) student_id = input('请输入学生编号: ').strip() if student_id.isdigit(): student_id = int(student_id) if student_id in range(1, len(student_list) + 1): student = student_list[student_id - 1] score = input('请输入要修改的成绩: ').strip() if score.isdigit(): score = int(score) if score in range(1, 101): # 修改成绩 ret = self.modify_score( student['name'], score) ret1 = self.rewrite(ret) # print(ret) if ret1: Logger.logger.info( '%s 修改了%s学生成绩' % (self.info['username'], student['name'])) # 记录日志 print( Prompt.display( '修改成绩成功!', 'green')) break else: print('修改失败!') continue else: print('成绩不能大于100!') continue else: print('成绩请输入数字!') continue else: print('学生编号超出范围,请重新输入!') continue else: print('学生编号输入错误!') continue else: print('班级编号超出范围,请重新输入!') continue else: print('班级编号输入错误,请重新输入!') continue
options = parser.parse_args() target = str(options.url) domain = str(options.domain) #scan = str(options.scan) path = args.path port = str(options.port) delay = options.delay proxy = options.proxy timeout = options.timeout if not proxy: core.Config.proxies = {} #ans = scan level = 1 if type(args.add_headers) == bool: headers = extractHeaders(Prompt()) elif type(args.add_headers) == str: headers = extractHeaders(args.add_headers) else: from core.Config import headers #using a domain and a port or a URL? if ":" not in target: if (len(str(domain)) > 4): target = "http://" + domain #print "target is: " + target else: parsed_uri = urlparse(target) domain = '{uri.netloc}'.format(uri=parsed_uri) #print "domain after parsed_uri is now: " + domain