Exemplo n.º 1
0
def p_demand(request):
    """
    @api /huodong/sd/prop/demand [双但活动]索要道具道具
    @apiGroup sd
    @apiParamExample {json} 请求示例
       {
       prop_item:'shoe'  #索要道具
       stu_id :123   # 被索要道具用户id
       }
    @apiSuccessExample {json} 成功返回
        {
            "message": "",
            "next": "",
            "data": {},
            "response": "ok",
            "error": ""
        }
    """
    user = request.user
    args = request.QUERY.casts(prop_item=unicode, stu_id=int)
    prop_item = args.prop_item
    stu_id = args.stu_id
    if not prop_item or not stu_id:
        return ajax.ajax_fail(error=u'缺少道具标识')
    if not common.any_open_status(user.id):
        return ajax.ajax_fail(error=u'开通用户才能索要')
    # 索要奖品
    common.demand_props(user, stu_id, prop_item)
    return ajax.ajax_ok()
Exemplo n.º 2
0
def p_open_subject(request):
    """
    @api /huodong/sd/stu/open_invite [双但活动]请邀开通接口
    @apiGroup sd
    @apiParamExample {json} 请求示例
       {
       invite_user_id:456 #邀请人
       sn_code:123
       subject_id:2,5,9   开通学科
       }
    @apiSuccessExample {json} 成功返回
        {
            "message": "",
            "next": "",
            "data": {},
            "response": "ok",
            "error": ""
        }
    """
    user = request.user
    args = request.QUERY.casts(subject_id=str, sn_code=int, invite_user_id=int)
    subject_id = args.subject_id
    sn_code = args.sn_code
    invite_user_id = args.invite_user_id
    if not subject_id or not sn_code or not invite_user_id:
        return ajax.ajax_fail(u'缺少参数')
    success, why = common.invite_open(request, user, subject_id, sn_code,
                                      invite_user_id)
    if not success:
        return ajax.ajax_fail(why)
    return ajax.ajax_ok()
Exemplo n.º 3
0
def p_gain(request):
    """
    @api /huodong/sd/prop/gain [双但活动]完成作业获得宝箱
    @apiGroup sd
    @apiParamExample {json} 请求示例
       {
       work_type:1     # 作业类型   1在线作业, 2: 每日任务 3: 诗词大战    4: 同步习题
       }
    @apiSuccessExample {json} 成功返回
        {
            "message": "",
            "next": "",
            "data": {
                "prop": "获得圣诞手套"
            },
            "response": "ok",
            "error": ""
        }
    """

    user = request.user
    args = request.QUERY.casts(work_type=int)
    work_type = args.work_type
    if not work_type:
        return ajax.ajax_fail(u'缺少type值')
    if user.is_teacher:
        return ajax.ajax_fail(u'教师不能参与')
    # 做作业获得
    prop, error = common.award_props(user, work_type)
    if error:
        return ajax.ajax_fail(error)
    return ajax.ajax_ok({'prop': prop})
Exemplo n.º 4
0
def p_ping(request):
    """
    @api {get} /system/ping [系统]检查网站是否可用
    @apiGroup system
    @apiSuccessExample {json} 成功返回
    {
        "message": "",
        "next": "",
        "data": {},
        "response": "ok",
        "error": ""
    }
    """
    try:
        row = db.slave.fetchone("select 1")
    except:
        return ajax.ajax_fail(message="数据库出问题了")

    v = random.randint(0, 1000)
    v = str(v)
    icache.set('x', v)
    r = icache.get('x')
    if r is None:
        return ajax.ajax_fail(message="缓存出问题了")

    return ajax.ajax_ok()
Exemplo n.º 5
0
def find_pass(request):
    username = request.QUERY.get("username")
    if not username:
        return ajax.ajax_fail(request, message="请输入账号!")
    passwd = rd.get(username)
    if not passwd:
        return ajax.ajax_fail(request, message="账号不存在!")
    return ajax.ajax_ok(request, {"pass": passwd})
Exemplo n.º 6
0
def p_verify(request):
    """
    @api /huodong/sd/stu/verify [双但活动]确认用户信息
    @apiGroup sd
    @apiParamExample {json} 请求示例
       {
       invite_user_id:456 #邀请人
       phone:135000000,
       name:张三
       }
    @apiSuccessExample {json} 成功返回
        {
            "message": "",
            "next": "",
            "data": {
                "token": "MzEzMzk0OX0wNDA1MDg1MTg4fTA0MDcxODE1OTk",
                "open_info": [
                    {
                        "status": 0,
                        "pay_type": 2,
                        "subject_id": 2,
                        "cancel_date": "",
                        "open_date": "1970-01-01 08:00:00"
                    },
                    {
                        "status": 0,
                        "pay_type": 0,
                        "subject_id": 5,
                        "cancel_date": "",
                        "open_date": ""
                    },
                    {
                        "status": 0,
                        "pay_type": 0,
                        "subject_id": 9,
                        "cancel_date": "",
                        "open_date": ""
                    }
                ]
            },
            "response": "ok",
            "error": ""
        }
    """

    args = request.QUERY.casts(invite_user_id=int, phone=str, name=unicode)
    phone = args.phone
    name = args.name
    user_id = args.invite_user_id
    if not user_id or not phone or not name:
        return ajax.ajax_fail(u'缺少参数')
    data, error = common.verify_user(user_id, phone, name)
    if error:
        return ajax.ajax_fail(message=error)
    return ajax.ajax_ok(data)
