Пример #1
0
def sellHand_show(fc):

    #check if FC exist in DB

    result = Seller.select().where(Seller.choice == "Cabin",
                                   Seller.flightcode == fc)

    if result:

        seller_list = Seller.select().where(Seller.choice == "Cabin",
                                            Seller.flightcode == fc,
                                            Seller.sold == False,
                                            Seller.buyer_id.is_null(True),
                                            Seller.sold.is_null(False))

        ranNum = random.randint(0, seller_list.count())
        ranNum -= 1

        if ranNum < 0:
            ranNum = 0
        else:
            ranNum = ranNum

        return render_template('sellHand/sellHand_market.html',
                               seller=seller_list[ranNum])

    else:
        return render_template('sellHand/sellHand.html')
Пример #2
0
def refresh_token():
    if not request.data:
        return INVALID_PARAM()

    db = g._db
    obj = json.loads(request.data)
    refresh_token = obj["refresh_token"]
    rt = token.RefreshToken()
    if not rt.load(g.rds, refresh_token):
        return INVALID_REFRESH_TOKEN()

    seller = Seller.get_seller(db, rt.user_id)
    if not seller:
        return INVALID_REFRESH_TOKEN()

    access_token = login_gobelieve(int(rt.user_id), seller['name'],
                                   config.APP_ID, config.APP_SECRET)

    if not access_token:
        return CAN_NOT_GET_TOKEN()

    seller = Seller.get_seller(db, rt.user_id)
    tok = create_token(3600, False)
    tok["refresh_token"] = obj["refresh_token"]
    tok["access_token"] = access_token
    tok['uid'] = rt.user_id
    tok['store_id'] = seller['store_id']
    tok['name'] = seller['name']

    t = token.AccessToken(**tok)
    t.user_id = rt.user_id
    t.save(g.rds)

    return make_json_response(tok, 200)
Пример #3
0
def sellHand_show(fc):

    #check if FC exist in DB
    result = Seller.select().where(Seller.choice == "Cabin",
                                   Seller.flightcode == fc,
                                   Seller.sold == False)

    if result:

        if current_user.is_authenticated:

            seller_list = Seller.select().where(
                Seller.choice == "Cabin", Seller.flightcode == fc,
                Seller.sold == False, Seller.buyer_id.is_null(True),
                Seller.sold.is_null(False) &
                (Seller.seller_id != current_user.id))

            ranNum = random.randint(0, seller_list.count())
            ranNum -= 1

            if ranNum < 0:
                ranNum = 0
            else:
                ranNum = ranNum

            return render_template('sellHand/sellHand_market.html',
                                   seller=seller_list[ranNum],
                                   result=result[ranNum].id)

    else:
        return render_template('homepage2.html',
                               noflight="No Available Sellers")
Пример #4
0
def post(odata):
    curr_session = db_session()
    tobj = CrudObj(**odata)
    curr_session.add(tobj)
    curr_session.commit()
    tobjstr = tobj.dump()
    return tobjstr, 201  #note: tobj.dump() here causes {} return, not sure why?!?
