Example #1
0
def shopVerifyTelephone(request):
    logger = logging.getLogger('Pack.app')
    response = {}
    response['data'] = {}
    response['errorMsg'] = ""
    _telephone = request.REQUEST.get('telephone',18201637776)
    _verify_code = request.REQUEST.get('verifyCode',8888)
    _method = request.REQUEST.get('method')
    _deviceInfo = request.REQUEST.get('deviceInfo')
    _clientID = request.REQUEST.get('clientID','0')
    _deviceToken = request.REQUEST.get('deviceToken','0')

    cache.set(str(_telephone),str(_verify_code),1800)
    if _telephone == None or _telephone == '':
        response['code'] = -1
        response['errorMsg'] = u'请输入手机号'
        return HttpResponse(json.dumps(response,ensure_ascii=False),content_type="application/json")
    if  _verify_code == None or _verify_code == '':
        response['code'] = -1
        response['errorMsg'] = u'请输入验证码'
        return HttpResponse(json.dumps(response,ensure_ascii=False),content_type="application/json")
    if _deviceInfo == None or _deviceInfo == '':
        response['code'] = -1
        response['errorMsg'] = u'请输入设备信息'
        return HttpResponse(json.dumps(response,ensure_ascii=False),content_type="application/json")
    if _clientID == None or _clientID == '':
        response['code'] = -1
        response['errorMsg'] = u'请输入clientID'
        return HttpResponse(json.dumps(response,ensure_ascii=False),content_type="application/json")
    if _deviceToken == None or _deviceToken == '':
        response['code'] = -1
        response['errorMsg'] = u'请输入deviceToken'
        return HttpResponse(json.dumps(response,ensure_ascii=False),content_type="application/json")
    if _method == None or _method == '':
        response['code'] = -1
        response['errorMsg'] = u'请输入method'
        return HttpResponse(json.dumps(response,ensure_ascii=False),content_type="application/json")


    _telephone = str(_telephone)
    _verify_code = str(_verify_code)
    _clientID = str(_clientID)
    _deviceToken = str(_deviceToken)
    _method = str(_method)

    if len(_telephone) != 11:
        response['code'] = -1
        response['errorMsg'] = '请输入11位手机号'
        return HttpResponse(json.dumps(response,ensure_ascii=False),content_type="application/json")
    if _telephone.isdigit() == False:
        response['code'] = -1
        response['errorMsg'] = '请输入有效的手机号'
        return HttpResponse(json.dumps(response,ensure_ascii=False),content_type="application/json")
    #中国移动:China Mobile
    # 134[0-8],135,136,137,138,139,150,151,157,158,159,182,187,188
    CM_prog = re.compile(r"^1(34[0-8]|(3[5-9]|5[017-9]|8[278])\d)\d{7}$")
    #CM = r"^1(34[0-8]|(3[5-9]|5[017-9]|8[278])\\d)\\d{7}$"
    #中国联通:China Unicom
    # 130,131,132,152,155,156,185,186
    CU_prog = re.compile(r"^1(3[0-2]|5[256]|8[56])\d{8}$")
    #CU = r"^1(3[0-2]|5[256]|8[56])\\d{8}$"
    # 中国电信:China Telecom
    # 133,1349,153,180,189
    CT_prog = re.compile(r"^1((33|53|8[09])[0-9]|349)\d{7}$")
    #CT = r"^1((33|53|8[09])[0-9]|349)\\d{7}$"
    telephone_match_CM = CM_prog.match(str(_telephone))
    telephone_match_CU = CU_prog.match(str(_telephone))
    telephone_match_CT = CT_prog.match(str(_telephone))

    if not telephone_match_CM and not telephone_match_CT and not telephone_match_CU:
        response['code'] =  -1
        response['errorMsg'] = '请输入有效的手机号'
        return HttpResponse(json.dumps(response,ensure_ascii=False),content_type="application/json")
    saved_verify_code = cache.get(str(_telephone))
    #print('saved_verify_code:'+str(saved_verify_code))
    if not saved_verify_code:
        response['code'] = -1
        response['errorMsg'] = '请重新发送验证码'
        return HttpResponse(json.dumps(response,ensure_ascii=False),content_type="application/json")
    if saved_verify_code != _verify_code:
        response['code'] = -1
        response['errorMsg'] = '验证码错误,请重新输入'
        return HttpResponse(json.dumps(response,ensure_ascii=False),content_type="application/json")
    if _method == '0':
        query_telephone = WaiterOrder.objects.filter(telephone = str(_telephone))
        if not query_telephone.exists():
            _name = '****'+_telephone[7:11]
            _headImage = 'http://meiyue.b0.upaiyun.com/head/1_head.jpg'
            currentTime = time.time()
            currentTime = int(currentTime)
            currentTime = str(currentTime)
            new_waiterOrder = WaiterOrder(telephone=str(_telephone),name = _name, headImage = _headImage,lastLoginTime =
            currentTime,deviceToken = _deviceToken,clientID = _clientID,deviceInfo = _deviceInfo)
            new_waiterOrder.save()
            response['code'] = 0
            response_data = {'waiterOrderId':new_waiterOrder.id,'setShopStatus':'0','shopId':'0'}
            request.session['waiterOrderId'] = new_waiterOrder.id   #new_shop.save()之后,才能在session中设置shopid,未保存之前不知道是多少
            request.session['lastLoginTime'] = currentTime
            response['data'] = response_data
            return HttpResponse(json.dumps(response),content_type="application/json")

        response_data = {}
        response_data['waiterOrderId'] = query_telephone[0].id
        if query_telephone[0].shop == None:
            response_data['setShopStatus'] = '0'
            response_data['shopId'] = '0'
        else:
            response_data['setShopStatus'] = '1'
            response_data['shopId'] = query_telephone[0].shop.id
            request.session['shopId'] = str(query_telephone[0].shop.id)
        request.session['waiterOrderId'] = query_telephone[0].id
        currentTime = time.time()*1000
        currentTime = int(currentTime)
        currentTime = str(currentTime)
        query_telephone.update(clientID = _clientID, deviceToken = _deviceToken,deviceInfo = _deviceInfo,lastLoginTime = currentTime)
        request.session['lastLoginTime'] = currentTime
        response['code'] = 0
        response['data'] = response_data
        return HttpResponse(json.dumps(response),content_type="application/json")

    elif _method == '1':
        query_telephone = Cook.objects.filter(telephone = str(_telephone))
        if not query_telephone.exists():
            _name = '****'+_telephone[7:11]
            _headImage = 'http://meiyue.b0.upaiyun.com/head/1_head.jpg'
            currentTime = time.time()
            currentTime = int(currentTime)
            currentTime = str(currentTime)
            new_cook = Cook(telephone=str(_telephone),name = _name, headImage = _headImage,lastLoginTime =
            currentTime,deviceToken = _deviceToken,clientID = _clientID,deviceInfo = _deviceInfo)
            new_cook.save()
            response['code'] = 0
            response_data = {'cookId':new_cook.id,'setShopStatus':'0','shopId':'0'}
            request.session['cookId'] = new_cook.id   #new_shop.save()之后,才能在session中设置shopid,未保存之前不知道是多少
            request.session['lastLoginTime'] = currentTime
            response['data'] = response_data
            return HttpResponse(json.dumps(response),content_type="application/json")

        response_data = {}
        response_data['cookId'] = query_telephone[0].id
        if query_telephone[0].shop == None:
            response_data['setShopStatus'] = '0'
            response_data['shopId'] = '0'
        else:
            response_data['setShopStatus'] = '1'
            response_data['shopId'] = query_telephone[0].shop.id
        request.session['cookId'] = query_telephone[0].id
        currentTime = time.time()*1000
        currentTime = int(currentTime)
        currentTime = str(currentTime)
        query_telephone.update(clientID = _clientID, deviceToken = _deviceToken,deviceInfo = _deviceInfo,lastLoginTime = currentTime)
        request.session['lastLoginTime'] = currentTime
        response['code'] = 0
        response['data'] = response_data
        return HttpResponse(json.dumps(response),content_type="application/json")

    elif _method == '2':
        query_telephone = WaiterServe.objects.filter(telephone = str(_telephone))
        if not query_telephone.exists():
            _name = '****'+_telephone[7:11]
            _headImage = 'http://meiyue.b0.upaiyun.com/head/1_head.jpg'
            currentTime = time.time()
            currentTime = int(currentTime)
            currentTime = str(currentTime)
            new_waiterServe = WaiterServe(telephone=str(_telephone),name = _name, headImage = _headImage,lastLoginTime =
            currentTime,deviceToken = _deviceToken,clientID = _clientID,deviceInfo = _deviceInfo)
            new_waiterServe.save()
            response['code'] = 0
            response_data = {'waiterServeId':new_waiterServe.id,'setShopStatus':0,'shopId':'0'}
            request.session['waiterServeId'] = new_waiterServe.id   #new_shop.save()之后,才能在session中设置shopid,未保存之前不知道是多少
            request.session['lastLoginTime'] = currentTime
            response['data'] = response_data
            return HttpResponse(json.dumps(response),content_type="application/json")

        response_data = {}
        response_data['waiterServeId'] = query_telephone[0].id
        if query_telephone[0].shop == None:
            response_data['setShopStatus'] = '0'
            response_data['shopId'] = '0'
        else:
            response_data['setShopStatus'] = '1'
            response_data['shopId'] = query_telephone[0].shop.id
        request.session['waiterServeId'] = query_telephone[0].id
        currentTime = time.time()*1000
        currentTime = int(currentTime)
        currentTime = str(currentTime)
        query_telephone.update(clientID = _clientID, deviceToken = _deviceToken,deviceInfo = _deviceInfo,lastLoginTime = currentTime)
        request.session['lastLoginTime'] = currentTime
        response['code'] = 0
        response['data'] = response_data
        return HttpResponse(json.dumps(response),content_type="application/json")

    elif _method == '3':
        query_telephone = Shop.objects.filter(telephone = str(_telephone))
        if not query_telephone.exists():
            currentTime = time.time()
            currentTime = int(currentTime)
            currentTime = str(currentTime)
            new_shop = Shop(telephone=str(_telephone),setInfoStatus = '0',lastLoginTime = currentTime,deviceToken
            = _deviceToken,clientID = _clientID,deviceInfo = _deviceInfo)
            new_shop.save()
            response['code'] = 0
            response_data = {'shopId':new_shop.id,'setInfoStatus':0}
            request.session['shopId'] = new_shop.id   #new_shop.save()之后,才能在session中设置shopid,未保存之前不知道是多少
            request.session['lastLoginTime'] = currentTime
            response['data'] = response_data
            return HttpResponse(json.dumps(response),content_type="application/json")

        response_data = {'setInfoStatus':query_telephone[0].setInfoStatus,'shopId':query_telephone[0].id}
        request.session['shopId'] = query_telephone[0].id
        currentTime = time.time()*1000
        currentTime = int(currentTime)
        currentTime = str(currentTime)
        query_telephone.update(lastLoginTime = currentTime,clientID = _clientID, deviceToken = _deviceToken,deviceInfo = _deviceInfo)
        request.session['lastLoginTime'] = currentTime
        response['code'] = 0
        response['data'] = response_data
        return HttpResponse(json.dumps(response),content_type="application/json")
