Exemple #1
0
def cho_tec_course(obj, course1, t_class):
    #更改老师教课列表
    obj.course.append(course1)
    #更改老师教课班级
    obj.classes.append(t_class)
    DB_handler.save_obj_to_file(obj)
    return
Exemple #2
0
def student_resister(name, password):
    # 要判断是否存在这个学生
    filenames = DB_handler.get_all_filename(Student.__name__.lower())
    if not filenames:
        student = Student(name, password)
        DB_handler.save_obj_to_file(student)
        return student
    if name in filenames:
        return
    # 处理数据并且完成存储
    student = Student(name, password)
    DB_handler.save_obj_to_file(student)
    return student
Exemple #3
0
def admin_resister(name, password):
    # 要判断是否存在这个管理员,返回管理员列表
    filenames = DB_handler.get_all_filename(Admin.__name__.lower())
    if not filenames:
        #生成管理员对象
        admin = Admin(name, password)
        DB_handler.save_obj_to_file(admin)
        return admin
    if name in filenames:
        return
    # 处理数据并且完成存储
    admin = Admin(name, password)
    DB_handler.save_obj_to_file(admin)
Exemple #4
0
def zhuce(dic_user):
    tag = True
    while tag:
        user_name = input("请输入您要注册的姓名:").strip()
        if user_name in dic_user:
            print("该姓名存在")
            continue
        pwd1 = input("请输入密码:").strip()
        pwd2 = input("请在此输入密码:").strip()
        if pwd1 == pwd2:
            pwd3 = hashlib_pwd(pwd2)
            while tag:
                emile = input("请输入邮箱:").strip()
                j = re.findall(r"[a-z0-9\.\-+_]+@[a-z0-9\.\-+_]+\.[a-z]+",
                               emile)
                if j != []:
                    while tag:
                        yanzhengma1 = yanzhengma()
                        print("验证码:%s" % yanzhengma1)
                        yanzhengma2 = input("请输入验证码,区分大小写: ").strip()
                        if yanzhengma2 == yanzhengma1:
                            print("""
                            用户名:%s
                            密码:%s
                            邮箱:%s
                            """ % (user_name, pwd2, emile))
                            dic_user[user_name] = {
                                "pwd": pwd3,
                                "email": emile,
                                "logger_time": 0,
                                "lock": False,
                                "type": 0
                            }
                            res = DB_handler.get_user_write(dic_user)
                            jieguo = DB_handler.user_zhuce_ini(user_name)
                            if res == True and jieguo == True:
                                print("注册成功")
                                logger2.info("%s注册成功" % user_name)
                                return True
                            else:
                                print("注册失败,联系管理员")
                                tag = False
                        else:
                            print("验证码输入错误!")
                            continue
                else:
                    print("邮箱错误")
                    continue
        else:
            print("密码输入错误")
            continue
Exemple #5
0
def logginger():
    global logging_user, username
    dic_user = DB_handler.get_user_read()
    while True:
        user_name = input("请输入你的姓名: ").strip()
        if user_name not in dic_user:
            print("""
                该用户不存在!!!
                1.注册
                2.重新输入
                3.退出
                """)
            choice = input("请选择: ")
            if choice == "1":
                jieguo = zhuce(dic_user)
                if jieguo == True:
                    return
            elif choice == "2":
                continue
            elif choice == "3":
                return
            else:
                print("你输入的不正确!!!")
        else:
            if dic_user[user_name]["lock"] == False:
                count = 0
                if time.time() - dic_user[user_name]["logger_time"] >= 300:
                    while count <= 2:
                        pwd = input("请输入您的密码:").strip()
                        pwd1 = hashlib_pwd(pwd)
                        if pwd1 == dic_user[user_name]["pwd"]:
                            print("登陆成功")
                            dic_user[user_name]["logger_time"] = 0
                            DB_handler.get_user_write(dic_user)
                            logging_user = True
                            username = user_name
                            return dic_user[user_name]["type"], user_name
                        else:
                            print("密码不正确,请重新输入")
                            count += 1
                    else:
                        print("您输入次数过多,账户已被锁定300秒")
                        dic_user[user_name]["logger_time"] = time.time()
                        DB_handler.get_user_write(dic_user)
                else:
                    print("账户之前被锁定时间未超过300秒")
                    continue
            else:
                print("您的账户已被管理员锁定,请联系管理员")
                continue
Exemple #6
0
def student_choice_read(obj_name):
    if obj_name == "School":
        obj_name = School
    elif obj_name == "Teacher":
        obj_name = Teacher
    else:
        obj_name = Course
    filenames = DB_handler.get_all_filename(obj_name.__name__.lower())
    if not filenames:
        return False
    # 生成对象
    obj_lis=[DB_handler.load_obj_from_file(obj_name.__name__.lower(), i)\
             for i in filenames]
    return obj_lis
Exemple #7
0
def admin_create_school(name, address, telephone):
    #获得学校列表
    filenames = DB_handler.get_all_filename(School.__name__.lower())
    if not filenames:
        #生成学习对象
        school = School(name, address, telephone)
        #保存学校对象
        DB_handler.save_obj_to_file(school)
        return school
    if name in filenames:
        return
    school = School(name, address, telephone)
    DB_handler.save_obj_to_file(school)
    return school
Exemple #8
0
def admin_create_classes(course_school, course_class):
    # 生成创建班级的路径,是不同学校可以创建相同班级
    file_path = os.path.join(settings.DB_DIR, Classes.__name__.lower(),
                             course_school)
    filenames = DB_handler.get_all_filename(file_path)
    if not filenames:
        #生成班级对象
        classes = Classes(course_class)
        DB_handler.save_obj_to_file(classes, file_path)
        return
    if course_class in filenames:
        return course_class
    classes = Classes(course_class)
    DB_handler.save_obj_to_file(classes, file_path)
    return
