示例#1
0
def remove_post():
    p_id = request.values.get("p_id")
    #삭제전에 삭제하려는 글이 현재 로그인한 사용자가 작성한 글인지 검증 필요

    cursor = db.get_conn().cursor()
    sql = "select p_date, board_id from test_post where p_id = %s" % (p_id)
    cursor.execute(sql)
    result = cursor.fetchone()
    cursor.close
    if result[0].replace('/', '') == current_user.user_id:
        print "writer try modify, board_id:" + str(result[1])
        sql = "delete from test_post where p_id = %s" % (p_id)
        print "sql : %s" % (sql)
        con = db.get_conn()
        cursor = con.cursor()
        result2 = cursor.execute(sql)
        cursor.close()
        con.commit()
        print "삭제 결과 : " + str(result2)
        if result[1] == 1:
            flash(p_id + "번 게시글이 삭제되었습니다.")
            return redirect(url_for("board_view.common_board"))
        elif result[1] == 2:
            flash(p_id + "번 게시글이 삭제되었습니다.")
            return redirect(url_for("board_view.member_board"))
    else:
        flash("잘못된 접근 입니다.")
        return redirect(url_for("main_view.index"))
示例#2
0
def api_login():
    id = request.values.get('id') if "id" in request.form else None
    pw = request.values.get('pw') if "pw" in request.form else None
    logger.info("id : "+id)

    cursor = db.get_conn().cursor()    # cursor 객체를 얻는다.
    cursor.callproc('get_user_by_id', (id,))    #argument 1개일 때도 ,하나 붙여줘야 제대로 인식함.
    r = cursor.fetchall()
    cursor.close()
    logger.info( "login user info : " + str(r))
    if r:
        #id 존재
        logger.info("pw 체크) DB에 있는 hashedpw: %s, 입력한pw:%s,  check_password_hash():%s" % (r[0][4], pw, check_password_hash(str(r[0][4]), pw)))
        #if r[0][4] == pw:
        if check_password_hash(r[0][4], pw):

            # 아이디와 비밀번호가 일치하면 로그인 처리
            # 직접 정의한 'User'클래스의 객체를 인자로 넘겨준다.
            login_user(User(id, name=r[0][2], auth=True))

            flash("로그인 되었습니다.")
            return redirect(url_for('main_view.index'))
        else:
            flash("아이디 또는 비밀번호를 확인하세요.")
            return redirect(url_for('auth_view.login'))
    else:
        flash("아이디 또는 비밀번호를 확인하세요.")
        return redirect(url_for('auth_view.login'))
示例#3
0
def insert_post():

    data = request.values
    logger.info("form data : " + str(data))
    p_title = data.get('p_title') if data.get('p_title') else None
    p_body = data.get('p_body') if data.get('p_title') else None
    p_date = datetime.now().strftime('%Y-%m-%d %H:%M')
    p_writer = data.get('p_writer') if data.get('p_writer') else None
    b_id = None
    if data.get('b_type') == 'common_board/':
        b_id = 1
    elif data.get('b_type') == 'member_board/':
        b_id = 2

    logger.info("post insert : " + str(p_title) + ", " + str(p_body) + ", " +
                str(p_date) + ", " + str(p_writer) + ", " + str(b_id))

    cursor = db.get_conn().cursor()
    cursor.callproc('insert_post',
                    (p_title, p_body, p_date, p_writer, b_id, 0))
    cursor.execute('select @_insert_post_5')
    result = cursor.fetchone()
    logger.info("post insert result : " + str(result[0]))
    if result[0] == 0:
        flash("글이 등록 되었습니다.")
        if b_id == 1:
            return redirect(url_for("board_view.common_board"))
        elif b_id == 2:
            return redirect(url_for("board_view.member_board"))
    else:
        flash("글 등록과정에서 오류가 발생하였습니다.")
        return redirect(url_for("post_view.post_form"))
示例#4
0
def modify_post():
    p_id = request.values.get("p_id")
    # 수정하려는 글이 현재 로그인한 사용자가 작성한 글인지 검증 필요

    data = {}
    cursor = db.get_conn().cursor()
    sql = "select * from test_post where p_id = %s" % (p_id)
    cursor.execute(sql)
    result = cursor.fetchone()
    cursor.close

    print str(result)
    data['title'] = result[1]
    data['body'] = result[2]
    data['p_id'] = result[0]

    if str(result[3]).replace('/', '') == current_user.user_id:
        print "writer try modify, board_id:" + str(result[1])
        if result[5] == 1:
            return render_template('/post/modify_post.html',
                                   data=data,
                                   board_name="common_board")
        elif result[5] == 2:
            return render_template('/post/modify_post.html',
                                   data=data,
                                   board_name="member_board")
    else:
        flash("잘못된 접근 입니다.")
        return redirect(url_for("main_view.index"))
