Esempio n. 1
0
    def post(self):
        result = utils.init_response_data()
        code_model_obj = models.code_model.CodeModel()
        code_coll = code_model_obj.get_coll()
        user_model_obj = models.user_model.UserModel()
        user_coll = user_model_obj.get_coll()
        try:
            mobile = self.get_argument("mobile")
            mobile_code = self.get_argument("mobile_code")
            user_id = self.get_argument("user_id")
            utils.check_code(code_coll, mobile, mobile_code)

            user = user_coll.find_one({
                "mobile": mobile,
            })
            if user:
                raise Exception(u'该手机号已被使用!')

            user = user_coll.find_one({"_id": utils.create_objectid(user_id)})
            if user["mobile"] != mobile:
                user["mobile"] = mobile
                user_coll.save(user)

        except Exception, e:
            result = utils.reset_response_data(0, unicode(e))
Esempio n. 2
0
    def post(self):
        result = utils.init_response_data()
        user_coll = self.model.get_coll()
        try:
            login = self.get_argument("login")
            password = self.get_argument("password")
            is_save_password = int(self.get_argument("is_save_password",
                                                     False))
            if login == "":
                raise Exception("请输入用户名!")
            elif user_coll.find({"mobile":login}).count() == 0 \
                              and user_coll.find({"email":login}).count() == 0:
                raise Exception("手机或邮箱不存在!")
            elif password == "":
                raise Exception("请输入密码!")

            user = user_coll.find_one({"mobile": login}) or user_coll.find_one(
                {"email": login})
            if user["password"] != password:
                raise Exception("密码错误!")

            user["login_date"] = datetime.datetime.now()
            user_coll.save(user)

            params = {
                'client_id': user["mobile"],
                'client_secret': password,
                'grant_type': 'client_credentials',
                'scope': 'font-api',
            }
            body = urllib.urlencode(params)
            client = tornado.httpclient.AsyncHTTPClient()
            response = yield tornado.gen.Task(client.fetch,
                                              "http://localhost:8888/token",
                                              method='POST',
                                              body=body)
            response_body = json.loads(response.body)
            try:
                access_token = response_body["access_token"]
            except Exception, e:
                result = utils.reset_response_data(-1, str(e) + \
                                                   response_body["error"]+" "+\
                                                   response_body["error_description"]+\
                                                   " or password error!")
                self.finish(result)
                return
            if is_save_password:
                self.model.delay_access_token(access_token)

            user["_id"] = str(user["_id"])
            # 存储 token-uid
            self.model.save_token_uid(access_token, user["_id"])

            user["add_time"] = str(user["add_time"]).split(".")[0]
            user["login_date"] = str(user["login_date"]).split(".")[0]
            del user["password"]
            result["data"] = user
            result["data"]["access_token"] = access_token
Esempio n. 3
0
 def post(self, *args, **kwargs):
     result = utils.init_response_data()
     try:
         user_id = self.get_argument("user_id", "")
         if user_id != "" and user_id != "undefined":
             result['data'] = utils.dump(
                 self.coll.find_one({"_id":
                                     utils.create_objectid(user_id)}))
     except Exception as e:
         result = utils.reset_response_data(0, str(e))
     self.finish(result)
Esempio n. 4
0
 def post(self):
     result = utils.init_response_data()
     try:
         code = self.get_argument("code", "")
         if code == '':
             raise ValueError(u"登录失败")
         js_pub = JsApi_pub()
         js_pub.setCode(code)
         wx_user = js_pub.get_user_info()
         user = self.model.get(wx_user)
         result['data'] = utils.dump(user)
     except Exception as e:
         result = utils.reset_response_data(0, str(e))
     self.finish(result)
Esempio n. 5
0
    def post(self):
        result = utils.init_response_data()
        code_model_obj = models.code_model.CodeModel()
        code_coll = code_model_obj.get_coll()
        try:
            mobile = self.get_argument("mobile")
            curr_time = datetime.datetime.now()
            if code_coll.find({
                    "mobile": mobile,
                    "enable_flag": True
            }).count() > 0:
                # 验证码请求限制 每小时限制5条
                if code_coll.find({
                        "mobile": mobile,
                        "add_time": {
                            "$gte": curr_time - datetime.timedelta(hours=1),
                            "$lte": curr_time + datetime.timedelta(hours=1),
                        }
                }).count() >= 5:
                    raise Exception("验证码请求限制,每小时限制5条!")

                code_list = code_coll.find({
                    "mobile": mobile,
                    "enable_flag": True
                })
                for c in code_list:
                    c["enable_flag"] = False
                    code_coll.save(c)
            else:
                pass
            random_code = utils.get_random_num(6, mode="number")
            code_coll.insert_one({
                "mobile": mobile,
                "enable_flag": True,
                "add_time": curr_time,
                "type": "mobile",
                "code": random_code,
            })

            res = wslib.send_msg(
                mobile,
                "(东信宝),尊敬的用户:您好,您的短信验证码为%s,有效时间为10分钟,请及时输入。" % random_code)
            if res != "0":
                raise ValueError(u'短信发送失败')
            result["code"] = random_code
        except Exception, e:
            result = utils.reset_response_data(0, unicode(e))
