当前位置: 首页>>代码示例>>Python>>正文


Python QueryHelper.get_user_by_mobile方法代码示例

本文整理汇总了Python中helpers.queryhelper.QueryHelper.get_user_by_mobile方法的典型用法代码示例。如果您正苦于以下问题:Python QueryHelper.get_user_by_mobile方法的具体用法?Python QueryHelper.get_user_by_mobile怎么用?Python QueryHelper.get_user_by_mobile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在helpers.queryhelper.QueryHelper的用法示例。


在下文中一共展示了QueryHelper.get_user_by_mobile方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get

# 需要导入模块: from helpers.queryhelper import QueryHelper [as 别名]
# 或者: from helpers.queryhelper.QueryHelper import get_user_by_mobile [as 别名]
    def get(self):
        """Get terminal info.
        """
        status = ErrorCode.SUCCESS
        try:
            tid = self.get_argument('tid', None)
            # check tid whether exist in request and update current_user
            self.check_tid(tid)

            car_sets = DotDict()

            terminal = QueryHelper.get_available_terminal(self.current_user.tid, self.db)
            if not terminal:
                status = ErrorCode.LOGIN_AGAIN
                logging.error("[UWEB] The terminal with tid: %s does not exist,"
                              "  redirect to login.html",
                              self.current_user.tid)
                self.write_ret(status)
                return

            user = QueryHelper.get_user_by_mobile(terminal.owner_mobile, self.db)
            if not user:
                logging.error("[UWEB] The user with uid: %s does not exist,"
                              "  redirect to login.html", 
                              self.current_user.uid)
                self.clear_cookie(self.app_name)
                self.write_ret(ErrorCode.LOGIN_AGAIN)
                return

            # NOTE: deprecated.
            if terminal['mannual_status'] == 1:
                terminal['parking_defend'] = 0
            else:
                terminal['parking_defend'] = 1

            # NOTE: deprecated.
            whitelist = QueryHelper.get_white_list_by_tid(
                self.current_user.tid, self.db)

            car_info = QueryHelper.get_car_by_tid(
                self.current_user.tid, self.db)
            car = dict(corp_cnum=car_info.get('cnum', ''))

            # add tow dict: terminal, car. add two value: whitelist_1,
            # whitelist_2
            white_list = [terminal.owner_mobile]
            for item in whitelist:
                white_list.append(item['mobile'])

            car_sets.update(terminal)
            car_sets.update(car)
            car_sets.update(DotDict(white_list=white_list))
            self.write_ret(status,
                           dict_=dict(car_sets=car_sets))
        except Exception as e:
            status = ErrorCode.SERVER_BUSY
            logging.exception("[UWEB] uid: %s tid: %s get terminal failed. Exception: %s",
                              self.current_user.uid, self.current_user.tid, e.args)
            self.write_ret(status)
开发者ID:jcsy521,项目名称:ydws,代码行数:61,代码来源:terminal.py

示例2: day_notify

# 需要导入模块: from helpers.queryhelper import QueryHelper [as 别名]
# 或者: from helpers.queryhelper.QueryHelper import get_user_by_mobile [as 别名]
    def day_notify(self):
        logging.info("[CELERY] checkertask day_notify started.")
        try:
            #NOTE: avoid sms is sent when the server is restart.
            _date = datetime.datetime.fromtimestamp(int(time.time()))
            if _date.hour not in (9,10):
                return
                
            #NOTE: get all terminals which may be notified, record them into T_MILEAGE_NOTIFICATION.
            terminals = self.db.query("SELECT tid, day_notification, notify_count, left_days"
                                      "  FROM T_DAY_NOTIFICATION"
                                      "  WHERE day_notification != 0"
                                      "  AND notify_count < 3")
            for terminal in terminals:
                if int(time.time()) < terminal['day_notification']:
                    # it's not time to notify
                    continue

                terminal_info = QueryHelper.get_terminal_by_tid(terminal.tid, self.db)
                tid = terminal['tid']

                owner_mobile = terminal_info['owner_mobile']
                assist_mobile = terminal_info['assist_mobile']
                
                t = self.db.get("SELECT distance_current FROM T_TERMINAL_INFO WHERE tid = %s", terminal.tid)
                #distance_current = terminal_info['distance_current']
                distance_current = t['distance_current']
                mobile = terminal_info['mobile']

                notify_count = terminal['notify_count']
                left_days = terminal['left_days']
                day_notification= terminal['day_notification']

                if left_days == 1: # it should be notified this day                           
                    logging.info("[CELERY] Send day notification."
                                 "  tid: %s, mobile: %s, owner_mobile: %s, assist_mobile: %s,"
                                 "  day_notification: %s" 
                                 "  notify_count: %s, left_days: %s.", 
                                 tid, mobile, owner_mobile, assist_mobile, day_notification, 
                                 notify_count, left_days)
                    self.db.execute("UPDATE T_DAY_NOTIFICATION"
                                    "  SET notify_count = %s,"
                                    "      left_days = %s,"
                                    "      notify_time = %s"
                                    "  WHERE tid = %s",
                                    notify_count+1, 3, 
                                    int(time.time()), tid)
                    if owner_mobile:
                        sms = SMSCode.SMS_NOTIFY_DAY % (terminal_info['alias'])
                        SMSHelper.send(owner_mobile, sms)
                    if assist_mobile:
                        user = QueryHelper.get_user_by_mobile(owner_mobile, self.db)
                        name = safe_unicode(user['name'])
                        sms = SMSCode.SMS_NOTIFY_ASSIST_DAY % (mobile, owner_mobile, name)
                        SMSHelper.send(assist_mobile, sms)
                elif left_days in (2, 3): # do not notify, just postpone one day
                    logging.info("[CELERY] Do not send day notification this day,"
                                 "  just modify the left_days."
                                 "  tid: %s, mobile: %s, owner_mobile: %s, assist_mobile: %s,"
                                 "  day_notification: %s" 
                                 "  notify_count: %s, left_days: %s.", 
                                 tid, mobile, owner_mobile, assist_mobile, day_notification, 
                                 notify_count, left_days)
                    self.db.execute("UPDATE T_DAY_NOTIFICATION"
                                    "  SET left_days = %s"
                                    "  WHERE tid = %s",
                                    left_days-1,
                                    tid)
                else: #NOTE: It should never occur.
                    logging.info("[CELERY] Invalid left_days: %s, mobile: %s.", 
                                left_days, mobile)
                    
        except Exception as e:
            logging.exception("[CELERY] Day notification failed. Exception: %s.",
                              e.args)
