Ejemplo n.º 1
0
def create_ssh_user(trade):
    '''创建新的SSH帐号.

    先把创建的SSH用户保存到 UserProduct数据库,再在所有服务器上创建该SSH用户'''
    # 待创建的ssh用户list, 每个元素是tuple(username,pwd,expire)
    ssh_info_list = []
    for item in trade.cart.item_set.all():
        # 创建 N 个SSH帐号
        for i in range(item.quantity):
            up = UserProduct()
            #save一次以获得自增的id值
            up.save()
            ssh_user = "******" % up.id
            ssh_pwd = baseutil.time_hash()[-6:]
            expired_date = baseutil.get_expired_date(item.product.valid_months)
            ssh_info_list.append((ssh_user, ssh_pwd, expired_date))

            #保存到 UserProduct
            up.user = trade.user
            up.product = item.product
            up.sshuser = ssh_user
            up.sshpwd = ssh_pwd
            up.buy_date = datetime.datetime.now()
            up.expired_date = expired_date
            # 2013-03-02 post_save signal将触发创建账号
            up.save()
    #在所有服务器上创建该SSH帐号
    #baseutil.well_print("before create ssh user")
    ssh_util = SSHUtil(trade.user, None, None)
    ssh_util.ssh_create_onall(ssh_info_list)
Ejemplo n.º 2
0
def checkout(request):
    # 订单号
    out_trade_no = baseutil.time_hash()

    cart = Cart(request)
    # 关闭cart购物车,防止付款之前购物车内内容改变
    cart.cart.checked_out=True
    cart.cart.save()
    # 记录transaction
    now = datetime.datetime.now()
    Transaction.objects.create(out_trade_no=out_trade_no,user=request.user,\
            cart=cart.cart,payed_fee=0,trade_time=now)

   # What you want the button to do.
    paypal_dict = {
            "business": settings.PAYPAL_RECEIVER_EMAIL,
            "amount": (cart.total_fee)/5, # exchange rate is 5
            "item_name": "Bluessh ssh+vpn fee",
            "invoice": out_trade_no, # 本站订单号
            "notify_url": "%s%s" % (settings.SITE_URL, '/paypal/ipn_pengzhao/'),
            "return_url": "%s/usercenter/" % settings.SITE_URL,
            "currency_code":"USD", # 人民币CNY,美元USD
            "charset":"utf-8",
            }

    paypal_form = PayPalPaymentsForm(initial=paypal_dict)
    submit_js = "<script>document.forms['paypalsubmit'].submit()</script>"
    return render(request,'usercenter/checkout.html',
                  {'content':paypal_form.render(),'submit_js':submit_js})
Ejemplo n.º 3
0
def checkout(request):
    # 订单号
    out_trade_no = baseutil.time_hash()

    cart = Cart(request)
    # 关闭cart购物车,防止付款之前购物车内内容改变
    cart.cart.checked_out = True
    cart.cart.save()
    # 记录transaction
    now = datetime.datetime.now()
    Transaction.objects.create(out_trade_no=out_trade_no,user=request.user,\
            cart=cart.cart,payed_fee=0,trade_time=now)

    # What you want the button to do.
    paypal_dict = {
        "business": settings.PAYPAL_RECEIVER_EMAIL,
        "amount": (cart.total_fee) / 5,  # exchange rate is 5
        "item_name": "Bluessh ssh+vpn fee",
        "invoice": out_trade_no,  # 本站订单号
        "notify_url": "%s%s" % (settings.SITE_URL, '/paypal/ipn_pengzhao/'),
        "return_url": "%s/usercenter/" % settings.SITE_URL,
        "currency_code": "USD",  # 人民币CNY,美元USD
        "charset": "utf-8",
    }

    paypal_form = PayPalPaymentsForm(initial=paypal_dict)
    submit_js = "<script>document.forms['paypalsubmit'].submit()</script>"
    return render(request, 'usercenter/checkout.html', {
        'content': paypal_form.render(),
        'submit_js': submit_js
    })
Ejemplo n.º 4
0
def create_ssh_user(trade):
    '''创建新的SSH帐号.

    先把创建的SSH用户保存到 UserProduct数据库,再在所有服务器上创建该SSH用户'''
    # 待创建的ssh用户list, 每个元素是tuple(username,pwd,expire)
    ssh_info_list = []
    for item in trade.cart.item_set.all():
        # 创建 N 个SSH帐号
        for i in range(item.quantity):
            up = UserProduct()
            #save一次以获得自增的id值
            up.save()
            ssh_user = "******" % up.id
            ssh_pwd = baseutil.time_hash()[-6:]
            expired_date = baseutil.get_expired_date(item.product.valid_months)
            ssh_info_list.append((ssh_user, ssh_pwd, expired_date))

            #保存到 UserProduct
            up.user = trade.user
            up.product = item.product
            up.sshuser = ssh_user
            up.sshpwd = ssh_pwd
            up.buy_date = datetime.datetime.now()
            up.expired_date = expired_date
            # 2013-03-02 post_save signal将触发创建账号
            up.save()
    #在所有服务器上创建该SSH帐号
    #baseutil.well_print("before create ssh user")
    ssh_util = SSHUtil(trade.user, None, None)
    ssh_util.ssh_create_onall(ssh_info_list)
