Beispiel #1
0
 def add_actv_pv(ids):
     '''增加活动的pv'''
     if not isinstance(ids, (types.ListType, types.TupleType)):
         ids = [ids]
     r = {}
     try:
         for i in ids:
             redis_pool.incr('__member_actv_customer_%s_pv__' % i)
     except:
         log.warn('incr pv error:%s' % traceback.format_exc())
     return r
Beispiel #2
0
    def password_error(self, userid, password, opuid=None):
        '''密码错误'''
        log.debug('[userid:%s opuid:%s password:%s]错误密码' %
                  (userid, opuid, password))

        if self.pwderr_conf.get('can_many_pwderr'): return

        redis_key = self.pwderr_fmt.format(userid=userid,
                                           opuid=opuid or 0,
                                           udid=self.req.input().get('udid'))

        if not redis_pool.get(redis_key):
            redis_pool.set(redis_key, 1, self.pwderr_conf['time'])

        else:
            redis_pool.incr(redis_key)
Beispiel #3
0
    def check_user(self, userid, opuid):
        if self.pwderr_conf.get('can_many_pwderr'): return

        redis_key = self.pwderr_fmt.format(userid=userid,
                                           opuid=opuid or 0,
                                           udid=self.req.input().get('udid'))

        # 密码错误频繁, 用户需要稍后重试
        pwderr_cnt = int(redis_pool.get(redis_key) or 0)
        if pwderr_cnt >= self.pwderr_conf['cnt']:
            if pwderr_cnt == self.pwderr_conf['cnt']:
                retry_time = self.pwderr_conf['retry_time']
                redis_pool.incr(redis_key)
                redis_pool.expire(redis_key, retry_time)
            else:
                retry_time = redis_pool.ttl(redis_key)

            errinfo = '密码错误频繁, 请{}分钟后重试'.format(retry_time / 60)
            raise UserError(errinfo)
Beispiel #4
0
    def POST(self):

        info = {'code': '', 'codeDesc': ''}
        params = self.req.inputjson()
        banktype = params.get('banktype', '1')

        if banktype == '1':
            userid = int(self.user.userid)
            key = 'verify_account_{}'.format(str(userid))
            if redis_pool.exists(key):
                count = int(redis_pool.get(key))
                if count >= config.CHANGE_BANK_LIMIT:
                    info['codeDesc'] = config.CHANGE_LIMIT_TIP
                    return self.write(success(info))
                else:
                    redis_pool.incr(key)
            else:
                redis_pool.incr(key)
                start_time_stmp = int(time.time())
                end_time = datetime.now().strftime('%Y-%m-%d') + " 23:59:59"
                end_time_stmp = str_to_tstamp(end_time)
                expire_time = end_time_stmp - start_time_stmp
                redis_pool.expire(key, expire_time)

            bankuser = params.get('bankuser', '')
            bankaccount = params.get('bankaccount', '')
            r = apcli.userprofile_by_id(userid)
            if not r:
                raise ParamError('获取用户信息失败')
            else:
                idCard = r.get('user', {}).get('idnumber', '')
                result = verify_account(config.PATH,
                                        config.APPKEY,
                                        userCode="CITI20170912174935",
                                        sysCode="CITIAPP20170912175227",
                                        bankuser=bankuser,
                                        bankaccount=bankaccount,
                                        idCard=idCard)
                return self.write(success(result))
        else:
            return self.write(success(info))
