示例#1
0
def login():
    if request.method == 'GET':
        return render_template('login.html')
    else:
        account = request.form['account']
        password = request.form['password']
        if len(account) == 0 | len(password) == 0:
            return render_template('login.html')

        cursor.execute('select account from coursefilemanagement.user')
        accounts = cursor.fetchall()

        for account in accounts:
            if request.form['account'] == account[0]:
                cursor.execute(
                    'select password,usertype from coursefilemanagement.user where account=%s',
                    (account[0]))
                detail = cursor.fetchall()

                if request.form['password'] == detail[0][0]:
                    curr_user = User()
                    curr_user.id = account[0]
                    print(curr_user.id)
                    login_user(curr_user)
                    return redirect(url_for('.homepage'))

        return '<h>账号、密码错误!</h>'
示例#2
0
def download_file():
    filepath = '../' + 'files/' + current_user.get_id()
    fileID = request.form['id']
    cursor.execute(
        'select fileName from coursefilemanagement.file where fileID=%s',
        fileID)
    filename = cursor.fetchall()
    print(filepath)
    print(filename[0][0])
    return send_from_directory(filepath, filename[0][0], as_attachment=True)
示例#3
0
def load_user(user_id):
    curr_user = User()
    curr_user.id = user_id
    cursor.execute(
        'select usertype '
        'from coursefilemanagement.user '
        'where account=%s', user_id)
    detail = cursor.fetchall()
    ac_type = detail[0][0]
    curr_user.utype = ac_type
    return curr_user
示例#4
0
def newmessage():
    if request.method == 'GET':
        return render_template('mailbox.html')
    else:
        receiver = request.form['receiver']
        content = request.form['content']
        if current_user.utype == 1:
            cursor.execute(
                'select sID '
                'from coursefilemanagement.student '
                'where account=%s', (current_user.get_id()))
            sid = cursor.fetchall()
            messageID = time.strftime("%m%d%H%M%S", time.localtime()) + str(
                random.randint(1, 99))
            cursor.execute(
                'insert into coursefilemanagement.message(sID, tID, messageID, content, direction) '
                'values (%s,%s,%s,%s,%s)',
                (sid[0][0], receiver, messageID, content, 0))
            conn.commit()
            return 'success!'
        elif current_user.utype == 2:
            cursor.execute(
                'select tID '
                'from coursefilemanagement.teacher '
                'where account=%s', (current_user.get_id()))
            tid = cursor.fetchall()
            messageID = time.strftime("%m%d%H%M%S", time.localtime()) + str(
                random.randint(1, 99))
            cursor.execute(
                'insert into coursefilemanagement.message(sID, tID, messageID, content, direction) '
                'values (%s,%s,%s,%s,%s)',
                (receiver, tid[0][0], messageID, content, 1))
            conn.commit()
            return 'success!'
示例#5
0
def register():
    if request.method == 'GET':
        return render_template('register.html')
    else:
        usertype = request.form['usertype']
        account = request.form['account']
        password = request.form['password']
        if len(account) == 0:
            return render_template('error.html', err=0)

        cursor.execute(
            'insert into coursefilemanagement.user(usertype, account, password) values (%s,%s,%s)',
            (usertype, account, password))

        conn.commit()
        return '<h>注册成功!请登录。</h><form action="/login" method="get"><p><button type="submit">返回登录</button></p></form>'
示例#6
0
def mailbox():
    if current_user.utype == 1:
        cursor.execute(
            'select tid, sid, messageid, content, direction '
            'from coursefilemanagement.message natural join coursefilemanagement.student '
            'where account = %s', (current_user.get_id()))
        message_list = cursor.fetchall()
        print(message_list)
        return render_template('mailbox.html', message_list=message_list)
    elif current_user.utype == 2:
        cursor.execute(
            'select tid, sid, messageid, content, direction '
            'from coursefilemanagement.message natural join coursefilemanagement.teacher '
            'where account = %s', (current_user.get_id()))
        message_list = cursor.fetchall()
        print(message_list)
        return render_template('mailbox.html', message_list=message_list)
def smodify():
    if request.method == 'GET':
        return render_template('smodify.html')
    else:
        studentName = request.form['studentName']
        sID = request.form['sID']
        majorID = request.form['majorID']

        cursor.execute(
            'DELETE FROM coursefilemanagement.student '
            'WHERE account =%s', (current_user.get_id()))

        cursor.execute(
            'insert into coursefilemanagement.student(studentName, sID, account, majorID) values (%s,%s,%s,%s)',
            (studentName, sID, current_user.get_id(), majorID))

        conn.commit()
        return redirect(url_for('.perinfo'))