Ejemplo n.º 5
0
def checkout(request):
    #-------------请求参数-------------
    #-------必填参数---------
    #请与贵网站订单系统中的唯一订单号匹配
    out_trade_no = baseutil.time_hash()

    #订单名称,显示在支付宝收银台里的“商品名称”里,显示在支付宝的交易管理的“商品名称”的列表里
    subject = alipay_settings.subject
    #订单描述、订单详细、订单备注,显示在支付宝收银台里的“商品描述里
    body = alipay_settings.body
    cart = Cart(request)
    for item in cart:
        body = "%s%sx%d+" % (body, item.product.name, item.quantity)
    body = body[:-1]
    #订单总金额,显示在支付宝收银台里的“应付总额里
    #以后添加促销策略,就在这里修改实际应付金额。在页面中传值过来容易被firebug等手动改变
    #记得测试完改回total_fee = cart.total_fee
    #total_fee = 0.01 #测试时使用
    total_fee = cart.total_fee
    #------end of 必填参数------

    #///////扩展功能参数——其他///
    show_url = alipay_settings.show_url
    #-----------endof请求参数----------

    #/////商户自己的业务逻辑/////#
    cart = Cart(request)
    #关闭cart购物车,防止付款之前购物车内内容改变
    cart.cart.checked_out = True
    cart.cart.save()
    #记录transaction
    now = datetime.datetime.now()
    Transaction.objects.create(out_trade_no=out_trade_no,
                               user=request.user,
                               cart=cart.cart,
                               payed_fee=0,
                               trade_time=now)

    #把请求参数打包成数组
    sParaTemp = {}
    sParaTemp["payment_type"] = "1"
    sParaTemp["show_url"] = show_url
    sParaTemp["out_trade_no"] = out_trade_no
    sParaTemp["subject"] = subject
    sParaTemp["body"] = body
    sParaTemp["total_fee"] = total_fee
    #构造即时到帐接口表单提交HTML数据,无需修改
    alipay = Service()
    strHtml = alipay.Create_direct_pay_by_user(sParaTemp)
    return render_to_response("usercenter/checkout.html", {'content': strHtml})
Ejemplo n.º 6
0
def checkout(request):
    #-------------请求参数-------------
    #-------必填参数---------
    #请与贵网站订单系统中的唯一订单号匹配
    out_trade_no = baseutil.time_hash()

    #订单名称,显示在支付宝收银台里的“商品名称”里,显示在支付宝的交易管理的“商品名称”的列表里
    subject = alipay_settings.subject
    #订单描述、订单详细、订单备注,显示在支付宝收银台里的“商品描述里
    body = alipay_settings.body
    cart = Cart(request)
    for item in cart:
        body = "%s%sx%d+" % (body, item.product.name, item.quantity)
    body = body[:-1]
    #订单总金额,显示在支付宝收银台里的“应付总额里
    #以后添加促销策略,就在这里修改实际应付金额。在页面中传值过来容易被firebug等手动改变
    #记得测试完改回total_fee = cart.total_fee
    #total_fee = 0.01 #测试时使用
    total_fee = cart.total_fee
    #------end of 必填参数------

    #///////扩展功能参数——其他///
    show_url = alipay_settings.show_url
    #-----------endof请求参数----------

    #/////商户自己的业务逻辑/////#
    cart = Cart(request)
    #关闭cart购物车,防止付款之前购物车内内容改变
    cart.cart.checked_out = True
    cart.cart.save()
    #记录transaction
    now = datetime.datetime.now()
    Transaction.objects.create(out_trade_no=out_trade_no, user=request.user,
                               cart=cart.cart, payed_fee=0, trade_time=now)

    #把请求参数打包成数组
    sParaTemp = {}
    sParaTemp["payment_type"] = "1"
    sParaTemp["show_url"] = show_url
    sParaTemp["out_trade_no"] = out_trade_no
    sParaTemp["subject"] = subject
    sParaTemp["body"] = body
    sParaTemp["total_fee"] = total_fee
    #构造即时到帐接口表单提交HTML数据,无需修改
    alipay = Service()
    strHtml = alipay.Create_direct_pay_by_user(sParaTemp)
    return render_to_response("usercenter/checkout.html", {'content': strHtml})