Exemplo n.º 1
0
 def input(self,
           name="",
           pwd="",
           affirm_pwd="",
           activate=0,
           phone="",
           school_id="",
           level=1):
     if pwd != affirm_pwd:
         raise FormalError(pwd=pwd, affirm_pwd=affirm_pwd)
     if not convert.is_mobile(phone):
         raise FormalError(phone=phone)
     if db_api.user_list(name=name):
         raise ParamExist(name=name)
     if db_api.user_list(phone=phone):
         raise ParamExist(phone=phone)
     values = {
         "name": name,
         "pwd": encry_md5(pwd.strip()),
         "activate": activate,
         "phone": phone,
         "level": level
     }
     if school_id:
         if not db_api.school_get(school_id):
             raise NotFound(school_id=school_id)
         values.update({"school_id": school_id})
     user_obj = db_api.user_create(values)
     return user_obj
Exemplo n.º 2
0
    def _check_student_relative(self, student_relative_info):
        name = student_relative_info.get('name', '')
        birthday = student_relative_info.get('birthday', '')
        class_id = student_relative_info.get('class_id', '')
        relative_list = student_relative_info.get("relative_list", [])

        if birthday and not convert.is_date(birthday):
            return 1, '%s: student info error.'%name
        if not name or not class_id:
            return 1, '%s: student info error.'%name

        relative_op = RelativeLogic()
        for relative_info in relative_list:
            relative_birthday = relative_info.get("birthday", "")
            if relative_birthday and not convert.is_date(convert.bs2utf8(relative_birthday)):
                return 2, '%s: relative info error.' % relative_info.get("name", "")
            phone = convert.bs2utf8(relative_info.get("phone", ""))
            if phone and not convert.is_mobile(phone):
                return 2, '%s: relative info error.' % relative_info.get("name", "")
            name = convert.bs2utf8(relative_info.get("name", ""))
            if not name:
                return 2, '%s: relative info error.' % relative_info.get("name", "")
            if phone:
                db_relative_list = relative_op.info_by_phone(phone=phone)
                if db_relative_list and convert.bs2utf8(db_relative_list[0].get("name", "")) != name:
                    LOG.info("relative info, phone:%s and name:%s error"%(phone, name))
                    return 2, '%s: relative info error.' % relative_info.get("name", "")
        return 0, 'relative ok'
Exemplo n.º 3
0
 def update(self, id="", **kwargs):
     if not id or not kwargs:
         return False
     phone = convert.bs2utf8(kwargs.get("phone", ""))
     if phone and not convert.is_mobile(phone):
         raise exception.FormalError(phone=phone)
     _ = db_api.relative_update(id, kwargs)
     return _
Exemplo n.º 4
0
def _extract_mobiles(accounts):
    if not accounts:
        return None
    if isinstance(accounts, str):
        mobile = accounts.partition('@')[0]
        return mobile if is_mobile(mobile) else None
    if not isinstance(accounts, (list, tuple)):
        raise ValueError('unsupported type: %s' % type(accounts))
    if 1 == len(accounts):
        return _extract_mobiles(accounts[0])
    return [_extract_mobiles(x) for x in accounts]
Exemplo n.º 5
0
 def update_pwd_by_phone(self, phone, pwd):
     user_list = db_api.user_list(phone=phone)
     if not user_list:
         return False
     user_id = user_list[0].id
     if not phone:
         return False
     if not convert.is_mobile(phone):
         return False
     db_api.user_update(user_id, {"pwd": encry_md5(pwd.strip())})
     return True
Exemplo n.º 6
0
def _yield_multi(redis_result, accounts):
    if not isinstance(redis_result, (list, tuple)):
        raise ValueError('redis_result invalid: {0}'.format(redis_result))
    if not isinstance(accounts, (list, tuple)):
        raise ValueError('accounts invalid: {0}'.format(accounts))

    for rr, single_acc in izip(redis_result, accounts):
        if not rr:
            yield _extract_mobiles(single_acc)
            continue
        mobile, _ = rr.split(':')
        yield mobile if is_mobile(mobile) else None
Exemplo n.º 7
0
    def post(self, account, pwd, val, *args, **kwargs):
        """
        检查注册验证码
        """
        user_agent = urllib.unquote(bs2utf8(
            self.request.headers['user-agent']))

        reg_ip = bs2utf8(self.request.remote_ip)
        if not is_email(account):
            return {'status': 1}

        mobile = account.partition('@')[0]
        if not is_mobile(mobile):
            return {'status': 2}

        if not is_reg_val_code(val):
            return {'status': 3}

        expect_code = GAccRdsInts.send_cmd(*get_newacc_reg_val(mobile))
        if not expect_code:
            return {'status': 4}
        expect_code = expect_code.split(':')[0]
        if expect_code != val:
            return {'status': 4}

        pwd_mask = cipher_pwd(pwd)
        ok = GAccRdsInts.send_cmd(*set_account_pwd(account, pwd_mask))
        if not ok:
            return {'status': 5}

        reg_ts = time.strftime(fmt, time.gmtime())
        GMQDispRdsInts.send_multi_cmd(*combine_redis_cmds(
            shortcut_mq(
                'gen_mysql',
                mysql_pack(DB_TBL_SSP_USR_LOGIN, {
                    'username': account,
                    'password': pwd_mask,
                    'mobile': mobile,
                }, 0)),
            shortcut_mq(
                'gen_mysql',
                mysql_pack(
                    DB_TBL_SSP_USR_LOGIN,
                    {
                        'username': account,
                        'reg_agent': user_agent,
                        'reg_ts': reg_ts,
                        'reg_ip': reg_ip,
                    },
                    action=0,
                ))))
        return {'status': 0}