Пример #5
0
def user_seller_create():
    T = {}
    helpers.template.get_user(T=T, path=request.path)
    if not "user" in T:
        flash(u'ログインしてください', category='warning')
        return redirect(url_for('index'))

    p = re.compile(r'^[a-z0-9]{1}[a-z0-9_]{2,31}$')
    if not p.match(request.form['name']):
        flash(u'seller名は半角英数+"_"で構成される32文字以内の文字列です',
              category='warning')
        return redirect(url_for('user_index'))

    #
    # sellerが存在しないかチェック
    #
    user = T["user"].user_id()
    name = request.form['name']
    exist_seller = SellerAndUsers.gql('WHERE seller = :seller',
                                      seller=name,
                                      keys_only=True).get()
    if exist_seller:
        flash(u'そのsellerアカウントはすでに使用されています', category="warning")
        return redirect(url_for('user_index'))

    #
    # 上限Overしてないかチェック
    #
    exist_rec = SellerAndUsers.gql('WHERE user = :user',
                                   user=user,
                                   keys_only=True).fetch(3)
    if len(exist_rec) == 3:
        flash(u'1ユーザ3店舗までです', category="warning")
        return redirect(url_for('user_index'))

    new_seller_and_users = SellerAndUsers(
        key_name = name + "-" + user,
        seller   = name,
        user     = user,
        grant    = 1, # owner
        status   = 0, # created
        )
    new_seller_and_users.put()

    new_seller = Seller(
        key_name = name,
        name     = name,
        title    = request.form['title'],
        currency = int(request.form['currency']),
        status   = 0, # hidden
        )
    new_seller.put()

    flash(u'新規sellerを申請しました', category="success")
    return redirect(url_for('user_index'))
Пример #6
0
def availability():
    flightcode = request.form.get('flightcode')
    time = request.form.get('time')
    date = request.form.get('date')
    now = str(datetime.datetime.now())

    if current_user.is_authenticated:

        available = Seller.select().where(
            (Seller.flightcode == flightcode) & (Seller.departure_date == date)
            & (Seller.departure_time == time) & (Seller.sold == False)
            & (Seller.choice == 'Luggage')
            & (Seller.seller_id != current_user.id))
        d = re.search('\d+-\d+-\d+', now)
        if d:
            date = d.group(0)

        t = re.search('\d+:\d+:\d+', now)
        if t:
            time = t.group(0)

        list_of_sellers = Seller.select().where(
            (Seller.departure_date >= date) & (Seller.sold != True)
            & (Seller.choice == 'Luggage')
            & (Seller.seller_id != current_user.id))

    else:

        available = Seller.select().where((Seller.flightcode == flightcode)
                                          & (Seller.departure_date == date)
                                          & (Seller.departure_time == time)
                                          & (Seller.sold == False)
                                          & (Seller.choice == 'Luggage'))
        d = re.search('\d+-\d+-\d+', now)
        if d:
            date = d.group(0)

        t = re.search('\d+:\d+:\d+', now)
        if t:
            time = t.group(0)

        list_of_sellers = Seller.select().where((Seller.departure_date >= date)
                                                & (Seller.sold != True)
                                                & (Seller.choice == 'Luggage'))

    return render_template('seller/marketplace.html',
                           available=available,
                           list_of_sellers=list_of_sellers)
Пример #7
0
def seller_product(seller, code):
    T = {"sellername":seller, "code":code}
    ret = seller_tool_check_login(seller, T)

    s = Seller.get_by_key_name('%s' % seller)
    if not 2:
        abort(404)

    p = Product.get_by_key_name('%s-%s' % (seller,code))
    if not p:
        abort(404)

    T['seller']  = s
    T['product'] = p
    host = "http://localhost:5000/"

    if p.image1:
        T['imageurl1'] = "%s%s" % (host,
                                   get_image_path(seller,code,1,300,300,p.image1))
    else:
        T['imageurl1'] = 'http://placehold.it/300x300'

    if p.image2:
        T['imageurl2'] = "%s%s" % (host,
                                   get_image_path(seller,code,2,120,120,p.image2))

    if p.image3:
        T['imageurl3'] = "%s%s" % (host,
                                   get_image_path(seller,code,3,120,120,p.image3))

    T['cart_url'] = url_for('cart_add', seller=seller, code=p.code)
    return render_template('seller_product.html', T=T)
