Example #1
0
def editParty(request):
    if request.method == 'POST':
        partyID = request.POST['partyID']
#        location = request.POST['location']
#        starttime = request.POST['starttime']
#        peopleMaximum = request.POST['peopleMaximum']
        description = request.POST['description']
        uID = request.POST['uID']
#        startdate = None
        
        location = ''
#        starttime = ''
#        peopleMaximum = 0
#        try:
#            startdate = datetime.datetime.strptime(re_a.search(starttime).group(), '%Y-%m-%d %H:%M:%S').date()
#        except:
#            startdate = None               
#        try:
#            starttime = datetime.datetime.strptime(re_a.search(starttime).group(), '%Y-%m-%d %H:%M:%S').time()
#        except Exception:
#            starttime = None
        if len(location) > 256:
            raise myException(ERROR_CREATEPARTY_LONG_LOCATION)
        
        user = User.objects.get(pk = uID)
        try:
            party = Party.objects.get(pk = partyID, creator = user)
        except Exception:
            raise myException(u'您要编辑的会议已被删除')
#        party.start_date = startdate
#        party.start_time = starttime
        party.description = description
#        party.address = location
#        party.limit_count = peopleMaximum
        party.save()
Example #2
0
def editParty(request):
    if request.method == "POST":
        partyID = request.POST["partyID"]
        location = request.POST["location"]
        starttime = request.POST["starttime"]
        peopleMaximum = request.POST["peopleMaximum"]
        description = request.POST["description"]
        uID = request.POST["uID"]
        try:
            startdate = datetime.datetime.strptime(re_a.search(starttime).group(), "%Y-%m-%d")
        except:
            startdate = None
        try:
            starttime = datetime.datetime.strptime(re_a.search(starttime).group(), "%H:%M:%S")
        except Exception:
            starttime = None
        if len(location) > 256:
            raise myException(ERROR_CREATEPARTY_LONG_LOCATION)

        user = User.objects.get(pk=uID)
        try:
            party = Party.objects.get(pk=partyID, creator=user)
        except Exception:
            raise myException(u"您要编辑的会议已被删除")
        party.start_date = startdate
        party.start_time = starttime
        party.descrption = description
        party.address = location
        party.limit_count = peopleMaximum
        party.save()
Example #3
0
def changePasswordByFinePWD(request):
    if request.method == "POST":
        uid = request.POST["uID"]
        newpassword = request.POST["newpassword"]
        user = User.objects.get(pk=uid)
        if newpassword == "":
            raise myException(ERROR_ACCOUNTREGIST_PWD_BLANK)
        if len(newpassword) > 16 or len(newpassword) < 6:
            raise myException(ERROR_ACCOUNTREGIST_PWD_LENTH_WRONG)
        user.set_password(newpassword)
        user.save()
Example #4
0
def accountRegist(request):
    if request.method == 'POST':
        username = request.POST['username']
        password = request.POST['password']
        if len(username) > 14 or len(username) < 6:
            raise myException(ERROR_ACCOUNTREGIST_USERNAME_LENTH_WRONG)
        if len(password) > 16 or len(password) < 6:
            raise myException(ERROR_ACCOUNTREGIST_PWD_LENTH_WRONG)
        if not re_username.match(username):
            raise myException(ERROR_ACCOUNTREGIST_USERNAME_INVALID_FORMAT)
        if User.objects.filter(username = username):
            raise myException(ERROR_ACCOUNTREGIST_USER_EXIST)
        user = User.objects.create_user(username, '', password)
        return {'uid':user.id}
Example #5
0
def changePassword(request):
    if request.method == "POST":
        uid = request.POST["uID"]
        originalpassword = request.POST["originalpassword"]
        newpassword = request.POST["newpassword"]
        user = User.objects.get(pk=uid)
        if newpassword == "":
            raise myException(ERROR_ACCOUNTREGIST_PWD_BLANK)
        if len(newpassword) > 16 or len(newpassword) < 6:
            raise myException(ERROR_ACCOUNTREGIST_PWD_LENTH_WRONG)
        if user.check_password(originalpassword):
            user.set_password(newpassword)
            user.save()
        else:
            raise myException(ERROR_CHANGE_PWD_WRONG_PWD)
Example #6
0
def GetPartyClientSeperatedList(request, pid, type):
    try:
        party = Party.objects.get(pk=pid)
    except:
        raise myException(u"该会议已被删除")
    if type == "all":
        clientparty_list = PartiesClients.objects.filter(party=party).order_by("apply_status")
    elif type == "applied":
        clientparty_list = PartiesClients.objects.filter(party=party, apply_status=u"apply")
    elif type == "refused":
        clientparty_list = PartiesClients.objects.filter(party=party, apply_status=u"reject")
    elif type == "donothing":
        clientparty_list = PartiesClients.objects.filter(party=party, apply_status=u"noanswer")
    clientList = []
    for clientparty in clientparty_list:
        if not clientparty.client.phone:
            cValue = clientparty.client.email
        else:
            cValue = clientparty.client.phone
        if type == "all":
            dic = {
                "cName": clientparty.client.name,
                "cValue": cValue,
                "backendID": clientparty.id,
                "status": clientparty.apply_status,
            }
        else:
            dic = {"cName": clientparty.client.name, "cValue": cValue, "backendID": clientparty.id}
        clientList.append(dic)
    return {"clientList": clientList}
