def modify():
    if request.method == 'POST':
        id = session['id']
        newpassword = request.form['new_password']
        email = request.form['email']
        name = request.form['name']
        cell_phone = request.form['cell_phone']

        buf = user(\
                   id=id, \
                   permission= session['permission'],\
                   password=newpassword,\
                   email=email,\
                   name=name,\
                   cell_phone=cell_phone)

        data = OrderedDict()

        db = DB()
        if newpassword == '':
            if db.modify_nopassword(buf):
                session_refresh(buf.id)
                data['status'] = 'ok'
            else:
                data['status'] = 'fail'
        else:
            if db.modify(buf):
                session_refresh(buf.id)
                data['status'] = 'ok'
            else:
                data['status'] = 'fail'
        del db
        return jsonify(data)
    data['status'] = 'error'
    return jsonify(data)
def Search_Boards(keyword, page):
    if request.method == "GET":
        db = DB()
        total_cnt = db.get_boardtotal_cnt()

        per_page = 10
        pagination = Pagination(page, per_page=per_page, total_count=total_cnt)

        if page != 1:
            offset = per_page * (page - 1)
        else:
            offset = 0

        del db
        mydb = search_db()
        result = mydb.get_search_list(keyword, per_page, offset)
        if not result:
            result = "not search"
        if session:
            return render_template("board.html",
                                   session=session,
                                   keyword=keyword,
                                   search_list=result,
                                   pagination=pagination)
        else:
            return render_template("board.html",
                                   keyword=keyword,
                                   search_list=result,
                                   pagination=pagination)
def board_list(category, page):

    mydb = DB()
    total_cnt = mydb.get_board_cnt(category)
    per_page = 10

    pagination = Pagination(page, per_page=per_page, total_count=total_cnt)

    if page != 1:
        offset = per_page * (page - 1)
    else:
        offset = 0

    rows = mydb.get_Page_list(per_page, offset, category)

    if session:
        return render_template("board.html",
                               session=session,
                               board_name=category,
                               rows=rows,
                               pagination=pagination)
    else:
        return render_template("board.html",
                               board_name=category,
                               rows=rows,
                               pagination=pagination)
def signup():
    if request.method == 'POST':

        id = request.form['id']
        email = request.form['email']
        password = request.form['password']
        name = request.form['name']
        cell_phone = request.form['cell_phone']

        item = user(\
                    id = id,
                    permission = 'user',
                    cell_phone = cell_phone,
                    email = email,
                    name = name,
                    password=password)

        mydb = DB()
        data = OrderedDict()
        data['status'] = 'ok'
        if not mydb.sign_up(item):
            del mydb
            data['status'] = 'error'
            return jsonify(data)
        del mydb
    if 'id' in session:
        session.clear()
    return jsonify(data)
def withdrawal():
    data = OrderedDict()
    data['status'] = 'error'
    if request.method == 'POST':
        if session:
            password = request.form['PASSWORD']

            db = DB()
            user_buf = db.login(session['id'], password)
            if user_buf == None:
                data['status'] = 'password_discordance'
                return jsonify(data)

            buf = user(\
                   id=user_buf.id, \
                   permission= session['permission'],\
                   password='',\
                   email='',\
                   name='',\
                   cell_phone='',\
                   m_delete=1)
            if db.modify(buf):
                if db.user_delete_update_board(buf.id):
                    del db
                    session.clear()
                    data['status'] = 'ok'
                    return jsonify(data)
            del db
    return jsonify(data)
Exemple #6
0
def login():
    if request.method == 'POST':
        id = request.form['id']
        password = request.form['password']
        mydb = DB()
        user_buffer = mydb.login(id, password)
        del mydb

        session.clear()

        if user_buffer:
            if user_buffer.m_delete:
                return render_template('alert_msg.html', msg="탈퇴한 회원입니다.")
            else:
                session['id'] = user_buffer.id
                session['permission'] = user_buffer.permission
                session['cell_phone'] = user_buffer.cell_phone
                session['email'] = user_buffer.email
                session['name'] = user_buffer.name
                session['sponsor_status'] = user_buffer.sponsor_status
                session['m_delete'] = user_buffer.m_delete
                return redirect(url_for('app.index'))
        else:
            return render_template('alert_msg.html',
                                   msg="Login Fail! 등록되지 않은 아이디거나 비밀번호가 다릅니다!")
    else:
        return render_template('alert_msg.html', msg="POST Error!")
Exemple #7
0
def api_login():
    id = request.json['id']
    password = request.json['password']

    data = OrderedDict()

    db = DB()
    flag = db.id_check(id)

    if flag == 0:
        data['status'] = 'id not found'
        return jsonify(data)

    user_buf = db.login(id, password)
    del db

    if user_buf:
        data['status'] = 'ok'
        data['id'] = user_buf.id
        data['permission'] = user_buf.permission

        return jsonify(data)
    else:
        data['status'] = 'password wrong'
        return jsonify(data)
def del_user(id, m_delete):
    if session['permission'] == "Admin":
        db = DB()
        mydb = Manage_DB()
        if m_delete == '0':
            mydb.delete_user(id)
            db.user_delete_update_board(id)
            del mydb
            del db
            return redirect(url_for('.manage_user'))
        else:
            return render_template('alert_msg.html', msg="탈퇴된 회원입니다.")
    else:
        return render_template('alert_msg.html', msg="잘못된 접근입니다.")