Пример #8
0
def login():
    username = request.form.get('username')
    password = request.form.get('password')
    if not username:
        return render_template_string(error_html, error="用户名称为空")
    if not password:
        return render_template_string(error_html, error="密码为空")

    password_md5 = md5.new(password).hexdigest()
    db = g._db

    uid = None
    store_id = None
    seller = Seller.get_seller_with_number(db, username)

    if check_seller_password(seller, password):
        uid = seller['id']
        store_id = seller['store_id']
    else:
        try:
            seller_id = int(username)
            seller = Seller.get_seller(db, seller_id)
            if check_seller_password(seller, password):
                uid = seller['id']
                store_id = seller['store_id']
        except ValueError:
            pass

    if not uid:
        return render_template_string(error_html, error="非法的用户名/密码")

    name = seller.get('name')
    if not name:
        name = ""
    access_token = login_gobelieve(uid, name, config.APP_ID, config.APP_SECRET)

    if not access_token:
        return render_template_string(error_html, error="登录失败")

    response = flask.make_response(redirect('/'))

    response.set_cookie('token', access_token)
    response.set_cookie('store_id', str(seller['store_id']))
    response.set_cookie('uid', str(seller['id']))
    return response
Пример #9
0
def login():
    username = request.form.get('username')
    password = request.form.get('password')
    if not username:
        return render_template_string(error_html, error="用户名称为空")
    if not password:
        return render_template_string(error_html, error="密码为空")

    password_md5 = md5.new(password).hexdigest()
    db = g._db

    uid = None
    store_id = None
    seller = Seller.get_seller_with_number(db, username)

    if check_seller_password(seller, password):
        uid = seller['id']
        store_id = seller['store_id']
    else:
        try:
            seller_id = int(username)
            seller = Seller.get_seller(db, seller_id)
            if check_seller_password(seller, password):
                uid = seller['id']
                store_id = seller['store_id']
        except ValueError:
            pass

    if not uid:
        return render_template_string(error_html, error="非法的用户名/密码")

    name = seller.get('name')
    if not name:
        name = ""
    access_token = login_gobelieve(uid, name, config.APP_ID, config.APP_SECRET)

    if not access_token:
        return render_template_string(error_html, error="登录失败")

    response = flask.make_response(redirect('/'))

    response.set_cookie('token', access_token)
    response.set_cookie('store_id', str(seller['store_id']))
    response.set_cookie('uid', str(seller['id']))
    return response
Пример #10
0
def index():
    if request.cookies.get('token') and request.cookies.get('uid'):
        uid = request.cookies.get('uid')
        uid = int(uid)
        seller = Seller.get_seller(g._db, uid)
        return render_template('customer_support/chat.html', host=config.HOST, name=seller['name'],
                               apiURL=config.APIURL)
    else:
        return render_template('customer_support/index.html')
Пример #11
0
 def post(self, request):
     # 注册
     username = request.json.get("username")
     password = request.json.get("password")
     nickname = request.json.get("nickname")
     account_type = request.json.get("account_type")
     if not all([username, password, nickname, account_type]):
         return JsonErrorResponse("username, password, nickname, account_type are needed", 400)
     new_seller = Seller(
         username=username,
         password=password,
         nickname=nickname,
         account_type=account_type
     )
     try:
         new_seller.save()
     except Exception, e:
         print e
         return JsonErrorResponse("Fail:" + e.message)
Пример #12
0
def index():
    if request.cookies.get('token') and request.cookies.get('uid'):
        uid = request.cookies.get('uid')
        uid = int(uid)
        seller = Seller.get_seller(g._db, uid)
        return render_template('customer_support/chat.html',
                               host=config.HOST,
                               name=seller['name'],
                               apiURL=config.APIURL)
    else:
        return render_template('customer_support/index.html')
Пример #13
0
def confirmBuy():

    seller_id = request.args['seller_id']
    seller = Seller.get(Seller.seller_id == seller_id)
    seller.buyer_id = current_user.id
    seller.sold = True

    if seller.save():
        flash('Purchase Successful!')
        return redirect(url_for('braintree.new_checkout'))
    else:
        flash('Purchase Failed!')
        return render_template('sellHand/sign_in.html')