Example #7
0
def unbindContact(request, type):
    if request.method == "POST":
        value = request.POST["value"]
        uid = request.POST["uid"]
        try:
            user = User.objects.get(pk=uid)
        except Exception:
            raise myException(ERROR_BINDING_NO_USER)
        if type == "email":
            userkey = hashlib.md5(value).hexdigest()
        else:
            userkey = generate_phone_code()
        data = {
            "latest_status": {
                "email": user.userprofile.email,
                "email_binding_status": user.userprofile.email_binding_status,
                "phone": user.userprofile.phone,
                "phone_binding_status": user.userprofile.phone_binding_status,
            }
        }
        # 确定当前用户状态是已绑定
        if (type == "email" and user.userprofile.email_binding_status != "bind") or (
            type == "phone" and user.userprofile.phone_binding_status != "bind"
        ):
            raise myException(ERROR_UNBINDING, status=ERROR_STATUS_DIFFERENT_UNBINDED, data=data)
        # 确定app端的绑定信息是用户最新的绑定信息
        if (type == "email" and user.userprofile.email != value) or (
            type == "phone" and user.userprofile.phone != value
        ):
            raise myException(ERROR_UNBINDING, status=ERROR_STATUS_DIFFERENT_UNBINDED, data=data)
        # 发送验证码
        binding_temp, created = UserBindingTemp.objects.get_or_create(
            user=user, binding_type=type, defaults={"binding_address": value, "key": userkey}
        )
        if not created:
            binding_temp.binding_addres = value
            binding_temp.key = userkey
            binding_temp.save()
        data = {
            "latest_status": {
                "email": user.userprofile.email,
                "email_binding_status": user.userprofile.email_binding_status,
                "phone": user.userprofile.phone,
                "phone_binding_status": user.userprofile.phone_binding_status,
            }
        }
        return data
Example #8
0
def verify_receipt(request):
    if request.method == 'POST':
        user = User.objects.get(pk = request.POST['user-ID'])
        
        url = 'https://sandbox.itunes.apple.com/verifyReceipt'
#        url = 'https://buy.itunes.apple.com/verifyReceipt'
        data = {
            'receipt-data': request.POST['receipt-data']
        }
        
        conn = urllib.urlopen(url, json.dumps(data))
        resp = conn.read()
        
        data = json.loads(resp)
        status = data['status']
        if str(status) == "0":
            receipt = data["receipt"]
            receipt_str = json.dumps(receipt)
            print data
            product_id = receipt["product_id"]
            purchase_date = receipt["original_purchase_date"][:19]
            original_transaction_id = receipt['original_transaction_id']
            purchase_date = datetime.datetime.strptime(purchase_date, "%Y-%m-%d %H:%M:%S") + datetime.timedelta(hours = 8)
            production_info = ProductionInfo.objects.get(production_apple_id = product_id)
            pay_money = production_info.pay_money
            pay_money_type = production_info.pay_money_type
            items_count = production_info.items_count
            apple_receipt_list = UserAppleReceipt.objects.filter(original_transaction_id = original_transaction_id)
            if apple_receipt_list:
                raise myException(u'重复的收据')
            else:
                UserAppleReceipt.objects.create(
                                                user = user,
                                                receipt = receipt_str,
                                                buy_time = purchase_date,
                                                pre_sms_count = user.userprofile.available_sms_count,
                                                final_sms_count = user.userprofile.available_sms_count + items_count,
                                                original_transaction_id = original_transaction_id,
                                                apple_production = production_info,
                                                premium = Premium.objects.latest('pk'),
                                                )
                user.userprofile.available_sms_count += items_count
                user.userprofile.save()
        return json.loads(resp)
    else:
        raise myException('Bad Request')
Example #9
0
def accountLogin(request):
    if request.method == 'POST':
        user = authenticate(username = request.POST['username'], password = request.POST['password'])
        if user:
            print user
            return {
                    'uid':user.id,
                    'name':user.username,
                    }
        else:
            print 'error'
            raise myException(ERROR_ACCOUNTLOGIN_INVALID_PWD)
Example #10
0
def resendMsg(request):
    if request.method == "POST":
        receivers = eval(request.POST["receivers"])
        content = request.POST["content"]
        subject = request.POST["subject"]
        _isapplytips = request.POST["_isapplytips"]
        _issendbyself = request.POST["_issendbyself"]
        msgType = request.POST["msgType"]
        partyID = request.POST["partyID"]
        uID = request.POST["uID"]
        addressType = request.POST["addressType"]
        user = User.objects.get(pk=uID)
        try:
            party = Party.objects.get(pk=partyID, creator=user)
        except Exception:
            raise myException(u"该会议会议已被删除")
        addressArray = []
        for i in range(len(receivers)):
            receiver = receivers[i]

            if msgType == "SMS":
                client, is_created = Client.objects.get_or_create(
                    phone=receiver["cValue"], name=receiver["cName"], creator=user
                )
            else:
                client, is_created = Client.objects.get_or_create(
                    phone=receiver["cValue"], name=receiver["cName"], creator=user
                )
            PartiesClients.objects.get_or_create(party=party, client=client, apply_status=u"noanswer")
            #            receiversDic = {
            #                            'addressType':addressType,
            #                            'addressData':receivers
            #                            }
            #            receiversString = simplejson.dumps(receiversDic)
            addressArray.append(receiver["cValue"])
        addressString = simplejson.dumps(addressArray)
        if msgType == "SMS":
            msg, created = SMSMessage.objects.get_or_create(party=party)
            msg.content = content
            msg.is_apply_tips = _isapplytips
            msg.is_send_by_self = _issendbyself
            msg.save()
            Outbox.objects.create(address=addressString, base_message=msg.basemessage_ptr)
        else:
            msg, created = EmailMessage.objects.get_or_create(party=party)
            msg.subject = subject
            msg.content = content
            msg.is_apply_tips = _isapplytips
            msg.is_send_by_self = _issendbyself
            msg.save()
            Outbox.objects.create(address=addressString, base_message=msg.basemessage_ptr)
        return {"partyId": party.id}