示例#5
0
def post_veiw_func(p_id=None):

    cursor = db.get_conn().cursor()
    cursor.execute("select * from test_post where p_id = %s" % (p_id))
    result = cursor.fetchone()
    print str(result)

    return render_template("/post/view_post.html", post_data=result)
示例#6
0
def get_common_post_list():
    param = request.values
    per_page = param.get('length')

    return_data = {}
    return_data['draw'] = int(param.get('draw'))
    #DB와 datatables libaray처리

    cursor = db.get_conn().cursor()
    cursor.callproc("get_total_post_cnt", (1, ))
    result = cursor.fetchone()
    cursor.close()
    return_data['recordsTotal'] = result[0]
    return_data['recordsFiltered'] = result[0]

    cursor = db.get_conn().cursor()
    #cursor.callproc("select_post_list", (param.get('start'), per_page, 1))

    sql = "select p_id, p_title, p_body, p_date, p_writer, board_id from test_post where board_id = %s order by %s %s limit %s,%s" % (
        "1", param.get('columns[' + param.get('order[0][column]') + '][data]'),
        param.get('order[0][dir]'), param.get('start'), per_page)
    print param.get('columns[' + param.get('order[0][column]') + '][data]')
    print sql
    cursor.execute(sql)
    result = cursor.fetchall()
    cursor.close()

    post_list = []
    for row in result:
        post_list.append({
            param.get('columns[0][data]'):
            row[0],
            param.get('columns[1][data]'):
            row[1],
            param.get('columns[2][data]'):
            str(row[3]).replace("/", ""),
            param.get('columns[3][data]'):
            row[4]
        })
    #print str(post_list)
    return_data['data'] = post_list

    return make_response(jsonify(return_data))
示例#7
0
def load_user(id):
        logger.info("load_user(), session:"+str(session))

        cursor = db.get_conn().cursor()
        cursor.callproc('get_user_by_id', (id,))  # argument 1개일 때도 ,하나 붙여줘야 제대로 인식함.
        r = cursor.fetchall()
        cursor.close()

        if r : #id가 존재
            return User(id, name=r[0][2], auth=True)
        else:
            return None
示例#8
0
def modify_post_action():
    data = request.values

    con = db.get_conn()
    cursor = con.cursor()
    sql = "update test_post set p_title='%s', p_body='%s' where p_id = %s" % (
        str(data.get('p_title')), data.get('p_body'), str(
            data.get('p_id')).replace('/', ''))
    print sql
    rr = cursor.execute(sql)
    print "modify result :" + str(rr)
    cursor.close()
    con.commit()

    print "board type : %s" % (str(data.get('b_type')))
    board_type = str(data.get('b_type')).replace("/", "")
    flash(str(data.get('p_id')) + "번 글이 수정되었습니다.")
    if board_type == 'common_board':
        return redirect(url_for("board_view.common_board"))
    elif board_type == 'member_board':
        return redirect(url_for("board_view.member_board"))
示例#9
0
def register_action():
    form = request.form
    id = request.values.get('id') if 'id' in request.values else None
    name = request.values.get('name') if 'name' in request.values else None
    email = request.values.get('email') if 'email' in request.values else None
    pw = request.values.get('pw') if 'pw' in request.values else None
    pw_check = request.values.get(
        'pw_check') if 'pw_check' in request.values else None

    cursor = db.get_conn().cursor()
    hashed_pw = generate_password_hash(pw, salt_length=9)
    cursor.callproc('insert_user', (id, name, email, hashed_pw, 0))
    cursor.execute('select @_insert_user_4')
    result = cursor.fetchone()
    cursor.close()
    logger.info("insert result : " + str(result))
    if int(result[0]) == 0:
        flash("회원가입 되었습니다. 로그인 하세요.")
        return redirect(url_for('auth_view.login'))
    flash("이미 가입된 아이디 입니다.")
    return redirect(url_for('register_view.reigster_form'))