Пример #1
0
def api_user_login_token_get_ajax():
    '''获取用于登录的验证码'''
    phone = request.values.get('phone')
    smscode = request.values.get('smscode')
    if not all([phone, len(phone) == 11, smscode]):
        return apphelper.format_response(
            meta={
                'code': 400,
                'message': BadRequest.__name__,
                'description': u'请输入正确的手机号和验证码!'
            })

    # 验证码检验
    sc = SmsCode(phone=phone)
    if phone not in userconfig.whitelist and not sc.verify_smscode(
            smscode, seconds=300):
        return apphelper.format_response(
            meta={
                'code': 400,
                'message': SmsCodeError.__name__,
                'description': u'请输入正确的验证码!'
            })

    ta = ThirdAccount(thirdtype=ThirdAccountType.phone, thirdid=phone)
    if not ta.exists or ta.uid is None:
        return apphelper.format_response(meta={
            'code': 400,
            'message': NotFound.__name__,
            'description': u'该账号不存在!'
        })

    usertoken = UserToken(uid=ta.uid, appid=config.appids[0])
    return apphelper.format_ok_response(data={'token': usertoken.token})
Пример #2
0
def api_platform_user_setdelete():
    user = UserRDS.query(uid=request.values.get('uid'))
    if len(user)<1:
        raise BadRequest(description='用户不存在!')
    deleted = request.values.get('deleted')
    user[0].is_deleted = deleted
    user[0].save()
    return apphelper.format_ok_response()
Пример #3
0
def api_ajax_thirdaccount_unbind():
    '''ajax异步查询用户信息'''
    thirdtype = request.values.get('thirdtype')
    target_uid = request.values.get('target_uid')
    user = User(uid=target_uid)
    thirdid = user.third_accounts.get(thirdtype)
    td = ThirdAccount(thirdtype=thirdtype, thirdid=thirdid)
    thirdinfo = td.thirdinfo
    user.unbind(thirdtype)
    userRds = UserRDS(uid=target_uid)
    userRds.is_subscribe_miniapp = 'false'
    userRds.save()
    return apphelper.format_ok_response()
Пример #4
0
def api_platform_user_query():
    page_size = 20
    form = {
        'name': request.values.get('name'),
        'is_subscribe': request.values.get('is_subscribe'),
        'is_deleted': request.values.get('is_deleted'),
        'next_page': int(request.values.get('next_page') or 1),
        'is_subscribe_miniapp': request.values.get('is_subscribe_miniapp')
    }

    kwargs = {
        'is_subscribe': form.get('is_subscribe'),
        'is_deleted': request.values.get('is_deleted'),
        'limit': page_size,
        'offset': (form.get('next_page')-1)*page_size,
        'is_subscribe_miniapp': request.values.get('is_subscribe_miniapp')
    }
    if form.get('name'):
        try:
            int(form.get('name'))
        except:
            kwargs['name'] = form.get('name')
        else:
            if len(form.get('name')) == 11:
                kwargs['phone'] = form.get('name')
            else:
                kwargs['uid'] = form.get('name')
    users = UserRDS.query(**kwargs)
    newusers = []
    for u in users:
        jiameiVip = JiameiVip.query(uid=u.uid)
        vips = []
        for j in jiameiVip:
            vipcard = VipCard(cardid=j.cardid)
            vipcard.num = j.remain
            vips.append(vipcard)
        u = u.to_dict()
        u['vips'] = [vip.to_dict() for vip in vips]
        newusers.append(u)
    users = newusers
    # 查询总数
    total_count = UserRDS.query(count=True, **kwargs)
    total_pages = (total_count + page_size - 1) / page_size
    if request.values.get('type') == "ajax":
        # 兼容非跳转页面查询
        return apphelper.format_ok_response(data=users)
    else:
        return render_template('platform/user_query.html', form=form, users=users,  page=form.get('next_page'), total_count=total_count, total_pages=total_pages)
Пример #5
0
def api_tools_audio_upload_ajax():
    name = request.form.get('name') or ''
    tag = request.form.get('tag') or ''
    f = request.files.get('audio-file')
    if not f:
        raise BadRequest(description='请选择要上传的文件')

    f = FalyImageFile.upload(f,
                             tag=tag,
                             name=name or f.filename,
                             filename=f.filename,
                             rename=True)
    data = {
        'url': f.url,
        'file_url': f.url,
        'file_path': f.url,
    }
    data.update(f.urls)
    return apphelper.format_ok_response(data=data)
Пример #6
0
def api_ajax_query_2():
    '''ajax异步查询用户信息'''
    name = request.values.get('name')
    if name:
        kwargs = {}
        try:
            int(name)
        except:
            kwargs['name'] = name
        else:
            if len(name) == 11:
                kwargs['phone'] = name
            else:
                kwargs['uid'] = name

        users = UserRDS.query(limit=None, offset=None, **kwargs)
    else:
        users = []

    data = {'users': [u.to_dict() for u in users]}
    return apphelper.format_ok_response(data=data)
Пример #7
0
def api_tools_image_upload_ajax():
    name = request.form.get('name') or ''
    tag = request.form.get('tag') or ''
    width = request.values.get('width')
    f = request.files.get('image-file')
    if not f:
        raise BadRequest(description='请选择要上传的文件')

    filename = f.filename if '.' in f.filename else name
    f = FalyImageFile.upload(f,
                             tag=tag,
                             name=name or f.filename,
                             filename=filename,
                             rename=True)
    data = {
        'url': f.url,
        'file_url': f.url,
        'file_path': f.url,
    }
    data.update(f.urls)
    if width:
        data.update(
            {width: '%s?x-oss-process=image/resize,w_%s' % (f.url, width)})
    return apphelper.format_ok_response(data=data)
Пример #8
0
def api_user_login_smscode_send_ajax():
    phone = request.values.get('phone')
    if not phone or len(phone) != 11:
        return apphelper.format_response(
            meta={
                'code': 400,
                'message': BadRequest.__name__,
                'description': u'请输入正确的11位手机号!'
            })
    seconds = 300
    # 先保存生成的验证码
    sc = SmsCode(phone=phone)
    # 检查频率
    if not sc.is_allowed(seconds):
        raise TooFrequently(description=u'验证码发送太频繁,请稍后再试!')
    smscode = str(random.randint(1000, 9999))
    sc.save_smscode(smscode, seconds)
    # 不在白名单的话,发送验证码
    if phone not in userconfig.whitelist:
        SmsCodeMessage(phone, (smscode, '手机认证', seconds / 60)).send()
    else:
        logger.debug('smscode send ignored whitelist phone %s.' % phone)

    return apphelper.format_ok_response(data={})