Example #11
0
def forgetPassword(request):
    if request.method == "POST" and "value" in request.POST:
        value = request.POST["value"]
        if re_email.match(value):
            try:
                user = User.objects.get(userprofile__email=value, userprofile__email_binding_status="bind")
            except Exception:
                raise myException(ERROR_FORGETPASSWORD_NO_USER_BY_EMAIL)
            sending_type = "email"
        elif re_username.match(value):
            try:
                user = User.objects.get(username=value)
            except Exception:
                raise myException(ERROR_FORGETPASSWORD_NO_USER_BY_USERNAME)
            if user.userprofile.phone and user.userprofile.phone_binding_status == "bind":
                sending_type = "sms"
                value = user.userprofile.phone
            elif user.userprofile.email and user.userprofile.email_binding_status == "bind":
                sending_type = "email"
                value = user.userprofile.email
            else:
                raise myException(ERROR_FORGETPASSWORD_NO_USER_BY_USERNAME_NO_BINDING)
        elif re_phone.match(regPhoneNum(value)):
            try:
                user = User.objects.get(userprofile__phone=regPhoneNum(value), userprofile__phone_binding_status="bind")
            except Exception:
                raise myException(ERROR_FORGETPASSWORD_NO_USER_BY_SMS)
            sending_type = "sms"
        else:
            raise myException(ERROR_FORGETPASSWORD_NO_USER_BY_USERNAME)
        temp_password = generate_phone_code()
        temp_pwd_data, created = AccountTempPassword.objects.get_or_create(
            user=user, defaults={"temp_password": temp_password, "sending_type": sending_type}
        )
        if not created:
            temp_pwd_data.sending_type = sending_type
            temp_pwd_data.save()
Example #12
0
def GetPartyClientMainCount(request, pid):
    try:
        party = Party.objects.get(pk=pid)
    except:
        raise myException(u"您要复制的会议已被删除")
    clientparty_list = PartiesClients.objects.filter(party=party)
    all_client_count = clientparty_list.count()
    applied_client_count = clientparty_list.filter(apply_status=u"apply").count()
    donothing_client_count = clientparty_list.filter(apply_status=u"noanswer").count()
    refused_client_count = clientparty_list.filter(apply_status=u"reject").count()
    return {
        "allClientcount": all_client_count,
        "appliedClientcount": applied_client_count,
        "refusedClientcount": refused_client_count,
        "donothingClientcount": donothing_client_count,
    }
Example #13
0
def saveNickName(request):
    if request.method == "POST":
        uid = request.POST["uid"]
        user = User.objects.get(pk=uid)
        nickname = request.POST["nickname"]
        if len(nickname) > 16:
            raise myException(ERROR_PROFILEPAGE_LONG_NAME)
        user.userprofile.true_name = nickname
        user.userprofile.save()
        return {
            "nickname": user.userprofile.true_name,
            "remaining_sms_count": user.userprofile.available_sms_count,
            "email": user.userprofile.email,
            "email_binding_status": user.userprofile.email_binding_status,
            "phone": user.userprofile.phone,
            "phone_binding_status": user.userprofile.phone_binding_status,
        }
Example #14
0
def GetPartyMsg(request, pid):
    try:
        party = Party.objects.get(pk=pid)
    except:
        raise myException(u"您要复制的会议已被删除")
    message = BaseMessage.objects.filter(party=party).order_by("-createtime")[0]
    messageType = message.get_subclass_type()
    # receivers = simplejson.loads(message.receivers)
    partiesclients_list = PartiesClients.objects.filter(party=party)
    receivers = []
    for partiesclients in partiesclients_list:
        dict = {}
        if messageType == "SMS":
            dict["cVal"] = partiesclients.client.phone
        else:
            dict["cVal"] = partiesclients.client.email
        dict["cName"] = partiesclients.client.name
        dict["backendID"] = partiesclients.id
        receivers.append(dict)
    print 1
    subObj = message.get_subclass_obj()
    print 2
    if messageType == "SMS":
        subject = ""
        content = subObj.content
    else:
        subject = subObj.subject
        content = subObj.content
    print {
        "msgType": messageType,
        "receiverArray": receivers,
        "receiverType": "iphone",
        "content": content,
        "subject": subject,
        "_isApplyTips": message.is_apply_tips,
        "_isSendBySelf": message.is_send_by_self,
    }
    return {
        "msgType": messageType,
        "receiverArray": receivers,
        "receiverType": "iphone",
        "content": content,
        "subject": subject,
        "_isApplyTips": message.is_apply_tips,
        "_isSendBySelf": message.is_send_by_self,
    }