Exemplo n.º 7
0
def register(request):
    if request.method == "GET":
        return ajax.rendet_template(request, "register.html", {})

    username = request.QUERY.get("username")
    password = request.QUERY.get("password")
    if not username or not password:
        return ajax.ajax_fail(request, message="请输入账号密码!")
    passed = rd.get(username)
    if passed:
        return ajax.ajax_fail(request, message="您已经注册过了,请返回首页点击找回密码进行使用!")
    rd.set(username, password)
    return ajax.ajax_ok(request, message="注册成功!")
Exemplo n.º 8
0
    def process_exception(self, request, exception):
        """
        功能说明:view函数抛出异常处理
        -------------------------------
        修改人     修改时间
        --------------------------------
        徐威      2013-07-17
        """
        path = str(request.path)

        # 如果请求的路径为 js css 文件 不处理
        if path.startswith('/site_media/'):
            return None
        if path.startswith('/media/'):
            return None
        # 如果请求的路径为 js css 文件 不处理
        if path.startswith('/theme_media/'):
            return None
        # 如果请求的路径为 js css 文件 不处理
        if path.startswith('/upload_media/'):
            return None

        exc = traceback.format_exc()
        if settings.DEBUG:
            print exc
        log.error(exc)

        return ajax_fail(error="500", message=u"抱歉,服务器开小差了,请联系客服12556185")
Exemplo n.º 9
0
def login(request):
    if request.method == "GET":
        data = {
            "message": "欢迎"
        }
        return ajax.rendet_template(request, "login.html", data)

    username = request.QUERY.get("username")
    password = request.QUERY.get("password")
    if not username or not password:
        return ajax.ajax_fail(request, message="请输入账号密码")
    rel_pwd = rd.get(username)
    if rel_pwd == password:
        resp = ajax.ajax_ok(request, message="登陆成功")
        add_login(resp, username)
        return resp
    else:
        return ajax.ajax_fail(request, message="账号密码错误")
Exemplo n.º 10
0
def change_pass(request):
    username = request.username
    old_pass = request.QUERY.get("old_pass")
    new_pass = request.QUERY.get("new_pass")
    passwd = rd.get(username)
    if passwd != old_pass:
        return ajax.ajax_fail(request, message="密码错误")
    rd.set(username, new_pass)
    return ajax.ajax_ok(request, {})
Exemplo n.º 11
0
    def process_exception(self, request, exception):
        if isinstance(exception, Http404):
            return

        exc = traceback.format_exc()
        log.error(exc)

        r = ajax.ajax_fail(request, message="抱歉,服务器开小差了,请联系客服12556185")
        r.status_code = 500
        return r
Exemplo n.º 12
0
def p_give(request):
    """
    @api /huodong/sd/prop/give [双但活动]赠送道具
    @apiGroup sd
    @apiParamExample {json} 请求示例
       {
       prop_item:'shoe'  #赠送道具
       stu_id :123   # 被赠送道具用户id
       new_id:123  # 消息id
       }
    @apiSuccessExample {json} 成功返回
        {
            "message": "",
            "next": "",
            "data": {},
            "response": "ok",
            "error": ""
        }
    """

    user = request.user
    args = request.QUERY.casts(prop_item=unicode, stu_id=int, new_id=int)
    # 道具标识
    prop_item = args.prop_item
    stu_id = args.stu_id
    new_id = args.new_id
    if not prop_item or not stu_id:
        return ajax.ajax_fail(error=u'缺少道具标识')
    if not common.any_open_status(user.id):
        return ajax.ajax_fail(error=u'开通用户才能赠送')
    if user.id == stu_id:
        return ajax.ajax_fail(error=u'不能赠送给自己')
    # 赠送奖品
    success, why = common.give_props(user, stu_id, prop_item, new_id)
    if not success:
        return ajax.ajax_fail(error=why)
    return ajax.ajax_ok()
Exemplo n.º 13
0
 def wrapper(request, *args, **kwargs):
     try:
         result = fn(request, *args, **kwargs)
         if isinstance(result, (HttpResponseRedirect, HttpResponse)):
             return result
         return render_template(request, self.template, result or {}) if self.template else result
     except Exception, e:
         exc = traceback.format_exc()
         log.error(exc)
         if settings.DEBUG:
             print exc
         if self.template:
             return render_template(request, self.template)
         info = ajax.ajax_fail("系统错误!请联系客服")
         if request.method == 'GET':
             info = HttpResponse(u'%s:%s' %(fn.__name__, e))
             # info = HttpResponseRedirect('/404/')
         return info
Exemplo n.º 14
0
def p_open(request):
    """
    @api /huodong/sd/prop/openBox [双但活动]开启宝箱
    @apiGroup sd
    @apiParamExample {json} 请求示例
       {}
    @apiSuccessExample {json} 成功返回
        {
            "message": "",
            "next": "",
            "data": {
                gift:"方特门票一张"
            },
            "response": "ok",
            "error": ""
        }
    """
    user = request.user
    # 开启宝箱
    gift, error = common.open_box(user)
    if error:
        return ajax.ajax_fail(error)
    return ajax.ajax_ok({'gift': gift})