app.py 3.05 KB

from flask import request, render_template, redirect, session, flash, Flask
from Users import *
from ReservationControl import *
from datetime import datetime

app = Flask(__name__)
app.secret_key = 'A0Zr98j/3yX R~XHH!jmN]LWX/,?RT'

@app.route('/', redirect_to="/login")
def http_prepost_response():
    return "helloworld"


@app.route('/login', methods=["GET"])
def login():
    if session.get('ID'):
        return redirect('/myhome')
    elif request.args.get('retry') == 'true':
        return render_template("login.html", retry=True)
    return render_template("login.html", retry=False)


@app.route('/join')
def join():
    return render_template('join.html')


@app.route('/join/confirm', methods=['POST'])
def join_confirm():
    join_item = request.form
    print(join_item)
    if UserJoin(join_item.get('id'),join_item.get('deptid'),join_item.get('name'),join_item.get('password'),join_item.get('phone'),join_item.get('email')):
        flash('회원가입 성공!')
        return redirect('/login')
    flash('회원가입 실패!')
    return redirect('/join')


@app.route('/logincheck', methods=["POST"])
def login_check():
    IDPW = request.form
    if UserLogin(IDPW.get('id'),IDPW.get('pw')):
        session['ID'] = IDPW.get('id')
        welcome = IDPW.get('id')+" 님 안녕하세요!"
        flash(welcome)
        return redirect('/myhome')
    flash("ID와 비밀번호를 확인해주세요.")
    return redirect('/login?retry=true')


@app.route('/myhome')
def mystat():
    return render_template("myhome.html", ID=session['ID'])


@app.route('/viewresv')
def view_resv():
    resv_list = getReservations(session['ID'])
    print(resv_list)
    return render_template('resv_view.html', resv_list=resv_list)

@app.route('/deleteresv', methods=['POST'])
def delete_resv():
    resv_id = request.form
    if deleteReservations(resv_id.get('resv_id')):
        flash("예약이 삭제되었습니다")
    else:
        flash("예약 삭제에 실패했습니다")
    return redirect('/viewresv')



@app.route('/search')
def book():
    return render_template("resv_sch.html", ID=session['ID'])


@app.route('/search/result', methods=['POST'])
def search_result():
    searchdata = request.form
    print(searchdata)
    starttime = datetime.strptime(searchdata.get('starttime'),'%Y-%m-%dT%H:%M')
    endtime = datetime.strptime(searchdata.get('endtime'),'%Y-%m-%dT%H:%M')
    print(starttime,endtime)
    if searchdata.get('search'):
        # searchdata.get('searchinput') 얻어와서 sql 검색 쿼리
        pass
    elif searchdata.get('cat'):
        # searchdata.get('searchinput') 얻어와서 sql 검색 쿼리
        pass
    return render_template("searchresult.html", result)


@app.route('/search/resv', methods=['POST'])
def book_confirm():
    pass #search_result 페이지에서 JS로든 요청 보내면 예약 처리




@app.route('/logout')
def logout():
    session.clear()
    flash("로그아웃 되었습니다.")
    return redirect('/login')


if __name__ == '__main__':

    print("done")
    app.config['SESSION_TYPE'] = 'filesystem'
    app.run(host="0.0.0.0")