Пример #14
0
def userprofile(id):
    int_id = int(id)
    user = User.get(User.id == int_id)
    username = user.username
    ic_name = user.ic_name
    handphone = user.handphone
    profilepic = user.profilepic
    purchase = Seller.select().where(Seller.buyer_id == int_id)
    return render_template('profile/userprofile.html',
                           int_id=int_id,
                           username=username,
                           ic_name=ic_name,
                           handphone=handphone,
                           profilepic=profilepic,
                           purchase=purchase)
Пример #15
0
    def init_seller(self, price):
        self.customer_type = Customer.seller

        seller_props = Seller()
        seller_props.asking_price = price
        seller_props.status = Seller.UNAVAILABLE
        seller_props.parent_key = self.key
        self.seller_props = seller_props.put()
        memcache.add(str(self.seller_props), seller_props, 10)

        self.put()
Пример #16
0
def profile():
    pic = User.get(User.id == current_user.id).profilepic_url
    purchase = Seller.select().where(Seller.buyer_id == current_user.id)
    rated = Rate.select().where(Rate.rater_id == current_user.id)
    rated_ids = [r.user_being_rated_id.id for r in rated]
    everyone = User.select()
    # score = []
    # for r in rated :
    #     sum_score = Rate.select(fn.SUM('score')).where(Rate.user_being_rated_id == r.user_being_rated_id)
    #     total_records = raters.count()
    #     final_rating = sum_score/total_records
    #     score.append(final_rating)

    return render_template('profile/profile.html',
                           pic=pic,
                           purchase=purchase,
                           rated_ids=rated_ids)
Пример #17
0
def post():
    flightcode = request.form.get('flightcode')
    departure_time = request.form.get('departure_time')
    departure_date = request.form.get('departure_date')
    departure_location = request.form.get('departure_location')
    destination = request.form.get('destination')
    choice = request.form.get('choice')
    username = current_user.username
    user_id = current_user.id
    seller = Seller.create(choice=choice,
                           username=username,
                           seller_id=user_id,
                           flightcode=flightcode,
                           departure_time=departure_time,
                           departure_date=departure_date,
                           departure_location=departure_location,
                           destination=destination)
    return redirect(url_for('seller.availability'))
Пример #18
0
def buyer():
    flightcode = request.form.get('flightcode')
    departure_time = request.form.get('departure_time')
    departure_date = request.form.get('departure_date')
    departure_location = request.form.get('departure_location')
    destination = request.form.get('destination')
    username = request.form.get('username')
    seller = Seller.get((Seller.username == username)
                        & (Seller.flightcode == flightcode)
                        & (Seller.departure_time == departure_time)
                        & (Seller.departure_date == departure_date)
                        & (Seller.departure_location == departure_location)
                        & (Seller.destination == destination))
    seller.buyer_id = current_user.id
    seller.sold = True
    seller.amount = 50
    seller.save()

    return redirect(url_for('braintree.new_checkout'))
Пример #19
0
def get_one_supporter():
    rds = g.rds
    db = g._db

    appid = request.appid
    uid = request.uid

    store_id = request.args.get('store_id', 0)
    store_id = int(store_id)

    if not store_id:
        raise ResponseMeta(400, 'require store_id param')

    sellers = Seller.get_sellers(db, store_id)
    if not sellers:
        raise ResponseMeta(400, 'store no supporter')

    seller = None
    #获取上次对话的客服id
    last_store_id, last_seller_id = User.get_seller(rds, appid, uid)
    if store_id == last_store_id and last_seller_id > 0:
        for s in sellers:
            if s['id'] == last_seller_id:
                status = Supporter.get_user_status(rds, s['id'])
                s['status'] = status
                seller = s
                break

    if not seller:
        seller = get_new_seller(rds, sellers)
        User.set_seller(rds, appid, uid, store_id, seller['id'])

    name = ""
    if seller.has_key('name') and seller['name']:
        name = seller['name'].split('@')[0]

    resp = {
        "seller_id": seller['id'],
        "name": name,
        "status": seller["status"]
    }
    return make_json_response({"data": resp}, 200)