def Check_id():
    id = request.args.get('id', 0)
    if id == "error" or\
    id == "Error" or \
    id == "Admin" or \
    id == "admin" or \
    id == "Manager" or\
    id == "manager" :
        return render_template('alert_msg.html', msg="사용할수 없는 id 입니다.")
    mydb = DB()
    count = int(mydb.id_check(id))

    data = OrderedDict()
    data['count'] = count
    return jsonify(data)
Exemple #10
0
def session_refresh(id):
    mydb = DB()
    user_buffer = mydb.user_info(id)
    del mydb

    session.clear()

    if user_buffer:
        session['id'] = user_buffer.id
        session['password'] = user_buffer.password
        session['permission'] = user_buffer.permission
        session['cell_phone'] = user_buffer.cell_phone
        session['email'] = user_buffer.email
        session['name'] = user_buffer.name
        session['sponsor_status'] = user_buffer.sponsor_status
        session['m_delete'] = user_buffer.m_delete
        return True
    return False
def modify_password_check():
    if request.method == 'POST':
        id = session['id']
        password = request.form['password']

        #보낼 json데이터
        data = OrderedDict()

        db = DB()
        user_buf = db.login(id, password)
        del db
        if user_buf != None:
            data['status'] = 'ok'
            return jsonify(data)
        else:
            data['status'] = 'fail'
            return jsonify(data)
    data['status'] = 'error'
    return jsonify(data)
def board_modify():
    send_data = OrderedDict()
    data = dict()
    if request.method == "POST":
        data['uuid'] = request.form['uuid']
        data['title'] = request.form['subject']
        data['contents'] = request.form['content']
        send_data['status'] = 'error'
        db = DB()
        rows = db.get_board(data['uuid'])
        if session:
            if session['id'] == rows['id']:
                if db.modify_board(data):
                    send_data['status'] = 'ok'
                    files = request.files.getlist('file')
                    if files:
                        error = f_upload(data['uuid'], files)
                        if error:
                            db.delete_board(data['uuid'])
                            send_data['msg'] = error
                else:
                    send_data['status'] = 'fail'
        else:
            send_data['status'] = 'permission error'
    return jsonify(send_data)
def signup_form():
    if request.method == 'POST':

        id = request.form['id']
        email = request.form['email']
        password = request.form['password']
        name = request.form['name']
        cell_phone = request.form['cell_phone']

        item = user(\
                    id = id,
                    permission = 'user',
                    cell_phone = cell_phone,
                    email = email,
                    name = name,
                    password=password)

        mydb = DB()
        if not mydb.sign_up(item):
            del mydb
            return render_template('alert_msg.html', msg="회원가입 실패")
        del mydb
    return redirect(url_for('.index'))
def create(category):
    return_data = dict()
    return_data['status'] = "error"
    return_data['msg'] = ''
    if request.method == "POST":
        if session:
            data = dict()
            if 'notice' in request.form.keys():
                data['notice'] = True
            else:
                data['notice'] = False
            data['id'] = session['id']
            data['title'] = request.form['subject']
            data['contents'] = request.form['content']
            data['category'] = category
            data['hits'] = 0
            data['uuid'] = str(uuid.uuid4())
            mydb = DB()
            if mydb.create_board(data):
                files = request.files.getlist('file')
                if files:
                    error = f_upload(data['uuid'], files)
                    if error:
                        mydb.delete_board(data['uuid'])
                        return_data['msg'] = error
                    else:
                        return_data['status'] = "ok"
                    del mydb
                else:
                    del mydb
                    return_data['status'] = "ok"
            else:
                del mydb
                return_data['status'] = "error"
        else:
            return_data['status'] = "permission error"
    return jsonify(return_data)
def board_modify_form(uuid):
    db = DB()
    rows = db.get_board(uuid)
    if session:
        if session['id'] == rows['id']:

            db = DB()
            rows = db.get_board(uuid)
            db = files_db()
            files = db.get_files(uuid)
            return render_template('board_modify.html',
                                   session=session,
                                   data=rows,
                                   files=files)
    return render_template("alert_msg.html", msg="잘못된 접근 입니다.")
def board_show(uuid, page):
    db = DB()
    rows = db.get_board(uuid)
    del db
    mydb = files_db()
    downs = mydb.get_files(uuid)
    del mydb
    db = Comments_DB()
    total_cnt = db.get_comment_cnt(uuid)

    per_page = 10
    pagination = Pagination(page, per_page=per_page, total_count=total_cnt)

    if page != 1:
        offset = per_page * (page - 1)
    else:
        offset = 0

    comments = db.get_comments_list(per_page, offset, uuid)

    if request.method == "POST":
        hits = request.form['hits']
        db.hits_add(uuid, hits)
        rows['hits'] = hits
        del db

        if session:
            if session['id'] == rows['id']:
                return render_template("board_show.html",
                                       session=session,
                                       downs=downs,
                                       rows=rows,
                                       pagination=pagination,
                                       comments=comments,
                                       user_check=True)
    return render_template("board_show.html",
                           rows=rows,
                           pagination=pagination,
                           downs=downs,
                           comments=comments)