Beispiel #5
0
class Send(BaseHandler):
    '''
    获取验证码, 发验证码
    '''

    _base_err = '获取验证码失败'

    def check_signup(self, mobile):
        '''
        登录验证码验证
        '''
        # 验证手机号是否注册
        user = apcli.user_by_mobile(mobile)
        if user:
            raise ParamError('该手机已经注册')

        # 验证登录信息
        if self.check_login():
            self._groupid = self.get_groupid()

        # saleman_mobile
        d = self.req.input()
        if (not getattr(self, '_groupid', None) and 'saleman_mobile' in d
                and d['saleman_mobile']):
            user = apcli.user_by_mobile(d['saleman_mobile'])
            if user:
                self._groupid = user['groupid']

    def check_reset_pwd(self, mobile):
        user = apcli.user_by_mobile(mobile)
        if not user:
            raise ParamError('该手机号还未注册')

        self._groupid = user['groupid']

    def check_customer(self, mobile):
        '''
        消费者补充会员休息
        '''
        enuserid = self.req.input().get('enuserid')
        if enuserid:
            try:
                userid = hids.decode(enuserid)[0]
            except:
                if not is_valid_int(enuserid):
                    return
                userid = int(enuserid)

            user = apcli('findUserBriefById', userid)
            if user:
                self._groupid = user.groupid

    @login
    def check_modify_username_grant(self, mobile):
        userid = int(self.user.userid)

        user = apcli_ex('findUserBriefById', userid)
        if not user:
            raise ParamError('商户不存在')

        if mobile != user.mobile:
            raise ParamError('账号信息错误, 联系客服更改')

        self._groupid = user.groupid

    @login
    def check_modify_username_verify(self, mobile):
        with get_connection_exception('qf_core') as db:
            new_user = db.select_one('auth_user', where={'mobile': mobile})
        if new_user:
            raise ParamError('该手机已经注册')

        userid = int(self.user.userid)
        user = apcli_ex('findUserBriefById', userid)
        if not user:
            raise ParamError('商户不存在')

        self._groupid = user.groupid

    def check(self, mobile, mode):
        if not is_valid_mobile(mobile):
            raise ParamError('手机号码不合法')
        if mode not in PRESMS_FMT:
            raise ParamError('发送验证码模式错误')

        # 验证ip是否受限
        ip = self.req.clientip()
        log.debug('ip:%s' % ip)
        if redis_pool.sismember('_mchnt_api_sms_code_ip_', ip):
            raise ParamError('ip受限')

        # 手机号码是不是频繁获取验证码
        key = '_mchnt_api_sms_code_get_{}_'.format(mobile)
        if int(redis_pool.get(key)
               or 0) >= config.SMS_CODE_RULE['count_limit']:
            raise ParamError('该手机号频繁获取验证码')
        self._rkey = key

        self._groupid = None
        if mode.startswith('signup'):
            self.check_signup(mobile)
        elif callable(getattr(self, 'check_' + mode, None)):
            getattr(self, 'check_' + mode)(mobile)

    @dec_check()
    def GET(self):
        d = {k: v.strip() for k, v in self.req.input().iteritems()}
        mobile = d.get('mobile')
        mode = d.get('mode', 'signup')

        # 验证信息
        self.check(mobile, mode)

        # 获取验证码
        try:
            smsexpires = config.SMS_CODE_RULE.get('expires', 6 * 50)
            smslength = config.SMS_CODE_RULE.get('length', 6)
            smsmode = config.SMS_CODE_RULE.get('mode', 1)
            limit_time = config.SMS_CODE_RULE.get('limit_time', 60)
            code = thrift_callex(config.CAPTCHA_SERVERS,
                                 CaptchaServer,
                                 'captcha_get_ex',
                                 ucode=mobile,
                                 src=config.CAPTCHA_SRC,
                                 expires=smsexpires,
                                 length=smslength,
                                 mode=smsmode,
                                 limit_time=limit_time)
            log.debug('获取验证码:%s' % code)
        except CaptchaException, e:
            raise ParamError(str(e.respmsg))

        # 短信内容
        groupid = getattr(self, '_groupid', None)
        if 'group' in d and d['group']:
            group = d['group']
        else:
            group = redis_pool.get(
                '_mchnt_api_group_{}_'.format(groupid)) or 'hjsh'
        log.debug('groupid:{} group:{}'.format(groupid, group))

        fmt = PRESMS_FMT.get(mode + '_' + group, PRESMS_FMT[mode])
        csinfo = get_qd_conf_value(
            userid=None, mode=None, key='csinfo', groupid=groupid) or {}
        csinfo = {k: unicode_to_utf8_ex(v) for k, v in csinfo.iteritems()}
        content = fmt.format(code=code, **csinfo)
        log.debug('content:%s' % content)

        # 短信tag
        tags = config.PRESMS_TAG
        tag = tags.get(groupid or group, tags['hjsh'])

        r, respmsg = smscli.sendSms(mobile=mobile,
                                    content=str(content),
                                    tag=tag,
                                    source='merchant',
                                    target=mode)
        if not r:
            log.debug('调起发送短信服务失败:%s' % respmsg)
            raise ThirdError('发送验证码失败')

        # 设置获取验证码限制
        if not redis_pool.exists(self._rkey):
            redis_pool.set(self._rkey, 0, config.SMS_CODE_RULE['expire_limit'])
        redis_pool.incr(self._rkey)

        return self.write(success({}))