コード例 #1
0
ファイル: view.py プロジェクト: youfeng243/box
def admin_login():
    if request.json is None:
        logger.warn("参数错误...")
        return fail(HTTP_BAD_REQUEST, EMSG_PARAMS_MISSING)

    username = request.json.get('username', None)
    password = request.json.get('password', None)
    if username is None or password is None:
        logger.warn("用户账号密码没有传过来...")
        return fail(HTTP_UNAUTHORIZED, EMSG_PARAMS_ERROR)

    admin = Admin.get_admin_by_username(username)
    if admin is None:
        logger.warn("当前用户不存在: {}".format(username))
        return fail(HTTP_UNAUTHORIZED, u"当前用户不存在")

    if admin.password != password:
        logger.warn("当前用户密码错误: {} {}".format(username, password))
        return fail(HTTP_UNAUTHORIZED, u"密码错误!")

    # 登录用户信息
    login_user(admin, remember=True)

    logger.info("登录成功: {}".format(username))
    return success(admin.as_resp())
コード例 #2
0
def create_address():
    current_user = get_current_user()
    if current_user is None:
        return fail(HTTP_UNAUTHORIZED, u'请使用微信客户端登录')

    user_id = current_user.id
    if request.json is None:
        return fail(HTTP_BAD_REQUEST, EMSG_PARAMS_MISSING)

    logger.info(json.dumps(request.json, ensure_ascii=False))

    province = request.json.get('province')
    logger.info("province = {}".format(province))

    city = request.json.get('city')
    area = request.json.get('area')
    location = request.json.get('location')
    contact_name = request.json.get('contact_name')
    contact_phone = request.json.get('contact_phone')

    addr = Address.create(
        user_id=user_id,
        province=province,
        city=city,
        area=area,
        location=location,
        contact_name=contact_name,
        contact_phone=contact_phone,
    )

    return success(addr.as_resp())
コード例 #3
0
ファイル: sms.py プロジェクト: youfeng243/box
def mobile_reach_ratelimit(mobile):
    if config.DEBUG:
        return False
    key = 'box:ratelimit:mobile:captcha:%s' % mobile
    value = redis.get(key)
    logger.info('redis[%s]: %s', key, value)
    if value is not None:
        return True
    redis.setex(key, DEFAULT_MOBILE_EXPIRED, mobile)
    return False
コード例 #4
0
def wechat_login(*args, **kwargs):
    if request.endpoint != 'wechat.index':
        openid = session.get('openid', None)
        if openid is None and has_request_context():
            code = request.args.get('code', None)
            if code is not None:
                url = get_token_url(code)
                resp = requests.get(url, verify=False)
                if resp.status_code == 200:
                    data = json.loads(resp.content)
                    openid = data.get('openid', None)
                    session['openid'] = openid
            else:
                if request.method == 'GET':
                    url = get_oauth_url(request.endpoint, randint(1, 10))
                    logger.info(url)
                    return redirect(url)
        g.wechat_openid = openid
コード例 #5
0
ファイル: sms.py プロジェクト: youfeng243/box
def validate_captcha(mobile, captcha):
    if config.DEBUG or config.TESTING:
        if captcha == DEBUG_CODE:
            return True
        else:
            return False

    elif not config.LEANCLOUD_ID or not config.LEANCLOUD_KEY:
        raise RuntimeError('undefined leancloud id/key')
    URL = VERIFY_SMS_CODE.format(captcha=captcha)
    resp = requests.post(
        URL,
        params={'mobilePhoneNumber': mobile},
        headers=lean_cloud_client.gen_headers(),
    )
    data = resp.json()
    rt = data.get('code', None)
    logger.info('veriftySms(%s): %s', mobile, data)
    return rt is None
コード例 #6
0
def syncdb():
    with application.test_request_context():
        _import_models()

        db.create_all()
        db.session.commit()

        # 管理员
        if Admin.query.filter_by(username='******').first() is None:
            admin = Admin.create('youfeng', '555556')
            admin.save()
            logger.info("添加管理员完成...")

        # 产品
        if Product.query.filter_by(name='定制防潮防水纸箱').first() is None:
            product = Product(name='定制防潮防水纸箱', price=1,
                              description='413mmx320mmx257mm', avatar_url='www.baidu.com')
            product.save()
            logger.info("添加产品完成...")

        # 存储费用
        if Mode.query.filter_by(name='普通').first() is None:
            mode = Mode(name='普通', price=1, description='普通')
            mode.save()
            logger.info("添加费用完成...")

        print 'Database Created'
コード例 #7
0
ファイル: sms.py プロジェクト: youfeng243/box
def request_sms(mobile, callback=None):
    if config.DEBUG:
        return DEBUG_CODE

    cb = callback or _default_callback
    data = {'mobilePhoneNumber': mobile}
    logger.info('requestSms: %s', mobile)
    headers = lean_cloud_client.gen_headers()
    logger.info('headers: %s', headers)
    if not int(config.LEANCLOUD_PUSH_ENABLED):
        logger.info('DO NOT requestSms')
        return None
    session = FuturesSession()
    session.post(REQUEST_SMS_CODE_URL,
                 headers=headers,
                 data=json.dumps(data),
                 timeout=10,
                 background_callback=cb)
コード例 #8
0
ファイル: sms.py プロジェクト: youfeng243/box
def _default_callback(session, resp):
    logger.info('requestSms Resp: %s', resp.json())
コード例 #9
0
ファイル: view.py プロジェクト: youfeng243/box
def admin_test():
    logger.info("当前属于登录状态...")
    return success(u"测试通过!")