Esempio n. 1
0
def login(request: HttpRequest):
    data = request.POST.dict()
    print(data)
    account = data["account"]
    password = data["password"]
    user_type = data["type"]
    Log.i(__name__, account + "尝试登录...")
    try:
        if user_type == "student":  # 学生登录
            stu = Student.objects.filter(stu_id=account).first()
            _account = StuAccount.objects.filter(
                account_name_id=stu.id).first()
            _pwd = _account.pwd
            if _pwd == password:  # 密码正确
                obj = redirect("/stu_index")
                obj.set_cookie("account", account)
                obj.set_cookie("is_login", True)
                return obj

        else:  # 教师登录
            tea = Teacher.objects.filter(tea_id=account).first()
            _account = ManagerAccount.objects.filter(
                account_name_id=tea.id).first()
            _pwd = _account.pwd
            if _pwd == password:
                obj = redirect("/teacher/index")
                obj.set_cookie("account", account)
                obj.set_cookie("is_login", True)
                obj.set_cookie("level", _account.level)
                return obj
    except Exception:
        traceback.print_exc()
        Log.i(__name__, account + "账号错误, 登录失败...")
        return render(request, "index.html", {"status": "account_error"})
    finally:
        Log.i(__name__, account + "密码错误, 登录失败...")
    return render(request, "index.html", {"status": "password_error"})
Esempio n. 2
0
    elif sys_name.startswith("POSIX"):  # unix linux 系列
        # os.system("python3 manage.py makemigrations")
        # os.system("python3 manage.py migrate")
        os.system("python3 manage.py runserver 8000")


def start_eel():
    # 启动的函数调用放在最后,port=0表示使用随机端口,size=(宽,高)
    eel.start('db.html', port=8001, size=(1024, 800))


if __name__ == "__main__":
    # html文件所在文件夹
    eel.init('DormFrontend')
    # 检测数据库配置
    Log.i(__name__, "开始检查数据库配置")

    # 调用线程
    try:
        Log.i(__name__, "开始启动django")
        django = threading.Thread(target=start_django)
        django.setDaemon(True)
        django.start()
    except pymysql.err.InternalError:
        print_exc()
        Log.e(__name__, "数据库配置错误, django启动失败")
        sys.exit(0)

    sleep(2)
    Log.i(__name__, "开始尝试启动EEL")
    eel_t = threading.Thread(target=start_eel)