Example #15
0
def accountLogin(request):
    if request.method == "POST":
        username = request.POST["username"]
        password = request.POST["password"]
        user = authenticate(username=username, password=password)
        if not user:
            user_temp_pwd_list = AccountTempPassword.objects.filter(temp_password=password, user__username=username)
            if user_temp_pwd_list:
                user = user_temp_pwd_list[0].user
                _israndomlogin = "******"
            for user_temp_pwd in user_temp_pwd_list:
                user_temp_pwd.delete()
        else:
            _israndomlogin = "******"
        if user:
            if "device_token" in request.POST:
                device_token = request.POST["device_token"]
                if device_token:
                    #                if request.POST['device_type'] == 'iphone':
                    usertoken, created = UserIPhoneToken.objects.get_or_create(
                        device_token=device_token, defaults={"user": user}
                    )
                    if usertoken.user != user:
                        usertoken.user = user
                        usertoken.save()

            if "clientId" in request.POST:
                clientId = request.POST["clientId"]
                if clientId:
                    #                if request.POST['device_type'] == 'iphone':
                    clientId, created = UserAndroidToken.objects.get_or_create(
                        device_token=clientId, defaults={"user": user}
                    )
                    if clientId.user != user:
                        clientId.user = user
                        clientId.save()
            return {
                "uid": user.id,
                "name": user.userprofile.true_name,
                "_israndomlogin": _israndomlogin,
                "user_remaining": user.userprofile.available_sms_count,
                "username": user.username,
            }
        else:
            print "error"
            raise myException(ERROR_ACCOUNTLOGIN_INVALID_PWD)
Example #16
0
def GetPartyClientSeperatedList(request, pid, type):
    try:
        party = Party.objects.get(pk = pid)
    except:
        raise myException(u'该会议已被删除')
    if type == "all":
        clientparty_list = PartiesClients.objects.select_related('client').filter(party = party).order_by('apply_status').order_by('is_check').order_by('client')
    elif type == 'applied':
        clientparty_list = PartiesClients.objects.select_related('client').filter(party = party, apply_status = u"apply").order_by('is_check').order_by('client')
    elif type == 'refused':
        clientparty_list = PartiesClients.objects.select_related('client').filter(party = party, apply_status = u"reject").order_by('is_check').order_by('client')
    elif type == 'donothing':
        clientparty_list = PartiesClients.objects.select_related('client').filter(party = party, apply_status = u"noanswer").order_by('is_check').order_by('client')
    clientList = []
    for clientparty in clientparty_list:
        if party.invite_type == 'email':
            cValue = clientparty.client.email
        else:
            cValue = clientparty.client.phone
        if 'read' in request.GET:
            if not clientparty.is_check:
                clientparty.is_check = True
                clientparty.save()
                is_checked = False
            else:
                is_checked = True
        else:
            is_checked = clientparty.is_check
        dic = {
               'cName':clientparty.client.name,
               'cValue':cValue,
               'isCheck':is_checked,
               'backendID':clientparty.id,
               'status':clientparty.apply_status,
               "msg":clientparty.leave_message
               }
        clientList.append(dic)
    party_list = Party.objects.filter(creator = party.creator)
    unreadCount = PartiesClients.objects.filter(party__in = party_list, is_check = False).count()
    return {
            'clientList':clientList,
            'unreadCount':unreadCount,
            }
Example #17
0
def accountRegist(request):
    if request.method == "POST":
        username = request.POST["username"]
        password = request.POST["password"]
        if username == "":
            raise myException(ERROR_ACCOUNTREGIST_USERNAME_BLANK)
        if password == "":
            raise myException(ERROR_ACCOUNTREGIST_PWD_BLANK)
        if len(username) > 14 or len(username) < 6:
            raise myException(ERROR_ACCOUNTREGIST_USERNAME_LENTH_WRONG)
        if len(password) > 16 or len(password) < 6:
            raise myException(ERROR_ACCOUNTREGIST_PWD_LENTH_WRONG)
        if not re_username_string.match(username):
            raise myException(ERROR_ACCOUNTREGIST_USERNAME_INVALID_FORMAT_HEAD)
        if not re_username.match(username):
            raise myException(ERROR_ACCOUNTREGIST_USERNAME_INVALID_FORMAT_STRING)
        if User.objects.filter(username=username):
            raise myException(ERROR_ACCOUNTREGIST_USER_EXIST)
        user = User.objects.create_user(username, "", password)
        if user:
            if "device_token" in request.POST:
                device_token = request.POST["device_token"]
                if device_token:
                    usertoken, created = UserIPhoneToken.objects.get_or_create(
                        device_token=device_token, defaults={"user": user}
                    )
                    if usertoken.user != user:
                        usertoken.user = user
                        usertoken.save()
            if "clientId" in request.POST:
                clientId = request.POST["clientId"]
                if clientId:
                    #                if request.POST['device_type'] == 'iphone':
                    clientId, created = UserAndroidToken.objects.get_or_create(
                        device_token=clientId, defaults={"user": user}
                    )
                    if clientId.user != user:
                        clientId.user = user
                        clientId.save()
        return {"uid": user.id}