Пример #20
0
def get_one_supporter():
    rds = g.rds
    db = g._db

    appid = request.appid
    uid = request.uid

    store_id = request.args.get('store_id', 0)
    store_id = int(store_id)

    if not store_id:
        raise ResponseMeta(400, 'require store_id param')

    sellers = Seller.get_sellers(db, store_id)
    if not sellers:
        raise ResponseMeta(400, 'store no supporter')

    seller = None
    #获取上次对话的客服id
    last_store_id, last_seller_id = User.get_seller(rds, appid, uid)
    if store_id == last_store_id and last_seller_id > 0:
        for s in sellers:
            if s['id'] == last_seller_id:
                status = Supporter.get_user_status(rds, s['id'])
                s['status'] = status
                seller = s
                break
                
    if not seller:
        seller = get_new_seller(rds, sellers)
        User.set_seller(rds, appid, uid, store_id, seller['id'])
        
    name = ""
    if seller.has_key('name') and seller['name']:
        name = seller['name'].split('@')[0]

    resp = {
        "seller_id":seller['id'], 
        "name":name,
        "status":seller["status"]
    }
    return make_json_response({"data":resp} , 200)
Пример #21
0
def access_token():
    if not request.data:
        return INVALID_PARAM()

    obj = json.loads(request.data)
    username = obj["username"]
    password = obj["password"]

    platform = obj.get('platform', 0)
    device_id = obj.get('device_id', '')

    if not username or not password:
        return INVALID_PARAM()

    db = g._db
    rds = g.rds

    uid = None
    store_id = None

    try:
        seller_id = int(username)
    except ValueError:
        seller_id = 0

    if seller_id:
        seller = Seller.get_seller(db, seller_id)
    else:
        seller = Seller.get_seller_with_number(db, username)

    if check_seller_password(seller, password):
        uid = seller['id']
        store_id = seller['store_id']

    if not uid:
        return INVALID_USER()

    access_token = login_gobelieve(uid, seller['name'], config.APP_ID,
                                   config.APP_SECRET, device_id, platform)

    if not access_token:
        return CAN_NOT_GET_TOKEN()

    tok = create_token(3600, True)
    tok['uid'] = uid
    tok['store_id'] = store_id
    tok['access_token'] = access_token
    tok['name'] = seller['name']
    tok['status'] = 'online'

    t = token.AccessToken(**tok)
    t.save(rds)
    t = token.RefreshToken(**tok)
    t.save(rds)

    #用户上线
    Supporter.set_user_online(rds, uid)

    now = int(time.time())
    obj = {
        "timestamp": now,
        "device_name": obj.get("device_name", ""),
        "device_id": obj.get("device_id", ""),
        "platform": obj.get("platform", 0)
    }

    PLATFORM_WEB = 3
    PLATFORM_WIN32 = 4
    PLATFORM_DARWIN = 5
    PLATFORM_LINUX = 6
    if platform >= 3:
        content = json.dumps({"login_pc": obj})
    else:
        content = json.dumps({"login": obj})
    send_sys_message(uid, content, config.APP_ID, config.APP_SECRET)

    return make_json_response(tok, 200)
Пример #22
0
import sys
sys.path.append('/teste/')

from controller.seller import SellerController
from models.seller import Seller

seller = Seller('Fernanda', '*****@*****.**', '34-544323567')

# criação
# SellerController().create(seller)

# leitura
sellers = SellerController().read_all()
for se in sellers:
    print(se.name_seller)

# delete
#SellerController().delete(sellers[0])

# teste update
sellers[0].name_seller = 'Clara'
sellers[0].email = '*****@*****.**'
SellerController().create(sellers[0])

sellerrs = SellerController().read_all()
for se in sellerrs:
    print(se.name_seller)