Exemplo n.º 1
0
 def get(self):
     user_info = self.session['index_user'].to_json()
     data = json.loads(self.get_argument('data'))
     trade_no = sec_pass(str(int(time.time())))  # 交易号
     # 加入订单
     save_data = {"TRADE_NO": trade_no, "UserID": user_info.get('UserID'),
                  "OrderTotalPrice": data.get('totalprice'),
                  "OrderPayType": 1,
                  "OrderStatus": False,
                  "OrderSendAddress": data.get('address')}
     try:
         product_list = []
         for i, x in enumerate(data.get('all_data')):
             # 删除购物车信息
             session.query(ShopCart).filter(ShopCart.ShopCartID == x['shopcartid']).delete()
             # 修改商品信息
             session.query(Product).filter(Product.ProductID == x['productid']).update(
                 {"ProductBuyNum": Product.ProductBuyNum + int(x['num'])})
             product_list.append(str(x['productid']))
         save_data['ProductID'] = ','.join(product_list)
         session.add(Order(**save_data))
         session.commit()
     except Exception, e:
         print(e)
         session.rollback()
Exemplo n.º 2
0
    def post(self):
        # 注册
        try:
            # 获取前端传来的参数
            data = json.loads(self.get_argument('data'))

            luosimao_rep = data.get('luosimao_rep')
            check_json = {
                'api_key': settings.LUOSIMAO_API_KEY,
                'response': luosimao_rep
            }
            check_response = requests.post(settings.LUOSIMAO_CHECK_ADDRESS,
                                           data=check_json)
            if json.loads(check_response.content).get('res') != 'success':
                code = 3
                msg = u"人机验证失败"
                self.write_json(msg, code=code)
                return
            data.pop('luosimao_rep')
            data['UserAge'] = int(data['UserAge'])
            data['UserPwd'] = sec_pass(data['UserPwd'])
            data['UserLastVisitIP'] = self.request.remote_ip
            active_hash_code = sec_pass(str(int(time.time())))
            data['UserHashCode'] = active_hash_code
            session.add(Users(**data))
            session.commit()
            active_url = '<a href='+'http://'+settings.WEB_DOMAIN_NAME+\
                         '/active_email/?address='+data['UserEmail']+\
                         '&hash_code='+active_hash_code+'>http://'+settings.WEB_DOMAIN_NAME+\
                         '/active_email/?address='+data['UserEmail']+\
                         '&hash_code='+active_hash_code+'</a>'
            content = '''
<html>
<body>
<p>亲爱的用户:</p>
<pre>
  您收到这封邮件,是由于在 春色撩人网站 进行了新用户注册,或用户修改 Email 使用 了这个邮箱地址。
 如果您并没有访问过 春色撩人网站,或没有进行上述操作,请忽 略这封邮件。您不需要退订或进行其他进一步的操作。
</pre>
<pre>
 ===============激活链接===================

''' + active_url + '''

(如果上面不是链接形式,请将该地址手工粘贴到浏览器地址栏再访问)

</pre>
</body>
</html>
'''
            obj = redis_queue_send_email.REDIS_QUEUE()
            obj.send_email_via_queue(settings.SMTP_USER, data['UserEmail'],
                                     settings.WEB_NAME + "注册", content)

            self.write_json("success", code=1)
        except Exception, e:
            # 事务
            session.rollback()
            self.write_json("failed", code=0)
Exemplo n.º 3
0
 def post(self):
     # 新增商品类型
     try:
         # 获取前端传来的参数
         data = json.loads(self.get_argument('data'))
         session.add(ProductType(**data))
         session.commit()
         self.write_json("success", code=1)
     except:
         # 事务
         session.rollback()
         self.write_json("failed", code=0)
     finally:
         session.close()
Exemplo n.º 4
0
 def post(self):
     # 新增用户
     try:
         # 获取前端传来的参数
         data = json.loads(self.get_argument('data'))
         # 保存访问IP
         data['UserLastVisitIP'] = self.request.remote_ip
         # 密码加密
         data['UserPwd'] = sec_pass(data['UserPwd'])
         session.add(Users(**data))
         session.commit()
         self.write_json("success", code=1)
     except:
         # 事务
         session.rollback()
         self.write_json("failed", code=0)
     finally:
         session.close()
Exemplo n.º 5
0
 def post(self):
     # 新增商品
     try:
         # 获取前端传来的参数
         data = json.loads(self.get_argument('data'))
         if data['IsHot'] == '1':
             data['IsHot'] = True
         else:
             data['IsHot'] = False
         if data['IsNew'] == '1':
             data['IsNew'] = True
         else:
             data['IsNew'] = False
         pro = Product(**data)
         session.add(pro)
         session.commit()
         self.write_json(pro.ProductID, code=1)
     except Exception, e:
         # 事务
         print e
         session.rollback()
         self.write_json("failed", code=0)