Example #18
0
def GetPartyMsg(request, pid):
    try:
        party = Party.objects.get(pk = pid)
    except:
        raise myException(u'您要复制的会议已被删除')
    message = BaseMessage.objects.filter(party = party).order_by('-createtime')[0]
    messageType = message.get_subclass_type()
    #receivers = simplejson.loads(message.receivers)
    partiesclients_list = PartiesClients.objects.filter(party = party)
    receivers = []
    for partiesclients in partiesclients_list:
        dict = {}
        if messageType == 'SMS':
            dict['cVal'] = partiesclients.client.phone
        else:
            dict['cVal'] = partiesclients.client.email
        dict['cName'] = partiesclients.client.name
        dict['backendID'] = partiesclients.id
        receivers.append(dict)
    subObj = message.get_subclass_obj()
    if messageType == 'SMS':
        subject = ''
        content = subObj.content
    else:
        subject = subObj.subject
        content = subObj.content

    return {
            'msgType':messageType,
            'receiverArray':receivers,
            'receiverType':'iphone',
            'content':content,
            'subject':subject,
            '_isApplyTips':message.is_apply_tips,
            '_isSendBySelf':message.is_send_by_self
            }
Example #19
0
def GetPartyClientMainCount(request, pid):
    try:
        party = Party.objects.get(pk = pid)
    except:
        raise myException(u'您要复制的会议已被删除')
#    clientparty_list = PartiesClients.objects.filter(party = party)
#    all_client_count = clientparty_list.count()
#    applied_client_count = clientparty_list.filter(apply_status = u'apply').count()
#    donothing_client_count = clientparty_list.filter(apply_status = u'noanswer').count()
#    refused_client_count = clientparty_list.filter(apply_status = u'reject').count()
    #各个活动的人数情况
    party_clients = PartiesClients.objects.select_related('client').filter(party = party)
    client_counts = {
                     'party_content':'',
                    'allClientcount':0,
                    'appliedClientcount': 0,
                    'newAppliedClientcount':0,
                    'donothingClientcount':0,
                    'refusedClientcount':0,
                    'newRefusedClientcount':0,
                    }
    for party_client in party_clients:
#        if party_client.client.invite_type != 'public':
        client_counts['allClientcount'] += 1
        if party_client.apply_status == 'apply':
            client_counts['appliedClientcount'] += 1
        if party_client.apply_status == 'apply' and party_client.is_check == False:
            client_counts['newAppliedClientcount'] += 1 
        if party_client.apply_status == 'noanswer':
            client_counts['donothingClientcount'] += 1
        if party_client.apply_status == 'reject':
            client_counts['refusedClientcount'] += 1 
        if party_client.apply_status == 'reject' and party_client.is_check == False:
            client_counts['newRefusedClientcount'] += 1
    client_counts['party_content'] = party.description
    return client_counts
Example #20
0
def bindContact(request, type):
    if request.method == "POST":
        value = request.POST["value"]
        uid = request.POST["uid"]
        try:
            user = User.objects.get(pk=uid)
        except Exception:
            raise myException(ERROR_BINDING_NO_USER)
        if type == "email":
            userkey = hashlib.md5("%s:%s" % (uid, value)).hexdigest()
        else:
            userkey = generate_phone_code()
        data = {
            "latest_status": {
                "email": user.userprofile.email,
                "email_binding_status": user.userprofile.email_binding_status,
                "phone": user.userprofile.phone,
                "phone_binding_status": user.userprofile.phone_binding_status,
            }
        }
        # 数据有效性验证
        if type == "email" and not re_email.match(value):
            raise myException(ERROR_BINDING_INVAILID_EMAIL_FORMMAT)
        if type == "phone" and not re_phone.match(regPhoneNum(value)):
            raise myException(ERROR_BINDING_INVAILID_PHONE_FORMMAT)
        # 用户已经绑定了
        if type == "email" and user.userprofile.email_binding_status == "bind":
            if user.userprofile.email == value:
                raise myException("", status=ERROR_STATUS_HAS_BINDED, data=data)
            else:
                raise myException(
                    ERROR_BINDING_BY_EMAIL_DIFFERENT_BINDED, status=ERROR_STATUS_DIFFERENT_BINDED, data=data
                )
        elif type == "phone" and user.userprofile.phone_binding_status == "bind":
            if user.userprofile.email == value:
                raise myException("", status=ERROR_STATUS_HAS_BINDED, data=data)
            else:
                raise myException(
                    ERROR_BINDING_BY_PHONE_DIFFERENT_BINDED, status=ERROR_STATUS_DIFFERENT_BINDED, data=data
                )
        # 被别人绑定
        if (
            type == "email"
            and UserProfile.objects.filter(email=value, email_binding_status="bind").exclude(user=user).count() != 0
        ):
            raise myException(
                ERROR_BINDING_BY_EMAIL_HAS_BINDED_BY_OTHER, status=ERROR_STATUS_HAS_BINDED_BY_OTHER, data=data
            )
        elif (
            type == "phone"
            and UserProfile.objects.filter(phone=value, phone_binding_status="bind").exclude(user=user).count() != 0
        ):
            raise myException(
                ERROR_BINDING_BY_PHONE_HAS_BINDED_BY_OTHER, status=ERROR_STATUS_HAS_BINDED_BY_OTHER, data=data
            )
        if type == "phone":
            value = regPhoneNum(value)
        with transaction.commit_on_success():
            profile = user.userprofile
            if type == "phone":
                profile.phone = value
                profile.phone_binding_status = "waitingbind"
            else:
                profile.email = value
                profile.email_binding_status = "waitingbind"
            profile.save()
        with transaction.commit_on_success():
            binding_temp, created = UserBindingTemp.objects.get_or_create(
                user=user, binding_type=type, defaults={"binding_address": value, "key": userkey}
            )
            if not created:
                binding_temp.binding_address = value
                binding_temp.key = userkey
                binding_temp.save()
        data = {
            "latest_status": {
                "email": user.userprofile.email,
                "email_binding_status": user.userprofile.email_binding_status,
                "phone": user.userprofile.phone,
                "phone_binding_status": user.userprofile.phone_binding_status,
            }
        }
        return data
