Beispiel #1
0
    def post(self):
        try:
            uuid = request.json['uuid']
            item_id = request.json['item_id']
        except KeyError or TypeError:
            return {'msg': 'valueless'}, 400

        query_select_user_info = 'select point from user where uuid = %s'
        curs.execute(query_select_user_info, uuid)
        point = curs.fetchone()['point']

        query_select_item_info = 'select point from item where item_id = %s'
        curs.execute(query_select_item_info, item_id)
        item_point = curs.fetchone()['point']

        if point < item_point:
            return {'msg': 'low_point'}, 403

        query_update_user_point = 'update user set point = point - %s where uuid = %s'
        curs.execute(query_update_user_point, (item_point, uuid))

        query_update_item_info = 'update item set status = %s where item_id = %s'
        curs.execute(query_update_item_info, (uuid, item_id))
        conn.commit()

        return {'msg': 'success'}, 200
Beispiel #2
0
    def post(self):
        try:
            permission = request.json['permission']
            item_id = request.json['item_id']
        except KeyError or TypeError:
            return {'msg': 'valueless'}, 400

        if permission != 9:
            return {'msg': 'permission_denied'}, 403

        query_select_item_info = 'select point, status from item where item_id = %s'
        curs.execute(query_select_item_info, item_id)
        item_infos = curs.fetchone()
        point = item_infos['point']
        uuid = item_infos['status']

        if uuid == 0 or uuid == -1:
            return {'msg': 'invalid_access'}, 403

        query_select_user_info = 'select point from user where uuid = %s'
        curs.execute(query_select_user_info, uuid)
        existing_point = curs.fetchone()['point']

        if point > existing_point:
            return {'msg': 'low_point'}, 403

        query_update_item_info = 'update item set status = -1 where item_id = %s'
        curs.execute(query_update_item_info, item_id)

        conn.commit()

        return {'msg': 'success'}, 200
Beispiel #3
0
    def get(self):
        try:
            item_uuid = request.args['uuid']
        except KeyError or TypeError:
            return {'msg': 'value_skipped'}, 400

        query_select_item = 'select user as u, title, content, cate, main_img, price, desired_item, write_time ,' \
                            ' (select name, tell, zonecode, address from user where uuid = u) from item where uuid = %s'
        curs.execute(query_select_item, item_uuid)
        detail_item = curs.fetchone()

        refined_detail_item = detail_item
        return refined_detail_item, 200
Beispiel #4
0
    def post(self):
        try:
            tell = request.json['tell']
            email = request.json['email']
        except KeyError or TypeError:
            return {'msg': 'value_skipped'}, 400

        query_select_user_info = 'select tell from user where tell = %s'
        curs.execute(query_select_user_info, tell)
        existing_user_tell = curs.fetchone()
        if existing_user_tell:
            return {'msg': 'existing_telephone'}, 406

        query_select_user_info = 'select email from user where email = %s'
        curs.execute(query_select_user_info, email)
        existing_user_email = curs.fetchone()
        if existing_user_email:
            return {'msg': 'existing_email'}, 406

        smtp_connect = smtplib.SMTP('smtp.gmail.com', 587)
        smtp_connect.starttls()
        smtp_connect.login('*****@*****.**', 'epzuyfapmvrvxfib')

        cert_num = ''
        for i in range(6):
            cert_num += str(random.randrange(0, 10))

        msg = MIMEText(f'인증번호 : {cert_num}\n인증번호는 10분이 지나면 만료됩니다.')
        msg['Subject'] = 'RE:MARKET에서 발송한 인증번호입니다.'

        smtp_connect.sendmail('*****@*****.**', email, msg.as_string())\

        smtp_connect.quit()

        return {
            'cert_num': cert_num,
            'timestamp': datetime.now().timestamp()
        }, 200
Beispiel #5
0
    def post(self):
        try:
            tel = request.json['tel']
            pw = request.json['pw']
        except KeyError or TypeError:
            return {'msg': 'valueless'}, 400

        query_select_user_info = 'select uuid, permission from user where tel = %s and pw = %s'
        curs.execute(query_select_user_info, (tel, pw))
        existing_user_info = curs.fetchone()

        if not existing_user_info:
            return {'msg': 'invalid_account'}, 401

        return existing_user_info, 200
Beispiel #6
0
    def patch(self):
        try:
            uuid = request.json['uuid']
            pw = request.json['pw']
        except KeyError or TypeError:
            return {'msg': 'valueless'}, 400

        query_select_user_info = 'select pw from user where uuid = %s and pw = %s'
        curs.execute(query_select_user_info, (uuid, pw))

        if not curs.fetchone():
            return {'msg': 'invalid_pw'}, 403

        try:
            name = request.json['name']
        except KeyError or TypeError:
            name = None
        try:
            change_pw = request.json['change_pw']
        except KeyError or TypeError:
            change_pw = None
        try:
            profile_img = request.json['profile_img']
        except KeyError or TypeError:
            profile_img = None

        if not name and not change_pw and not profile_img:
            return {'msg': 'invalid_request'}, 400

        query_update_user_info = 'update user set '

        if name:
            query_update_user_info += f"name = '{name}', "

        if change_pw:
            query_update_user_info += f"pw = '{change_pw}', "

        if profile_img:
            query_update_user_info += f"profile_img = '{profile_img}', "

        query_update_user_info = query_update_user_info[:-2] + ' where uuid = %s'
        curs.execute(query_update_user_info, uuid)
        conn.commit()

        return {'msg': 'success'}, 200