Exemplo n.º 8
0
    def input(self, openid="", session_key="", phone="", wx_type=1):
        if db_api.wxuser_list(openid=openid):
            raise ParamExist(openid=openid)

        if db_api.wxuser_list(session_key=session_key):
            raise ParamExist(session_key=session_key)

        values = {
            "openid": openid,
            "session_key": session_key,
            "wx_type": wx_type
        }
        if phone and convert.is_mobile(phone):
            values.update({"phone": phone})

        wx_obj = db_api.wxuser_create(values)
        return wx_obj
Exemplo n.º 9
0
def validate(api_key, auth_cipher, sign, ver=1):
    """
    :param api_key: 开发者key
    :param auth_cipher:
    """
    api_ob = tuple(
        (x for x in (oem_accounts.get(api_key), beiqi_keys.get(api_key)) if x))
    if not api_ob:
        #api_key未找到
        logger.warn('no api_key {0}'.format(api_key))
        return 4

    api_ob = api_ob[0]
    plain = check_cipher(auth_cipher, api_ob.get('s'), sign)
    if not plain:
        return 4

    acc = plain.get('acc')
    code = plain.get('code')
    pwd = plain.get('pwd')

    if not (acc and code and pwd):
        logger.warn('params lost in {0}'.format(plain))
        return 5

    acc = acc.split('@')[0]
    if not is_mobile(acc):
        logger.warn('acc not mobile: {0}'.format(acc))
        return 3

    acc = fix_account_postfix(acc)
    if api_key in beiqi_keys:
        return False, api_key, acc, code, pwd

    parse_result = parse_oem_options(api_ob.get('opt_mask') or api_key)
    if not parse_result:
        return 1

    _, _, lt_acc, _, _, has_pwd = parse_result
    if not (lt_acc and has_pwd):
        logger.warn('not lt_acc, active refuse: {0}'.format(api_key))
        return 1

    return True, api_key, acc, code, pwd
Exemplo n.º 10
0
 def input(self, name="", sex=0, birthday="", phone="", describe=""):
     if birthday and not convert.is_date(birthday):
         raise exception.FormalError(birthday=birthday)
     if phone and not convert.is_mobile(phone):
         raise exception.FormalError(phone=phone)
     if not name:
         raise exception.ParamNone(name=convert.bs2unicode(name))
     if phone:
         relative_list = db_api.relative_list(phone=phone)
         if relative_list and convert.bs2utf8(
                 relative_list[0].name) != name:
             raise exception.ParamExist(name=name, phone=phone)
     values = {"name": name, "sex": sex, "describe": describe}
     if phone:
         values.update({"phone": phone})
     if birthday:
         values.update({"birthday": birthday})
     relativel_obj = db_api.relative_create(values)
     return relativel_obj
Exemplo n.º 11
0
def reg_via_mobile(account, api_key):
    """
    通过手机号注册
    :param account: 用户帐号
    :param api_key:
    :return:
    """
    mobile = account.split('@')[0]
    if not is_mobile(mobile):
        return

    val_code = ''.join((str(randint(0, 9)) for _ in xrange(6)))
    logger.debug('val_code %s sent' % val_code)
    #该接口需兼容oem,故填入空api_key
    GAccRdsInts.send_multi_cmd(*combine_redis_cmds(
        gen_newacc_reg_val(mobile, val_code, api_key or '')))
    GMQDispRdsInts.send_cmd(*shortcut_mq(
        'sms_notify',
        sms_notify_pack(
            mobile, SmsType.REGISTER, account, val_code, api_key=api_key)))

    logger.debug('account %s val_code %s sent' % (account, val_code))
    return True
Exemplo n.º 12
0
 def push_verify(self):
     phone = convert.bs2utf8(self.get_argument('phone', ''))
     if not phone or not convert.is_mobile(phone):
         self.finish(
             json.dumps({
                 'state': 1,
                 'message': 'Push verify code fail, phone is noe.'
             }))
         return
     verify_code = "888888"  #common_util.create_verifycode()
     _op = VerifyManageLogic()
     _ = _op.input(phone=phone, verify_code=verify_code)
     if _:
         self.finish(
             json.dumps({
                 'state': 0,
                 'message': 'Push verify code ok'
             }))
     else:
         self.finish(
             json.dumps({
                 'state': 2,
                 'message': 'Push verify code fail'
             }))