Example #21
0
def createParty(request):
    if request.method == "POST":
        receivers = eval(request.POST["receivers"])
        content = request.POST["content"]
        subject = request.POST["subject"]
        _isapplytips = request.POST["_isapplytips"]
        _issendbyself = request.POST["_issendbyself"]
        msgType = request.POST["msgType"]
        starttime = request.POST["starttime"]
        location = request.POST["location"]
        description = request.POST["description"]
        peopleMaximum = request.POST["peopleMaximum"]
        uID = request.POST["uID"]
        addressType = request.POST["addressType"]
        user = User.objects.get(pk=uID)
        try:
            startdate = datetime.datetime.strptime(re_a.search(starttime).group(), "%Y-%m-%d")
        except Exception:
            startdate = None
        try:
            starttime = datetime.datetime.strptime(re_a.search(starttime).group(), "%H:%M:%S")
        except Exception:
            starttime = None
        if len(location) > 256:
            raise myException(ERROR_CREATEPARTY_LONG_LOCATION)
        # 创建活动
        party = Party.objects.create(
            start_date=startdate,
            start_time=starttime,
            address=location,
            description=description,
            creator=user,
            limit_count=peopleMaximum,
        )
        addressArray = []
        for i in range(len(receivers)):
            receiver = receivers[i]

            if msgType == "SMS":
                client, is_created = Client.objects.get_or_create(
                    phone=receiver["cValue"], name=receiver["cName"], creator=user
                )
            else:
                client, is_created = Client.objects.get_or_create(
                    email=receiver["cValue"], name=receiver["cName"], creator=user
                )
            PartiesClients.objects.create(party=party, client=client)
            addressArray.append(receiver["cValue"])
        addressString = simplejson.dumps(addressArray)
        if msgType == "SMS":
            msg, created = SMSMessage.objects.get_or_create(party=party)
            msg.content = content
            msg.is_apply_tips = _isapplytips
            msg.is_send_by_self = _issendbyself
            msg.save()
            Outbox.objects.create(address=addressString, base_message=msg.basemessage_ptr)
        else:
            msg, created = EmailMessage.objects.get_or_create(party=party)
            msg.subject = subject
            msg.content = content
            msg.is_apply_tips = _isapplytips
            msg.is_send_by_self = _issendbyself
            msg.save()
            Outbox.objects.create(address=addressString, base_message=msg.basemessage_ptr)
        #        try :
        #            pass
        #            #send_emails(subject, content, SYS_EMAIL_ADDRESS, [receiver['cValue']])
        #        except:
        #            print 'exception'
        #            data['Email'] = u'邮件发送失败'

        return {"partyId": party.id}
Example #22
0
def verifyContact(request, type):
    if request.method == "POST":
        value = request.POST["value"]
        uid = request.POST["uid"]
        userkey = request.POST["verifier"]
        try:
            user = User.objects.get(pk=uid)
        except Exception:
            raise myException(ERROR_BINDING_NO_USER)
        data = {
            "latest_status": {
                "email": user.userprofile.email,
                "email_binding_status": user.userprofile.email_binding_status,
                "phone": user.userprofile.phone,
                "phone_binding_status": user.userprofile.phone_binding_status,
            }
        }
        # 确定当前用户状态是等待绑定状态或者是已绑定状态
        if (type == "email" and user.userprofile.email_binding_status == "unbind") or (
            type == "phone" and user.userprofile.phone_binding_status == "unbind"
        ):
            raise myException(ERROR_VERIFY, status=ERROR_STATUS_INVALID_VERIFIER, data=data)
        # 确定app端的绑定信息是用户最新的绑定信息
        if (type == "email" and user.userprofile.email != value) or (
            type == "phone" and user.userprofile.phone != value
        ):
            raise myException(ERROR_VERIFY, status=ERROR_STATUS_INVALID_VERIFIER, data=data)
        # 确定app端的绑定邮箱/手机号未被别的用户使用
        if (
            type == "email"
            and UserProfile.objects.filter(email=value, email_binding_status="bind").exclude(user=user).count() != 0
        ):
            raise myException(
                ERROR_VERIFYING_BY_EMAIL_HAS_BINDED_BY_OTHER, status=ERROR_STATUS_HAS_BINDED_BY_OTHER, data=data
            )
        elif (
            type == "phone"
            and UserProfile.objects.filter(phone=value, phone_binding_status="bind").exclude(user=user).count() != 0
        ):
            raise myException(
                ERROR_VERIFYING_BY_PHONE_HAS_BINDED_BY_OTHER, status=ERROR_STATUS_HAS_BINDED_BY_OTHER, data=data
            )

        # 确定app端绑定操作是否已经被正常操作过了
        if (
            type == "email" and user.userprofile.email_binding_status == "bind" and user.userprofile.email == value
        ) or (type == "phone" and user.userprofile.phone_binding_status == "bind" and user.userprofile.phone == value):
            return data

        # 开始解绑
        binding_temp = UserBindingTemp.objects.filter(user=user, binding_type=type, binding_address=value, key=userkey)
        if not binding_temp:
            raise myException(ERROR_VERIFYING_WRONG_VERIFIER, status=ERROR_STATUS_WRONG_VERIFIER, data=data)
        if type == "email":
            if user.userprofile.email_binding_status == "waitingbind":
                user.userprofile.email_binding_status = "bind"
                user.userprofile.save()
            elif user.userprofile.email_binding_status == "bind":
                user.userprofile.email_binding_status = "unbind"
                user.userprofile.email = ""
                user.userprofile.save()
        elif type == "phone":
            if user.userprofile.phone_binding_status == "waitingbind":
                user.userprofile.phone_binding_status = "bind"
                user.userprofile.save()
            elif user.userprofile.phone_binding_status == "bind":
                user.userprofile.phone_binding_status = "unbind"
                user.userprofile.phone = ""
                user.userprofile.save()
        for binding in binding_temp:
            binding.delete()
        data = {
            "latest_status": {
                "email": user.userprofile.email,
                "email_binding_status": user.userprofile.email_binding_status,
                "phone": user.userprofile.phone,
                "phone_binding_status": user.userprofile.phone_binding_status,
            }
        }
        return data