Exemple #9
0
def admin_create_course(schol_name, course_name, course_time, course_money):
    #生成创建课程的路径,是不同学校可以创建相同课程
    filenames_path = os.path.join(settings.DB_DIR, Course.__name__.lower(),
                                  schol_name)
    #获得课程列表
    filenames = DB_handler.get_all_filename(filenames_path)
    if not filenames:
        #生成课程对象
        course = Course(course_name, course_time, course_money)
        DB_handler.save_obj_to_file(course, filenames_path)
        return
    if course_name in filenames:
        return course_name
    course = Course(course_name, course_time, course_money)
    DB_handler.save_obj_to_file(course, filenames_path)
    return
Exemple #10
0
def run():
    while True:
        print("""
***********************************
         欢迎来到新闻浏览器        
1.查看新闻              
2.登录
3.注册
4.退出
***********************************    
        """)
        choice=input("请输入你的选择:").strip()
        if choice == "1":
            user.show_news()
        elif choice == "2":
            jieguo,username=common.logginger()
            if jieguo == 1:
                admin.main(username)
                logger1.info("%s登陆成功"%username)
            elif jieguo == 0:
                user.main(username)
                common.logger2.info("%s登陆成功"%username)
        elif choice == "3":
            dic_user = DB_handler.get_user_read()
            common.zhuce(dic_user)
        elif choice == "4":
            exit(0)
        else:
            print("您输入的不正确,请重新输入!!!")
Exemple #11
0
def login(startname):
    global Logging, name
    while True:
        username = input("请输入登录用户名:").strip()
        filenames = DB_handler.get_all_filename(startname.lower())
        if username in filenames:
            pwd = input("请输入登录密码:").strip()
            obj1 = DB_handler.halib_file(pwd)
            obj = DB_handler.load_obj_from_file(startname, username)
            pwd2 = getattr(obj, "pwd")
            if obj1 == pwd2:
                Logging = True
                print("登录成功!!!")
                name = obj
                return name
            print("密码错误!!!")
            continue
        while True:
            if startname == "student" or startname == "admin":
                print("""
======================
    1.注册
    2.返回
======================           
                """)
                choice = input("请选择:")
                if choice == "1":
                    obj = register(startname)
                    if not obj:
                        return
                    elif choice == "2":
                        return
                    else:
                        print("输入错误!!!")
            else:
                print("请联系管理员帮你注册")
                return
Exemple #12
0
def register(startname):
    while True:
        user_name = input("请输入注册用户名(q退出):").strip()
        if user_name == "q": break
        if not user_name:
            print("用户名不能为空")
            continue
        pwd = input("请输入密码:").strip()
        if not pwd:
            print("密码不能为空")
            continue
        pwd1 = input("请再次输入密码:").strip()
        pwd2 = DB_handler.halib_file(pwd1)
        if not pwd1:
            print("密码不能为空")
            continue
        if pwd != pwd1:
            print("两次密码不一致")
            continue
        # 将数据按照不同的用户传给对应的接口层
        if startname == "admin":
            obj = admin_interface.admin_resister(user_name, pwd2)
            if obj:
                print("管理员注册成功")
                logger = get_logging("admin")
                logger.info("%s管理员注册成功" % (user_name))
                return
            else:
                print("用户名已存在,")
        elif startname == "student":
            obj = student_interface.student_resister(user_name, pwd2)
            if obj:
                print("学生注册成功,请重新启动")
                logger = get_logging("student")
                logger.info("%s学生注册成功" % (user_name))
                exit(0)
            else:
                print("用户名已存在,")
        else:
            obj = teacher_interface.teacher_resister(user_name, pwd2)
            if not obj:
                print("老师注册成功")
                logger = get_logging("teacher")
                logger.info("%s老师注册成功" % user_name)
                return user_name
            else:
                print(obj)
Exemple #13
0
def student_attr_set(st_obj, name, choice_obj):
    if type(choice_obj) != str and type(choice_obj) != int:
        setattr(st_obj, name, choice_obj.name)
        DB_handler.save_obj_to_file(st_obj)
        return
    elif type(choice_obj) == str or type(choice_obj) == int:
        setattr(st_obj, name, choice_obj)
        DB_handler.save_obj_to_file(st_obj)
        return
    else:
        s = getattr(st_obj, name)
        s.append(choice_obj)
        DB_handler.save_obj_to_file(st_obj)
        return
Exemple #14
0
def teacher_resister(name, password):
    # 要判断是否存在这个老师
    filenames = DB_handler.get_all_filename(Teacher.__name__.lower())
    school = input("请选择学校:").strip()
    #回去所有学校列表
    school_name = DB_handler.get_all_filename(School.__name__.lower())
    if school not in school_name:
        return "该学校不存在"
    # 第一次没有相对目录filenames为None
    if not filenames:
        #生成老师对象
        teacher = Teacher(name, password, school)
        DB_handler.save_obj_to_file(teacher)
        return
    if name in filenames:
        return "该老师已存在"
    # 处理数据并且完成存储
    teacher = Teacher(name, password, school)
    DB_handler.save_obj_to_file(teacher)
    return
Exemple #15
0
def set_tec_grade(st_obj, chengji):
    #将学生对象的成绩的值改为多少
    setattr(st_obj, "grade", chengji)
    DB_handler.save_obj_to_file(st_obj)