Exemplo n.º 1
0
    def wrapper(*args, **kwargs):
        access_token = request.headers.get('AUTHORIZATION', None)

        if access_token:
            try:

                payload = jwt.decode(access_token, SECRET_KEY, ALGORITHM)
                account_id = payload['account_id']
                connection = connect_db()
                account_dao = AccountDao()
                account = account_dao.account_identifier(account_id, connection)
                if not account:
                    return jsonify({'MESSAGE': 'account_nonexistant'}), 404
                if account['is_active'] == 0:
                    return jsonify({'MESSAGE': 'account_not_active'}), 400
                g.token_info = {
                    'account_id'      : account_id,
                    'account_type_id' : account['account_type_id'],
                    'seller_id'       : account['seller_id']}
                return func(*args, **kwargs)
            except Error as e:
                return Jsonify({'MESSAGE': 'DB_error'}), 400
            except jwt.InvalidTokenError:
                return jsonify({'MESSAGE': 'invalid_token'}), 401
            except not connection:
                return jsonify({'MESSAGE': 'no_db_connection'}), 400
        return jsonify({'MESSAGE': 'invalid_token'}), 401
 def filter_seller(self, filter_info, user, connection):
     account_dao = AccountDao()
     account_type_id = user.get('account_type_id')
     filter_info['offset'] = (filter_info['page'] *
                              filter_info['limit']) - filter_info['limit']
     if account_type_id != 1:
         raise Exception('NO_AUTH')
     seller_list = account_dao.list_seller(filter_info, connection)
     if not seller_list:
         raise Exception('NO_MATCHES')
     for items in seller_list:
         status = {'status_id': items['seller_status_id']}
         actions = account_dao.get_seller_actions(status, connection)
         items['actions'] = actions
     return seller_list
Exemplo n.º 3
0
    def get_filter_options(self, connection, order_status_id):
        order_dao = OrderDao()
        account_dao = AccountDao()
        seller_types = None

        # 마스터일 경우 셀러속성 리스트도 함께 보내줌.
        if g.token_info['account_type_id'] == 1:
            seller_types = account_dao.get_seller_types(connection)

        # 주문상태 변경 버튼 가져오기
        order_actions = order_dao.get_order_actions_by_status(
            connection, order_status_id)

        filter_options = {
            "seller_types": seller_types,
            "order_actions": order_actions
        }
        return filter_options
    def signin(self, login_info, connection):
        account_dao = AccountDao()
        account = account_dao.find_account(login_info, connection)

        if account:
            if account['is_active'] == 0:
                raise Exception('ACCOUNT_NOT_ACTIVE')
            if bcrypt.checkpw(login_info['password'].encode('utf-8'),
                              account['password'].encode('utf-8')):
                token = jwt.encode(
                    {
                        'account_id': account['account_id'],
                        'expiration':
                        str(datetime.utcnow() + timedelta(hours=1))
                    },
                    SECRET_KEY,
                    algorithm=ALGORITHM)
                return jsonify({'AUTHORIZATION': token}), 200
            else:
                raise Exception('CHECK_LOGIN')
        else:
            raise Exception('ACCOUNT_DOES_NOT_EXIST')
 def change_status(self, status, user, connection):
     account_dao = AccountDao()
     actions = account_dao.get_seller_actions_two(status, connection)
     if not actions:
         raise Exception('Invalid action for status')
     new_status_id = actions[0]['new_status_id']
     seller_id = status['seller_id']
     change_info = {'id': seller_id, 'seller_status': new_status_id}
     account_dao.update_seller_status(change_info, connection)
     seller_info = {'id': seller_id}
     account_info = account_dao.get_seller_info(seller_info, connection)
     account_info['seller_id'] = account_info.pop('id')
     account_info['editor_id'] = user['account_id']
     account_dao.create_seller_log(account_info, connection)
     return actions
 def change_seller_info(self, change_info, user, connection):
     account_dao = AccountDao()
     if change_info['seller_id'] != user['account_id'] and user[
             'account_type_id'] == 2:
         raise Exception('NO_AUTH')
     change_info['id'] = change_info.pop('seller_id')
     account_dao.update_seller(change_info, connection)
     seller_info = change_info
     account_info = account_dao.get_seller_info(seller_info, connection)
     account_info['seller_id'] = account_info.pop('id')
     account_info['editor_id'] = user['account_id']
     account_dao.create_seller_log(account_info, connection)
     return jsonify({'MESSAGE': 'SUCCESS'}), 200
    def signup_account(self, account_info, connection):
        account_dao = AccountDao()

        is_existing_email = account_dao.find_account(account_info, connection)
        if is_existing_email:
            raise Exception('EXISTING_EMAIL')

        bcrypt_password = bcrypt.hashpw(
            account_info['password'].encode('utf-8'), bcrypt.gensalt())
        account_info['password'] = bcrypt_password

        signed_up_id = account_dao.create_account(account_info, connection)
        account_info['account_id'] = signed_up_id
        account_info['editor_id'] = signed_up_id
        account_info['is_active'] = 1
        account_dao.create_account_log(account_info, connection)
        return signed_up_id
 def change_account_info(self, change_info, user, connection):
     account_dao = AccountDao()
     if change_info['id'] != user['account_id'] and user[
             'account_type_id'] == 2:
         raise Exception('NO_AUTH')
     if change_info['password']:
         bcrypt_password = bcrypt.hashpw(
             change_info['password'].encode('utf-8'), bcrypt.gensalt())
         change_info['password'] = bcrypt_password
     change = account_dao.update_account_info(change_info, connection)
     if not change:
         raise Exception('NO_CHANGE')
     get_account_info = account_dao.get_account_info(
         change_info, connection)
     get_account_info['editor_id'] = user['account_id']
     account_dao.create_account_log(get_account_info, connection)
     return jsonify({'MESSAGE': 'SUCCESS'}), 200
    def signup_seller(self, account_info, connection):
        account_dao = AccountDao()

        is_existing_email = account_dao.find_account(account_info, connection)
        if is_existing_email:
            raise Exception('EXISTING_EMAIL')

        is_kr_name_taken = account_dao.find_seller_name_kr_exist(
            account_info, connection)
        if is_kr_name_taken:
            raise Exception('EXISTING_KR_NAME')

        is_en_name_taken = account_dao.find_seller_name_en_exist(
            account_info, connection)
        if is_en_name_taken:
            raise Exception('EXISTING_EN_NAME')

        bcrypt_password = bcrypt.hashpw(
            account_info['password'].encode('utf-8'), bcrypt.gensalt())
        account_info['password'] = bcrypt_password

        signed_up_account = account_dao.create_account(account_info,
                                                       connection)
        account_info['account_id'] = signed_up_account
        account_info['editor_id'] = signed_up_account
        account_info['is_active'] = 1
        account_info['profile_pic_url'] = ''
        account_info['short_desc'] = ''
        account_info['long_desc'] = ''
        account_info['close_time'] = ''
        account_info['open_time'] = ''
        account_info['delivery_policy'] = ''
        account_info['return_policy'] = ''
        account_info['zip_code'] = ''
        account_info['address_1'] = ''
        account_info['address_2'] = ''
        account_info['is_open_weekend'] = ''

        account_dao.create_account_log(account_info, connection)

        signed_up_seller = account_dao.create_seller(account_info, connection)
        account_info['seller_id'] = signed_up_seller

        account_dao.create_seller_log(account_info, connection)

        return signed_up_seller