Example #23
0
def createParty(request):
    if request.method == 'POST' :
        receivers = eval(request.POST['receivers'])
        content = request.POST['content']
#        subject = request.POST['subject']
#        _isapplytips = request.POST['_isapplytips'] == '1'
        _issendbyself = request.POST['_issendbyself'] == '1'
#        msgType = request.POST['msgType']
#        starttime = request.POST['starttime']
#        location = request.POST['location']
#        description = request.POST['description']
#        peopleMaximum = request.POST['peopleMaximum']
        uID = request.POST['uID']
#        addressType = request.POST['addressType']
        user = User.objects.get(pk = uID)
        startdate = None
        
        subject = ''
        _isapplytips = True
        msgType = "SMS"
        starttime = ''
        location = ""
        description = content
        peopleMaximum = 0
        
        try:
            startdate = datetime.datetime.strptime(re_a.search(starttime).group(), '%Y-%m-%d %H:%M:%S').date()
        except Exception:
            startdate = None
        try:
            starttime = datetime.datetime.strptime(re_a.search(starttime).group(), '%Y-%m-%d %H:%M:%S').time()
        except Exception:
            starttime = None
#        if len(location) > 256:
#            raise myException(ERROR_CREATEPARTY_LONG_LOCATION)
        # 检测剩余短信余额是否足够————当条件_issendbyself==True时
        if _issendbyself:    
            number_of_message = (len(content) + SHORT_LINK_LENGTH + BASIC_MESSAGE_LENGTH - 1) / BASIC_MESSAGE_LENGTH
            client_phone_list_len = len(receivers)
            userprofile = user.get_profile() 
            sms_count = userprofile.available_sms_count
            will_send_message_num = client_phone_list_len * number_of_message #可能发送的从短信条数
            if will_send_message_num > sms_count:#短信人数*短信数目大于可发送的短信数目
                raise myException(ERROR_SEND_MSG_NO_REMAINING, status = ERROR_STATUS_SEND_MSG_NO_REMAINING, data = {'remaining':sms_count})
        with transaction.commit_on_success():
            #创建活动
            party = Party.objects.create(start_date = startdate,
                                         start_time = starttime,
                                         address = location,
                                         description = description,
                                         creator = user,
                                         limit_count = peopleMaximum,
                                         invite_type = (msgType == "SMS" and 'phone' or 'email')
                                         )
            creator_client, is_new = Client.objects.get_or_create(phone = user.userprofile.phone, creator = user)
            if creator_client.name != user.userprofile.nickname:
                creator_client.name = user.userprofile.nickname
                creator_client.save()
            PartiesClients.objects.create(party = party, client = creator_client, apply_status = u'apply')
            addressArray = []
            for i in range(len(receivers)):
                receiver = receivers[i]
                
                if msgType == 'SMS':