Example #2
0
def verifyCook(request):
    response = {}
    response['data'] = {}
    response['errorMsg'] = ""
    _shopId = request.session.get('shopId')
    if not _shopId:
        response['code'] = 1
        response['errorMsg'] = '请先登录'
        return HttpResponse(json.dumps(response),content_type="application/json")
    ##################JUDGE############
    _lastLoginTime = request.session.get('lastLoginTime')
    if not _lastLoginTime:
        response['code'] = 1
        response['errorMsg'] = '请先登录'
        return HttpResponse(json.dumps(response),content_type="application/json")
    try:
        shop = Shop.objects.get(id = _shopId)
    except ObjectDoesNotExist:
        response['code'] = 1
        response['errorMsg'] = '请先登录'
        return HttpResponse(json.dumps(response,ensure_ascii=False),content_type="application/json")
    if _lastLoginTime != shop.lastLoginTime:
        response['code'] = 1
        response['errorMsg'] = '上次登录失效,请重新登录'
        return HttpResponse(json.dumps(response),content_type="application/json")
    ####################END#################

    _telephone = request.REQUEST.get('telephone',18201637776)
    _verify_code = request.REQUEST.get('verifyCode',8888)
    cache.set(str(_telephone),str(_verify_code),1800)
    if _telephone == None or _telephone == '':
        response['code'] = -1
        response['errorMsg'] = u'请输入手机号'
        return HttpResponse(json.dumps(response,ensure_ascii=False),content_type="application/json")
    if  _verify_code == None or _verify_code == '':
        response['code'] = -1
        response['errorMsg'] = u'请输入验证码'
        return HttpResponse(json.dumps(response,ensure_ascii=False),content_type="application/json")

    _telephone = str(_telephone)
    _verify_code = str(_verify_code)
    if len(_telephone) != 11:
        response['code'] = -1
        response['errorMsg'] = '请输入11位手机号'
        return HttpResponse(json.dumps(response,ensure_ascii=False),content_type="application/json")
    if _telephone.isdigit() == False:
        response['code'] = -1
        response['errorMsg'] = '请输入有效的手机号'
        return HttpResponse(json.dumps(response,ensure_ascii=False),content_type="application/json")
    CM_prog = re.compile(r"^1(34[0-8]|(3[5-9]|5[017-9]|8[278])\d)\d{7}$")
    CU_prog = re.compile(r"^1(3[0-2]|5[256]|8[56])\d{8}$")
    CT_prog = re.compile(r"^1((33|53|8[09])[0-9]|349)\d{7}$")
    telephone_match_CM = CM_prog.match(_telephone)
    telephone_match_CU = CU_prog.match(_telephone)
    telephone_match_CT = CT_prog.match(_telephone)

    if not telephone_match_CM and not telephone_match_CT and not telephone_match_CU:
        response['code'] =  -1
        response['errorMsg'] = '请输入有效的手机号'
        return HttpResponse(json.dumps(response,ensure_ascii=False),content_type="application/json")
    saved_verify_code = cache.get(_telephone)
    if not saved_verify_code:
        response['code'] = -1
        response['errorMsg'] = '请重新发送验证码'
        return HttpResponse(json.dumps(response,ensure_ascii=False),content_type="application/json")
    if saved_verify_code != _verify_code:
        response['code'] = -1
        response['errorMsg'] = '验证码错误,请重新输入'
        return HttpResponse(json.dumps(response,ensure_ascii=False),content_type="application/json")
    query_cook = Cook.objects.filter(telephone = _telephone)
    if not query_cook.exists():
        _name = '****'+_telephone[7:11]
        _headImage = 'http://meiyue.b0.upaiyun.com/head/1_head.jpg'
        cook = Cook(telephone = _telephone, name = _name, headImage = _headImage,shop = shop)
        cook.save()
        response['code'] = 0
        response_data = {}
        response_data['waiterOrderId'] = cook.id
        response_data['waiterOrderName'] = cook.name
        response_data['waiterOrderTelepohone'] = cook.telephone
        response['data'] = response_data
        return HttpResponse(json.dumps(response,ensure_ascii=False),content_type="application/json")
    cook = query_cook[0]
    cook.shop = shop
    cook.save()
    response['code'] = 0
    response_data = {}
    response_data['waiterOrderId'] = cook.id
    response_data['waiterOrderName'] = cook.name
    response_data['waiterOrderTelepohone'] = cook.telephone
    response['data'] = response_data
    return HttpResponse(json.dumps(response,ensure_ascii=False),content_type="application/json")