Esempio n. 6
0
 def get(self):
     try:
         order_id = self.get_argument("order_id", "")
         mobile = self.get_argument("mobile", "")
         pay_type = self.get_argument("pay_type", "")
         order_status = self.get_argument("order_status", "")
         if order_id != "":
             self.mg_query_params.update({
                 "order_id": {
                     "$regex": order_id
                 },
             })
         if mobile != "":
             self.mg_query_params.update({
                 "mobile": {
                     "$regex": mobile
                 },
             })
         if pay_type != "":
             self.mg_query_params.update({
                 "pay_type.value": int(pay_type),
             })
         if order_status != "":
             self.mg_query_params.update({
                 "order_status.value":
                 int(order_status),
             })
         self.namelist = [
             u'序号', u'订单号', u'产品名称', u'消费类型', u'手机号', u'订单状态', u'支付类型',
             u'订单总金额', u'下单时间'
         ]
         self.column_list = [
             "order_id", "good_name", "good_type", "mobile",
             "order_status_desc", "pay_status_desc", "should_pay",
             "add_time"
         ]
     except Exception, e:
         result = utils.reset_response_data(0, str(e))
         self.write(result)
         self.finish()
         return
Esempio n. 7
0
    def post(self):
        result = utils.init_response_data()
        try:
            user_coll = self.model.get_coll()
            oauth_coll = models.OauthModel().get_coll()
            checkcode_coll = models.CheckCode().get_coll()

            mobile = self.get_argument("mobile")
            mobile_code = self.get_argument("mobile_code")
            email = self.get_argument("email")
            email_code = self.get_argument("email_code")
            password = self.get_argument("password")
            type = self.get_argument("type", "b")

            if mobile == "":
                raise Exception("请输入手机号!")
            elif mobile_code == "":
                raise Exception("请输入手机验证码")
            elif password == "":
                raise Exception("请输入password!")

            # 检查手机验证码
            utils.check_code(checkcode_coll, mobile, mobile_code)
            # 检查邮箱验证码
            utils.check_code(checkcode_coll, email, email_code, type="email")

            add_time = datetime.datetime.now()
            login_date = ""
            headimgurl = ""
            nickname = ""
            username = ""
            active = 0
            sex = 0
            city = ""
            address = ""
            privilege = 0
            province = ""
            if not user_coll.find_one({'mobile': mobile}):

                user_coll.insert_one({
                    'mobile': mobile,
                    'email': email,
                    'password': password,
                    'add_time': add_time,
                    'login_date': login_date,
                    'headimgurl': headimgurl,
                    'nickname': nickname,
                    'username': '',
                    'active': active,
                    'sex': sex,
                    'city': city,
                    'address': address,
                    'privilege': privilege,
                    'province': province,
                    'type': type,
                })
                oauth_coll.insert_one({
                    'identifier':
                    mobile,
                    'secret':
                    password,
                    'redirect_uris': [],
                    'authorized_grants':
                    [oauth2.grant.ClientCredentialsGrant.grant_type]
                })
            params = {
                'login': mobile,
                'password': password,
            }
            body = urllib.urlencode(params)
            client = tornado.httpclient.AsyncHTTPClient()
            response = yield tornado.gen.Task(client.fetch,
                                              "http://localhost:8500" +
                                              "/api/user/signin",
                                              method='POST',
                                              body=body)
            response_body = json.loads(response.body)
            if response_body.has_key("error"):
                result = utils.reset_response_data(
                    0, response_body["error"] +
                    response_body["error_description"])
                self.finish(result)
                return

            result["data"] = response_body["response"]["data"]
        except Exception, e:
            result = utils.reset_response_data(0, str(e))
Esempio n. 8
0
 def delete(self):
     result = utils.init_response_data()
     try:
         raise Exception("操作限制!")
     except Exception, e:
         result = utils.reset_response_data(0, str(e))