开发者ID:jcsy521,项目名称:ydws,代码行数:77,代码来源:checkertask.py

示例3: post

# 需要导入模块: from helpers.queryhelper import QueryHelper [as 别名]
# 或者: from helpers.queryhelper.QueryHelper import get_user_by_mobile [as 别名]
    def post(self):
        """Retrieve the password."""
        status = ErrorCode.SUCCESS
        try:
            data = DotDict(json_decode(self.request.body))
            mobile = data.mobile
            captcha = data.get('captcha','')
            logging.info("[UWEB] User retrieve password request: %s", data)
        except Exception as e:
            status = ErrorCode.ILLEGAL_DATA_FORMAT
            self.write_ret(status)
            return 

        try:
            status = self.check_privilege(data.mobile) 
            if status != ErrorCode.SUCCESS: 
                logging.error("[UWEB] User: %s is just for test,"
                              "  has no right to access the function.", 
                              data.mobile) 
                self.write_ret(status) 
                return

            psd = get_psd()                        
            user = QueryHelper.get_user_by_mobile(mobile, self.db)
            if user:
                psd_info = dict(user_id=mobile,
                                user_type=UWEB.USER_TYPE.PERSON,
                                password=psd)
                if not captcha: # old version               
                    update_password(psd_info, self.db, self.redis)
                    retrieve_password_sms = SMSCode.SMS_RETRIEVE_PASSWORD % (psd) 
                    ret = SMSHelper.send(mobile, retrieve_password_sms)
                    ret = DotDict(json_decode(ret))
                    if ret.status == ErrorCode.SUCCESS:
                        logging.info("[UWEB] user uid: %s retrieve password success, "
                                     "  the new passwrod: %s", 
                                     mobile, psd)
                    else:
                        status = ErrorCode.SERVER_BUSY
                        logging.error("[UWEB] user uid: %s retrieve password failed.", 
                                      mobile)
                else: # new version
                    captcha_key = get_captcha_key(mobile)
                    captcha_old = self.redis.get(captcha_key)
                    if captcha_old:
                        if captcha == str(captcha_old): 
                            update_password(psd_info, self.db, self.redis)
                            retrieve_password_sms = SMSCode.SMS_RETRIEVE_PASSWORD % (psd) 
                            ret = SMSHelper.send(mobile, retrieve_password_sms)
                            ret = DotDict(json_decode(ret))
                            if ret.status == ErrorCode.SUCCESS:
                                logging.info("[UWEB] user uid: %s retrieve password success, "
                                             "  the new passwrod: %s", 
                                             mobile, psd)
                            else:
                                status = ErrorCode.SERVER_BUSY
                                logging.error("[UWEB] user uid: %s retrieve password failed.", 
                                              mobile)
                        else:
                            status = ErrorCode.WRONG_CAPTCHA
                            logging.error("mobile: %s retrieve password failed. "
                                          "  captcha: %s, captcha_old: %s, Message: %s", 
                                           mobile, captcha, captcha_old, ErrorCode.ERROR_MESSAGE[status])
                    else:
                        status = ErrorCode.NO_CAPTCHA
                        logging.error("mobile: %s retrieve password failed. captcha: %s, Message: %s", 
                                      mobile, captcha, ErrorCode.ERROR_MESSAGE[status])
            else: 
                status = ErrorCode.USER_NOT_ORDERED
                logging.error("[UWEB] umobile: %s does not exist, retrieve password failed.", 
                              mobile)
            self.write_ret(status)
        except Exception as e:
            logging.exception("[UWEB] user uid: %s retrieve password failed. Exception: %s", 
                              mobile, e.args)
            status = ErrorCode.SERVER_BUSY
            self.write_ret(status)
开发者ID:jcsy521,项目名称:ydws,代码行数:79,代码来源:password.py


注:本文中的helpers.queryhelper.QueryHelper.get_user_by_mobile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。