Example #1
0
 def post(self):
     try:
         mobile = self.get_current_user()
         s = Session()
         info = get_info_by_mobile(mobile)
         self.response(Result.success(info))
     except Exception as ex:
         logging.exception("query info error!", exc_info=True)
         self.response(Result.error("query info error."))
Example #2
0
 def post(self):
     try:
         s = Session()
         book_id = self.get_body_argument("book_id")
         book = get_book_by_id(book_id)
         self.response(Result.success(book))
     except Exception as ex:
         logging.exception("query book error!", exc_info=True)
         self.response(Result.error("query book error."))
Example #3
0
 def post(self):
     try:
         s = Session()
         address = get_params(self)
         create_address(s, address)
         self.response(Result.success("success"))
     except Exception as ex:
         logging.exception("add address error!", exc_info=True)
         self.response(Result.error("add address error."))
Example #4
0
 def post(self):
     try:
         s = Session()
         category = self.get_body_argument("category")
         books = get_book_by_category(category)
         self.response(Result.success(books))
     except Exception as ex:
         logging.exception("query books error!", exc_info=True)
         self.response(Result.error("query books error."))
Example #5
0
 def get(self):
     try:
         user = self.get_current_user()
         s = Session()
         account = get_account_by_mobile(s, user)
         self.response(Result.success(account))
     except Exception as ex:
         logging.exception("query surplus error!", exc_info=True)
         self.response(Result.error("query surplus error."))
Example #6
0
 def post(self):
     try:
         s = Session()
         order = get_order_from_params(self)
         order_details = get_order_detail_from_params(self, order)
         order.fee = sum([detail.price for detail in order_details])
         create(s, order, order_details)
         self.response(Result.success("success"))
     except Exception as ex:
         logging.exception("create order error!", exc_info=True)
         self.response(Result.error("create order error."))
Example #7
0
 def post(self):
     try:
         mobile = self.get_current_user()
         s = Session()
         book_id = self.get_body_argument("book_id")
         cart = CartModel(mobile, book_id, 1, datetime.datetime.now())
         delete(cart)
         self.response(Result.success("success"))
     except Exception as ex:
         logging.exception("remove cart error!", exc_info=True)
         self.response(Result.error("remove cart error."))
Example #8
0
 def post(self):
     try:
         s = Session()
         # 只是需要一个 Order model,所以用虚假的数据生成一个
         mobile = self.get_current_user()
         order = OrderModel(mobile, 1, 0)
         order.order_id = self.get_body_argument("order_id")
         cancel(s, order)
         self.response(Result.success("success"))
     except Exception as ex:
         logging.exception("cancel order error!", exc_info=True)
         self.response(Result.error("cancel order error."))
Example #9
0
 def post(self):
     try:
         user = self.get_current_user()
         mobile = self.get_body_argument("mobile")
         fee = self.get_body_argument("fee")
         if mobile != user:
             self.response(
                 Result.error("Not same user, please logout and re-login."))
         s = Session()
         recharge(s, AccountModel(mobile, fee))
         self.response(Result.success("success"))
     except Exception as ex:
         logging.exception("signup error!", exc_info=True)
         self.response(Result.error("SignUp error."))
Example #10
0
    def post(self):
        try:
            s = Session()
            profile = get_params(self)
            if exist(s, profile.mobile):
                self.response(Result.error("mobile has been used."))
                return

            new_profile = ProfileModel(profile.mobile, "", profile.password)
            new_profile.salt = generate_random_string()
            new_profile.password = encrypt_password(new_profile.password,
                                                    new_profile.salt)
            create_profile(s, new_profile)
            self.response(Result.success("success"))
        except Exception as ex:
            logging.exception("signup error!", exc_info=True)
            self.response(Result.error("SignUp error."))
Example #11
0
    def post(self):
        try:
            s = Session()
            profile = get_params(self)
            account = get_profile_by_mobile(s, profile.mobile)
            if account is None:
                # 手机号没注册,需要先注册,跳转到注册页面
                self.response(Result.error("Mobile not find"))
                return

            is_right = is_right_password(profile.password, account.salt,
                                         account.password)
            if not is_right:
                self.response(Result.error("password not correct!"))
                return

            # 可以再做一个全局dict维护登陆状态并用guid代替mobile,提高速度和安全性
            self.set_secure_cookie("dejavu_user", profile.mobile)
            self.response(Result.success("success"))
        except Exception as ex:
            logging.exception("login error!", exc_info=True)
            self.response(Result.error("Some error, please try later."))
Example #12
0
 def get(self):
     self.response(Result.success(s="Hello, world"))