#                    client = Client.objects.get_or_create(phone = receiver['cValue'],
#                                                                      name = receiver['cName'],
#                                                                      creator = user,
#                                                                      )[0]
                    client_list = Client.objects.filter(phone = receiver['cValue'],
                                                        creator = user
                                                        ).exclude(name = '')
                    if client_list:
                        client = client_list[0]
                    else:
                        empty_name_client_list = Client.objects.filter(phone = receiver['cValue'],
                                                                       name = '',
                                                                       creator = user
                                                                       )
                        if empty_name_client_list:
                            client = empty_name_client_list[0]
                            client.name = receiver['cName']
                            client.save()
                        else:
                            client = Client.objects.create(phone = receiver['cValue'],
                                                           name = receiver['cName'],
                                                           creator = user,
                                                           invite_type = 'phone'
                                                           )
                    
                else:
                    client_list = Client.objects.filter(email = receiver['cValue'],
                                                        creator = user
                                                        ).exclude(name = '')
                    if client_list:
                        client = client_list[0]
                    else:
                        empty_name_client_list = Client.objects.filter(email = receiver['cValue'],
                                                                       name = '',
                                                                       creator = user
                                                                       )
                        if empty_name_client_list:
                            client = empty_name_client_list[0]
                            client.name = receiver['cName']
                            client.save()
                        else:
                            client = Client.objects.create(email = receiver['cValue'],
                                                           name = receiver['cName'],
                                                           creator = user,
                                                           invite_type = 'phone'
                                                           )
                PartiesClients.objects.create(
                                              party = party,
                                              client = client,
                                              ) 
                addressArray.append(receiver['cValue'])
            addressString = simplejson.dumps(addressArray)
            if msgType == 'SMS':
                msg = SMSMessage.objects.get_or_create(party = party)[0]
                msg.content = content
                msg.is_apply_tips = _isapplytips
                msg.is_send_by_self = _issendbyself
                msg.save()
            else:
                msg = EmailMessage.objects.get_or_create(party = party)[0]
                msg.subject = subject
                msg.content = content
                msg.is_apply_tips = _isapplytips
                msg.is_send_by_self = _issendbyself
                msg.save()
        
        if not msg.is_send_by_self:
            with transaction.commit_on_success():
                if addressArray:
                    addressString = ','.join(addressArray)
                    Outbox.objects.create(address = addressString, base_message = msg)
        return {
                'partyId':party.id,
                'applyURL':transfer_to_shortlink(DOMAIN_NAME + reverse('enroll', args = [party.id])),
                'sms_count_remaining':user.userprofile.available_sms_count,
                }
Example #24
0
def resendMsg(request):
    if request.method == "POST":
        receivers = eval(request.POST['receivers'])
        content = request.POST['content']
#        subject = request.POST['subject']
#        _isapplytips = request.POST['_isapplytips'] == '1'
        _issendbyself = request.POST['_issendbyself'] == '1'
#        msgType = request.POST['msgType']
        partyID = request.POST['partyID']
        uID = request.POST['uID']
#        addressType = request.POST['addressType']
        user = User.objects.get(pk = uID)
        
        subject = ''
        _isapplytips = True
        msgType = "SMS"
        
        try:
            party = Party.objects.get(pk = partyID, creator = user)
        except Exception:
            raise myException(u'该会议会议已被删除')
        
        # 检测剩余短信余额是否足够
        if _issendbyself:
            number_of_message = (len(content) + SHORT_LINK_LENGTH + BASIC_MESSAGE_LENGTH - 1) / BASIC_MESSAGE_LENGTH
            client_phone_list_len = len(receivers)
            userprofile = user.get_profile() 
            sms_count = userprofile.available_sms_count
            will_send_message_num = client_phone_list_len * number_of_message #可能发送的从短信条数
            if will_send_message_num > sms_count:#短信人数*短信数目大于可发送的短信数目
                raise myException(ERROR_SEND_MSG_NO_REMAINING, status = ERROR_STATUS_SEND_MSG_NO_REMAINING, data = {'remaining':sms_count})
        
        with transaction.commit_on_success():
            addressArray = []
            for i in range(len(receivers)):
                receiver = receivers[i]
                
                if msgType == 'SMS':
                    client_list = Client.objects.filter(phone = receiver['cValue'],
                                                        creator = user
                                                        )
                    if client_list:
                        client = client_list[0]
                        if client.name == '':
                            client.name = receiver['cName']
                            client.save()
                    else:
                        client = Client.objects.create(phone = receiver['cValue'],
                                                       name = receiver['cName'],
                                                       creator = user,
                                                       invite_type = 'phone'
                                                       )
                else:
                    client_list = Client.objects.filter(email = receiver['cValue'],
                                                        creator = user
                                                        )
                    if client_list:
                        client = client_list[0]
                        if client.name == '':
                            client.name = receiver['cName']
                            client.save()
                    else:
                        client = Client.objects.create(email = receiver['cValue'],
                                                       name = receiver['cName'],
                                                       creator = user,
                                                       invite_type = 'phone'
                                                       )
                PartiesClients.objects.get_or_create(
                                                  party = party,
                                                  client = client,
                                                  defaults = {
                                                              "apply_status":'noanswer'
                                                              }
                                                  ) 
                
                addressArray.append(receiver['cValue'])
    
            if msgType == 'SMS':
                msg = SMSMessage.objects.get_or_create(party = party)[0]
                msg.content = content
                msg.is_apply_tips = _isapplytips
                msg.is_send_by_self = _issendbyself
                msg.save()
            else:
                msg = EmailMessage.objects.get_or_create(party = party)[0]
                msg.subject = subject
                msg.content = content
                msg.is_apply_tips = _isapplytips
                msg.is_send_by_self = _issendbyself
                msg.save()
        
        if not msg.is_send_by_self:
            with transaction.commit_on_success():
                if addressArray:
                    addressString = ','.join(addressArray)
                    Outbox.objects.create(address = addressString, base_message = msg)
        
        return {
                'partyId':party.id,
                'applyURL':transfer_to_shortlink(DOMAIN_NAME + reverse('enroll', args = [party.id])),
                'sms_count_remaining':user.userprofile.available_sms_count,
                }