Beispiel #7
0
    def post(self):
        try:
            tell = request.json['tell']
            pw = request.json['pw']
        except KeyError or TypeError:
            return {'msg': 'value_skipped'}, 400

        query_select_user_info = 'select tell, pw, uuid from user where tell = %s and pw = %s'
        curs.execute(query_select_user_info, (tell, pw))
        existing_user_info = curs.fetchone()

        if not existing_user_info:
            return {'msg': 'invalid_info'}, 401

        identity = {'uuid': existing_user_info['uuid']}

        return {
            'access_token': create_access_token(identity=identity),
            'refresh_token': create_refresh_token(identity=identity)
        }, 200
Beispiel #8
0
    def post(self):
        try:
            tel = request.json['tel']
            pw = request.json['pw']
            name = request.json['name']
        except KeyError or TypeError:
            return {'msg': 'valueless'}, 400

        query_select_user_info = 'select uuid from user where tel = %s'
        curs.execute(query_select_user_info, tel)
        existing_user = curs.fetchone()

        if existing_user:
            return {'msg': 'existing_user'}, 403

        query_insert_user_info = 'insert into user (tel, pw, name, profile_img) values(%s, %s, %s, %s)'
        curs.execute(query_insert_user_info,
                     (tel, pw, name, BASIC_PROFILE_IMAGE))
        conn.commit()

        return {'msg': 'success'}, 200
Beispiel #9
0
    def patch(self):
        identity = get_jwt_identity()

        try:
            pw = request.json['pw']
        except KeyError or TypeError:
            return {'msg': 'value_skipped'}, 400
        try:
            change_pw = request.json['change_pw']
        except KeyError or TypeError:
            change_pw = None
        try:
            name = request.json['name']
        except KeyError or TypeError:
            name = None
        try:
            profile_img = request.json['profile_img']
        except KeyError or TypeError:
            profile_img = None

        query_select_info = 'select pw from user where pw = %s'
        curs.execute(query_select_info, pw)
        present_pw = curs.fetchone()
        if not present_pw:
            return {'msg': 'pw_incorrect'}, 401

        if change_pw:
            query_update_info = 'update user set pw = %s where uuid = %s'
            curs.execute(query_update_info, (change_pw, identity['uuid']))

        if name:
            query_update_info = 'update user set name = %s where uuid = %s'
            curs.execute(query_update_info, (name, identity['uuid']))

        if profile_img:
            query_update_info = 'update user set profileimg = %s where uuid = %s'
            curs.execute(query_update_info, (profile_img, identity['uuid']))

        conn.commit()
        return {'msg': 'success'}, 200
Beispiel #10
0
    def get(self):
        try:
            uuid = request.args['uuid']
        except KeyError or TypeError:
            return {'msg': 'valueless'}, 400

        query_select_user_info = 'select tel, name, profile_img, point from user where uuid = %s'
        curs.execute(query_select_user_info, uuid)
        user_info = curs.fetchone()

        query_select_item_info = 'select title, main_img, item_id, write_time from item where status = %s'
        curs.execute(query_select_item_info, uuid)
        item_infos = curs.fetchall()

        refined_item_infos = {}

        cnt = 0
        for item_info in item_infos:
            refined_item_infos[cnt] = item_info
            cnt += 1

        return {'user_info': user_info, 'list': refined_item_infos}
Beispiel #11
0
    def get(self):
        identity = get_jwt_identity()

        query_select_user_info = 'select tell, name, email, zonecode, address, detailaddress from user where uuid = %s'
        curs.execute(query_select_user_info, identity['uuid'])
        existing_user_info = curs.fetchone()

        query_select_item_info = 'select uuid, status, cate, title, main_img, desired_item, write_time ' \
                                 'from item where user = %s order by write_time desc'
        curs.execute(query_select_item_info, identity['uuid'])
        items = curs.fetchall()

        item_info = {}

        cnt = 0
        for item in items:
            item['write_time'] = item['write_time'].strftime(
                '%Y-%m-%d:%H:%M:%S')
            item_info[cnt] = item
            cnt += 1

        return {'user': existing_user_info, 'item': item_info}
Beispiel #12
0
    def delete(self):
        identity = get_jwt_identity()

        try:
            pw = request.json['pw']
        except KeyError or TypeError:
            return {'msg': 'value_skipped'}, 400

        query_select_user_info = 'select pw from user where pw = %s'
        curs.execute(query_select_user_info, pw)
        existing_password = curs.fetchone()

        if not existing_password:
            return {'msg': 'invalid_pw'}, 401

        query_delete_user_info = 'delete from user where uuid = %s'
        curs.execute(query_delete_user_info, identity['uuid'])

        query_delete_item_info = 'delete from item where user = %s'
        curs.execute(query_delete_item_info, identity['uuid'])
        conn.commit()

        return {'msg': 'bye'}, 200