示例#8
0
def upload_file():
    if request.method == 'GET':
        return render_template('uploadfile.html')
    else:
        f = request.files['file']
        filename = secure_filename(f.filename)
        if os.path.exists('../files'):
            print('base folder exists')
        else:
            os.mkdir('../files')
        filepath = 'files/' + current_user.get_id()
        if os.path.exists(filepath):
            print('filepath exists')
        else:
            os.mkdir(filepath)
        f.save(os.path.join(filepath, filename))
        print(current_user.get_id())
        fileID = time.strftime("%m%d%H%M%S", time.localtime()) + str(
            random.randint(1, 99))
        cursor.execute(
            'insert into coursefilemanagement.file(fileName, fileID, account) values (%s,%s,%s)',
            (filename, fileID, current_user.get_id()))
        conn.commit()
        return render_template('uploadfile.html')
示例#9
0
def show_file():
    cursor.execute('select * from coursefilemanagement.file')
    file_list = cursor.fetchall()
    print(file_list)
    return render_template('showfile.html', file_list=file_list)
def tmodify():
    if request.method == 'GET':
        return render_template('tmodify.html')
    else:
        try:
            teacherName = request.form['teacherName']
            tID = request.form['tID']
            cursor.execute(
                'DELETE FROM coursefilemanagement.teacher '
                'WHERE account =%s', (current_user.get_id()))
            cursor.execute(
                'insert into coursefilemanagement.teacher(teacherName, tID, account) values (%s,%s,%s)',
                (teacherName, tID, current_user.get_id()))
        except:
            print('no teacher modified')

        try:
            buildingName = request.form['buildingName']
            buildingID = request.form['buildingID']
            cursor.execute(
                'insert into coursefilemanagement.building(buildingName, buildingID) VALUES (%s,%s)',
                (buildingName, buildingID))
        except:
            print('no building modified')

        try:
            courseName = request.form['courseName']
            courseID = request.form['courseID']
            tID = request.form['tID']
            buildingID = request.form['buildingID']
            cursor.execute(
                'insert into coursefilemanagement.course VALUES (%s,%s,%s,%s)',
                (courseName, courseID, tID, buildingID))
        except:
            print('no course modified')

        try:
            majorName = request.form['majorName']
            majorID = request.form['majorID']
            cursor.execute(
                'insert into coursefilemanagement.major VALUES (%s,%s)',
                (majorName, majorID))
        except:
            print('no major modified')

        try:
            courseID = request.form['courseID']
            sID = request.form['sID']
            cursor.execute(
                'insert into coursefilemanagement.student_course VALUES (%s,%s)',
                (courseID, sID))
        except:
            print('no course_student modified')

        conn.commit()
        return redirect(url_for('.perinfo'))
def perinfo():
    if current_user.utype == 1:
        cursor.execute('select * from coursefilemanagement.student')
        student_details = cursor.fetchall()
        for student_detail in student_details:
            if student_detail[2] == current_user.get_id():
                return render_template('sperinfo.html',
                                       u_detail=(student_detail, ))
        return render_template('sperinfo.html',
                               u_detail=(('?', '?', '?', '?'), ))

    elif current_user.utype == 2:
        cursor.execute('select * from coursefilemanagement.teacher')
        teacher_details = cursor.fetchall()
        cursor.execute('select * from coursefilemanagement.building')
        building_details = cursor.fetchall()
        cursor.execute('select * from coursefilemanagement.course')
        course_details = cursor.fetchall()
        cursor.execute('select * from coursefilemanagement.major')
        major_details = cursor.fetchall()
        cursor.execute('select * from coursefilemanagement.student_course')
        sc_details = cursor.fetchall()

        for teacher_detail in teacher_details:
            if teacher_detail[2] == current_user.get_id():
                return render_template('tperinfo.html',
                                       u_detail=(teacher_detail, ),
                                       building_details=building_details,
                                       course_details=course_details,
                                       major_details=major_details,
                                       sc_details=sc_details)
        return render_template('tperinfo.html',
                               u_detail=(('?', '?', '?'), ),
                               building_details=building_details,
                               course_details=course_details,
                               major_details=major_details,
                               sc_details=sc_details)