def delete(id):
    if not session.get('logged_in'):
        return redirect(url_for('login'))
    owner_id = session['id']
    User.delete().where(User.id == id).execute()
    flash("User Deleted Successfully")
    return redirect(url_for('show'))
def register():
    if request.method == "POST":
        names = request.form["names"]
        email = request.form["email"]
        password = request.form["password"]
        password = generate_password_hash(password)
        User.create(names=names, email=email, password=password)
        flash("Account Created Successfully")
    return render_template("register.html")
def update(id):
    user = User.get(User.id == id)
    if request.method == "POST":
        names = request.form["names"]
        age = request.form["age"]
        weight = request.form["weight"]
        user.names = names
        user.age = age
        user.weight = weight
        user.save()
        flash("User Updated Successfully")
        return redirect(url_for('show'))
    return render_template('update.html', user=user)
def login():
    if request.method == "POST":
        email = request.form["email"]
        password = request.form["password"]
        try:
            user = User.get(User.email == email)
            hashed_password = user.password
            if check_password_hash(hashed_password, password):
                flash("Logged in Successfully")
                session['logged_in'] = True
                session['names'] = user.names
                session['id'] = user.id
                return redirect(url_for('show'))
        except User.DoesNotExist:
            flash("Wrong Username or Password")
    return render_template("login.html")
Beispiel #5
0
def update(id):
    user = User.get(User.id == id)
    if request.method == "POST":
        names = request.form["names"]
        admission = request.form["admission"]
        hostel = request.form["hostel"]
        email = request.form["email"]
        password = request.form["password"]
        password = generate_password_hash(password)
        user.names = names
        user.admission = admission
        user.hostel = hostel
        user.email = email
        user.password = password
        user.save()
        flash("User Updated Successfully")
        return redirect(url_for('show'))
    return render_template('update.html', user=user)
Beispiel #6
0
def post_process_request():
    response = request.form['state']
    TID = request.form['TID']
    EID = request.form['EID']
    EName = request.form['Ename']
    TName = request.form['Tname']
    if response == '许可':
        ltime = time.localtime()
        timeStr = time.strftime("%Y-%m-%d %H:%M:%S", ltime)
        # 调用宗佬的模拟
        MY_TWS.run(User(EName), Product(TName))

        sql = '''INSERT INTO LEND VALUE ('%s', '%s', '%s', '%s')'''
        try:
            conn = connect_database()
            cursor = conn.cursor()
            cursor.execute(
                sql %
                (str(int(random.random() * 999999999)), timeStr, EID, TID))
            conn.commit()
        except:
            print('插入LEND失败!')
            conn.close()
    elif response == '拒绝':
        sql = '''UPDATE TOOL SET Borrow = 0 WHERE TID = ('%s')'''
        try:
            conn = connect_database()
            cursor = conn.cursor()
            cursor.execute(sql % (TID))
            conn.commit()
        except:
            print('更新TOOL的Borrow状态失败!')
            conn.close()
    sql = '''DELETE FROM LENDTMP WHERE TID = ('%s')'''
    try:
        conn = connect_database()
        cursor = conn.cursor()
        cursor.execute(sql % (TID))
        conn.commit()
    except:
        print('删除LENDTMP失败!')
        conn.close()
    return redirect(url_for('process_request'))
def show():
    if not session.get('logged_in'):
        return redirect(url_for('login'))
    id = session['id']
    users = User.select()
    return render_template('show.html', users=users)