def completeUserInfo(data, files):
    try:
        userId = data["user_id"]
    except KeyError:
        return util.errorJsonWrapper("注册数据没有user_id字段")
    try:
        userToken = data["user_token"]
    except KeyError:
        return util.errorJsonWrapper("注册数据没有user_token字段")

    if not util.checkToken(userId, userToken):
        return util.errorJsonWrapper("token 验证失败")

    try:
        userGender = data["user_gender"]
    except KeyError:
        return util.errorJsonWrapper("注册数据没有user_gender字段")
    try:
        userAge = data["user_age"]
    except KeyError:
        return util.errorJsonWrapper("注册数据没有user_age字段")
    try:
        userAddress = data["user_address"]
    except KeyError:
        return util.errorJsonWrapper("注册数据没有user_address字段")
    try:
        userNickname = data["user_nickname"]
    except KeyError:
        return util.errorJsonWrapper("注册数据没有user_nickname字段")
    try:
        userInterest = data["user_interest"]
    except KeyError:
        return util.errorJsonWrapper("注册数据没有user_interest字段")
    

    FIllin = models.User.objects.get(user_id=userId)

    if FIllin:
        try:
            FIllin.user_gender = userGender
            FIllin.user_age = userAge
            FIllin.user_address = userAddress
            FIllin.user_nickname = userNickname
            FIllin.user_interest = userInterest
            
            picName = util.savePicture(files,"user_avatar",2*1024*1024)
            if picName == -1:
                return util.errorJsonWrapper("failed")
            if picName != "":
                FIllin.user_avatar = picName 

            FIllin.save()

        except Exception:
            return util.errorJsonWrapper("用户数据写入数据库出错")

        return util.simpleOkJsonWrapper()

    else:
        return util.errorJsonWrapper("该用户不存在")
Example #2
0
def authenticateUser(data, files):
    try:
        userId = data["user_id"]
    except KeyError:
        return util.errorJsonWrapper("请求数据没有user_id字段")
    try:
        userToken = data["user_token"]
    except KeyError:
        return util.errorJsonWrapper("请求数据没有token字段")

    if not util.checkToken(userId, userToken):
        return util.errorJsonWrapper("token 验证失败")

    user = models.User.objects.get(user_id=userId)

    if user:
        try:
            picName = util.savePicture(files, "user_authenticated_picture",
                                       20 * 1024 * 1024)
            if picName == -1:
                return util.errorJsonWrapper("failed")
            user.user_authenticated_picture = picName
            user.user_authenticated = True
            user.save()

        except Exception:
            return util.errorJsonWrapper("用户认证信息存入数据库出错")

        return util.simpleOkJsonWrapper("用户认证成功")
    else:
        return util.errorJsonWrapper("该用户不存在")
Example #3
0
def register(data):
    try:
        userId = data["user_id"]
    except KeyError:
        return util.errorJsonWrapper("注册数据没有user_id字段")

    try:
        userPassword = data["user_password"]
    except KeyError:
        return util.errorJsonWrapper("注册数据没有user_id字段")

    userPassword = hashlib.md5(userPassword).hexdigest()

    checkRes = models.User.objects.filter(user_id = userId)

    if len(checkRes) == 0:
        try:
            tmpUser = models.User(user_id = userId, user_password = userPassword)
            tmpUser.save()
        except Exception:
            return util.errorJsonWrapper("register 数据写入数据库出错")

        return util.simpleOkJsonWrapper()
    else:
        return util.errorJsonWrapper("注册失败,该手机号已经被注册")
def authenticateUser(data, files):
    try:
        userId = data["user_id"]
    except KeyError:
        return util.errorJsonWrapper("请求数据没有user_id字段")
    try:
        userToken = data["user_token"]
    except KeyError:
        return util.errorJsonWrapper("请求数据没有token字段")

    if not util.checkToken(userId, userToken):
        return util.errorJsonWrapper("token 验证失败")

    user = models.User.objects.get(user_id=userId)

    if user:
        try:
            picName = util.savePicture(files,"user_authenticated_picture",20*1024*1024)
            if picName == -1:
                return util.errorJsonWrapper("failed")
            user.user_authenticated_picture = picName 
            user.user_authenticated = True
            user.save()

        except Exception:
            return util.errorJsonWrapper("用户认证信息存入数据库出错")

        return util.simpleOkJsonWrapper("用户认证成功")
    else:
        return util.errorJsonWrapper("该用户不存在")
Example #5
0
def login(data):
    userID = data.get("user_id")
    token = data.get("user_token")
    password = data.get("user_password")
    user = models.User.objects.filter(user_id = userID).first()

    if not user:
        return util.errorJsonWrapper("不存在该用户名")
    else:
        if token:
            if str(datetime.datetime.now()) < user.user_token_overdue:
                if token == user.user_token:
                    return util.simpleOkJsonWrapper()
                else:
                    return util.errorJsonWrapper("token错误")
            else:
                return util.errorJsonWrapper("token已过期")


        if password:
            if user.user_password != hashlib.md5(password).hexdigest():
                return util.errorJsonWrapper("密码错误")
            else:
                token = hashlib.md5(userID + password + str(datetime.datetime.now())).hexdigest()
                user.user_token = token
                user.user_token_overdue = str(datetime.datetime.now() + datetime.timedelta(seconds = 30))
                user.save()
                tokenDict = {"user_token" : token}
                #retList = []
                #retList.append(tokenDict)
                res = dict(retCode=0, retMsg="", retValue = tokenDict)
                return json.dumps(res)
def issueFosterPetInfo(data):
    try:
        userId = data["user_id"]
    except KeyError:
        return util.errorJsonWrapper("寄养消息没有user_id字段")

    try:
        activityId = data["activity_id"]
    except KeyError:
        return util.errorJsonWrapper("寄养消息没有activity_id字段")
    
    checkUserId = models.User.objects.filter(user_id=userId)
    if len(checkUserId) == 0:
        return util.errorJsonWrapper("不存在该userId用户")

    checkActivityId = models.Activity.objects.filter(pk=activityId)
    if len(checkActivityId) == 0:
        return util.errorJsonWrapper("不存在该activity_id活动")


    try:
        tmpParticipant = models.Participant(participant_user_id = checkUserId[0], participant_activity_id=checkActivityId[0], participant_user_type=2)
        tmpParticipant.save()
        return util.simpleOkJsonWrapper()
    except Exception:
        return util.errorJsonWrapper("Participant 数据写入数据库出错")
Example #7
0
def register(data):
    try:
        userId = data["user_id"]
    except KeyError:
        return util.errorJsonWrapper("注册数据没有user_id字段")

    try:
        userPassword = data["user_password"]
    except KeyError:
        return util.errorJsonWrapper("注册数据没有user_id字段")

    userPassword = hashlib.md5(userPassword).hexdigest()

    checkRes = models.User.objects.filter(user_id=userId)

    if len(checkRes) == 0:
        try:
            tmpUser = models.User(user_id=userId, user_password=userPassword)
            tmpUser.save()
        except Exception:
            return util.errorJsonWrapper("register 数据写入数据库出错")

        return util.simpleOkJsonWrapper()
    else:
        return util.errorJsonWrapper("注册失败,该手机号已经被注册")
def issueFosterPetInfo(data):
    try:
        userId = data["user_id"]
    except KeyError:
        return util.errorJsonWrapper("寄养消息没有user_id字段")

    try:
        activityId = data["activity_id"]
    except KeyError:
        return util.errorJsonWrapper("寄养消息没有activity_id字段")

    checkUserId = models.User.objects.filter(user_id=userId)
    if len(checkUserId) == 0:
        return util.errorJsonWrapper("不存在该userId用户")

    checkActivityId = models.Activity.objects.filter(pk=activityId)
    if len(checkActivityId) == 0:
        return util.errorJsonWrapper("不存在该activity_id活动")

    try:
        tmpParticipant = models.Participant(
            participant_user_id=checkUserId[0],
            participant_activity_id=checkActivityId[0],
            participant_user_type=2)
        tmpParticipant.save()
        return util.simpleOkJsonWrapper()
    except Exception:
        return util.errorJsonWrapper("Participant 数据写入数据库出错")
Example #9
0
def completeUserInfo(data, files):
    try:
        userId = data["user_id"]
    except KeyError:
        return util.errorJsonWrapper("注册数据没有user_id字段")
    try:
        userToken = data["user_token"]
    except KeyError:
        return util.errorJsonWrapper("注册数据没有user_token字段")

    if not util.checkToken(userId, userToken):
        return util.errorJsonWrapper("token 验证失败")

    try:
        userGender = data["user_gender"]
    except KeyError:
        return util.errorJsonWrapper("注册数据没有user_gender字段")
    try:
        userAge = data["user_age"]
    except KeyError:
        return util.errorJsonWrapper("注册数据没有user_age字段")
    try:
        userAddress = data["user_address"]
    except KeyError:
        return util.errorJsonWrapper("注册数据没有user_address字段")
    try:
        userNickname = data["user_nickname"]
    except KeyError:
        return util.errorJsonWrapper("注册数据没有user_nickname字段")
    try:
        userInterest = data["user_interest"]
    except KeyError:
        return util.errorJsonWrapper("注册数据没有user_interest字段")

    FIllin = models.User.objects.get(user_id=userId)

    if FIllin:
        try:
            FIllin.user_gender = userGender
            FIllin.user_age = userAge
            FIllin.user_address = userAddress
            FIllin.user_nickname = userNickname
            FIllin.user_interest = userInterest

            picName = util.savePicture(files, "user_avatar", 2 * 1024 * 1024)
            if picName == -1:
                return util.errorJsonWrapper("failed")
            if picName != "":
                FIllin.user_avatar = picName

            FIllin.save()

        except Exception:
            return util.errorJsonWrapper("用户数据写入数据库出错")

        return util.simpleOkJsonWrapper()

    else:
        return util.errorJsonWrapper("该用户不存在")
def issueFosterPetInfo(data):
    try:
        userId = data["user_id"]
    except KeyError:
        return util.errorJsonWrapper("请求数据没有user_id字段")
    try:
        userToken = data["user_token"]
    except KeyError:
        return util.errorJsonWrapper("请求数据没有token字段")

    if not util.checkToken(userId, userToken):
        return util.errorJsonWrapper("token 验证失败")

    try:
        activityId = data["activity_id"]
    except KeyError:
        return util.errorJsonWrapper("寄养消息没有activity_id字段")
     
    checkUserId = models.User.objects.filter(user_id=userId)
    if len(checkUserId) == 0:
        return util.errorJsonWrapper("不存在该userId用户")

    checkActivityId = models.Activity.objects.filter(pk=activityId)
    if len(checkActivityId) == 0:
        return util.errorJsonWrapper("不存在该activity_id活动")
    
    #判断该活动是否已经被别人寄养
    isParAdopted = models.Participant.objects.filter(participant_activity = checkActivityId[0], participant_user_type = 1,
            participant_status = 1)

    if isParAdopted:
        return util.errorJsonWrapper("该活动已经被别人寄养")

    #判断是否已经有取消状态的订单
    parti = models.Participant.objects.filter(participant_user = checkUserId[0], participant_activity = checkActivityId[0], 
            participant_user_type = 2, participant_status = 2)
    try:
        if parti:
            parti.participant_status = 1
            parti.save()
        else:
            tmpParticipant = models.Participant(participant_user = checkUserId[0], participant_activity = checkActivityId[0], 
                    participant_user_type=2, participant_status = 1)
            tmpParticipant.save()


        adoptParticipant = models.Participant.objects.filter(participant_activity = checkActivityId[0], participant_user_type=1)
        for parti in adoptParticipant:
            parti.participant_status = 1
            parti.save()
    
        return util.simpleOkJsonWrapper()
    except Exception:
        return util.errorJsonWrapper("Participant 数据写入数据库出错")
Example #11
0
def completeUserInfo(data, files):
    try:
        userId = data["user_id"]
    except KeyError:
        return util.errorJsonWrapper("注册数据没有user_id字段")

    try:
        userGender = data["user_gender"]
    except KeyError:
        return util.errorJsonWrapper("注册数据没有user_gender字段")
    try:
        userAge = data["user_age"]
    except KeyError:
        return util.errorJsonWrapper("注册数据没有user_age字段")
    try:
        userAddress = data["user_address"]
    except KeyError:
        return util.errorJsonWrapper("注册数据没有user_address字段")
    try:
        userNickname = data["user_nickname"]
    except KeyError:
        return util.errorJsonWrapper("注册数据没有user_nickname字段")
    try:
        userInterest = data["user_interest"]
    except KeyError:
        return util.errorJsonWrapper("注册数据没有user_interest字段")
    

    FIllin = models.User.objects.get(user_id=userId)

    if FIllin:
        try:
            FIllin.user_gender = userGender
            FIllin.user_age = userAge
            FIllin.user_address = userAddress
            FIllin.user_nikename = userNickname
            #FIllin.user_longitude = userLongitude
            #FIllin.user_latitude = userLatitude
            FIllin.user_interest = userInterest
            
            #保存头像地址
            FIllin.user_avatar = saveUserAvatar(files)
            #return util.errorJsonWrapper(saveUserAvatar(files))

            FIllin.save()

        except Exception:
            return util.errorJsonWrapper("用户数据写入数据库出错")

        return util.simpleOkJsonWrapper()

    else:
        return util.errorJsonWrapper("该用户不存在")
Example #12
0
def login(data):
    userID = data.get("user_id")
    password = data.get("user_password")
    user = models.User.objects.filter(user_id = userID).first()
    if not user:
        return util.errorJsonWrapper("不存在该用户名")
    else:
        if not password:
            return util.errorJsonWrapper("请输入密码")
        elif user.user_password != hashlib.md5(password).hexdigest():
            return util.errorJsonWrapper("密码错误")
        else:
            return util.simpleOkJsonWrapper()
Example #13
0
def issueAdoptPetInfo(data):
    EVENT_STATUS = 0
    ADOPT = 1
    userId = data.get("user_id")
    user = models.User.objects.filter(user_id = userId).first()
    if not user:
        return util.errorJsonWrapper("不存在该用户")

    # check token by stanwu
    token = data.get("user_token")
    if token != user.user_token:
        return util.errorJsonWrapper("token错误")

    activityPic = data.get("activity_picture")
    activityIntro = data.get("activity_introduction")
    activityAddr = data.get("activity_address")
    activityLongi = data.get("activity_longitude")
    activityLati = data.get("activity_latitude")
    activityPet = data.get("activity_pet_type")
    activityPrice = data.get("activity_price")
    activityStartTime = data.get("activity_start_time")
    activityEndTime = data.get("activity_end_time")

    try:
        activity = models.Activity( activity_introduction = activityIntro,
                                activity_picture = activityPic,
                                activity_price = activityPrice,
                                activity_pet_type = activityPet,
                                activity_start_time = activityStartTime,
                                activity_end_time = activityEndTime,
                                activity_status = EVENT_STATUS,
                                activity_address = activityAddr)
        activity.save()
    except Exception:
        return util.errorJsonWrapper("发布收养信息出错,activity无法写入数据库")

    try:
        participant = models.Participant(participant_user = user,
                                     participant_activity = activity,
                                     participant_user_type = ADOPT)
        participant.save()
    except Exception:
        return util.errorJsonWrapper("发布收养信息出错,participant无法写入数据库")

    return util.simpleOkJsonWrapper()
Example #14
0
def issueAdoptPetInfo(data):
    EVENT_STATUS = 0
    ADOPT = 1
    userId = data.get("user_id")
    user = models.User.objects.filter(user_id=userId).first()
    if not user:
        return util.errorJsonWrapper("不存在该用户")

    # check token by stanwu
    token = data.get("user_token")
    if token != user.user_token:
        return util.errorJsonWrapper("token错误")

    activityPic = data.get("activity_picture")
    activityIntro = data.get("activity_introduction")
    activityAddr = data.get("activity_address")
    activityLongi = data.get("activity_longitude")
    activityLati = data.get("activity_latitude")
    activityPet = data.get("activity_pet_type")
    activityPrice = data.get("activity_price")
    activityStartTime = data.get("activity_start_time")
    activityEndTime = data.get("activity_end_time")

    try:
        activity = models.Activity(activity_introduction=activityIntro,
                                   activity_picture=activityPic,
                                   activity_price=activityPrice,
                                   activity_pet_type=activityPet,
                                   activity_start_time=activityStartTime,
                                   activity_end_time=activityEndTime,
                                   activity_status=EVENT_STATUS,
                                   activity_address=activityAddr)
        activity.save()
    except Exception:
        return util.errorJsonWrapper("发布收养信息出错,activity无法写入数据库")

    try:
        participant = models.Participant(participant_user=user,
                                         participant_activity=activity,
                                         participant_user_type=ADOPT)
        participant.save()
    except Exception:
        return util.errorJsonWrapper("发布收养信息出错,participant无法写入数据库")

    return util.simpleOkJsonWrapper()
Example #15
0
def cancelFoster(data):
    userId = data.get("user_id")
    if not userId:
        return util.errorJsonWrapper("缺少user_id")

    user = models.User.objects.filter(user_id=userId).first()
    if not user:
        return util.errorJsonWrapper("该用户不存在")

    userToken = data.get("user_token")
    if not userToken:
        return util.errorJsonWrapper("token不存在")

    if not util.checkToken(userId, userToken):
        return util.errorJsonWrapper("token验证失败")

    activityId = data.get("activity_id")
    if not activityId:
        return util.errorJsonWrapper("缺少activity_id")

    activity = models.Activity.objects.filter(pk=activityId).first()
    if not activity:
        return util.errorJsonWrapper("该活动不存在")

    partAdopt = models.Participant.objects.filter(
        participant_activity=activity, participant_user_type=1).first()
    if not partAdopt:
        return util.errorJsonWrapper("不存在该收养用户")

    partFoster = models.Participant.objects.filter(
        participant_user=user, participant_activity=activity).first()
    if not partFoster:
        return util.errorJsonWrapper("不存在该寄养用户")

    try:
        partAdopt.participant_status = 0
        partAdopt.save()

        partFoster.participant_status = 2
        partFoster.save()
    except:
        return util.errorJsonWrapper("写入数据库出错")

    return util.simpleOkJsonWrapper(partFoster.participant_status)
Example #16
0
def cancelFoster(data):
    userId = data.get("user_id")
    if not userId:
        return util.errorJsonWrapper("缺少user_id")

    user = models.User.objects.filter(user_id = userId).first()
    if not user:
        return util.errorJsonWrapper("该用户不存在")

    userToken = data.get("user_token")
    if not userToken:
        return util.errorJsonWrapper("token不存在")

    if not util.checkToken(userId, userToken):
        return util.errorJsonWrapper("token验证失败")

    activityId = data.get("activity_id")
    if not activityId:
        return util.errorJsonWrapper("缺少activity_id")

    activity = models.Activity.objects.filter(pk = activityId).first()
    if not activity:
        return util.errorJsonWrapper("该活动不存在")
    
    partAdopt = models.Participant.objects.filter(participant_activity = activity, participant_user_type = 1).first()
    if not partAdopt:
        return util.errorJsonWrapper("不存在该收养用户")
    

    partFoster = models.Participant.objects.filter(participant_user = user, participant_activity = activity).first()
    if not partFoster:
        return util.errorJsonWrapper("不存在该寄养用户")

    try:
        partAdopt.participant_status = 0
        partAdopt.save()
        
        partFoster.participant_status = 2
        partFoster.save()
    except:
        return util.errorJsonWrapper("写入数据库出错")

    return util.simpleOkJsonWrapper(partFoster.participant_status)
Example #17
0
def logout(data):

    try:
        userId = data["user_id"]
    except KeyError:
        return util.errorJsonWrapper("请求数据没有user_id字段")
    try:
        userToken = data["user_token"]
    except KeyError:
        return util.errorJsonWrapper("请求数据没有token字段")

    if not util.checkToken(userId, userToken):
        return util.errorJsonWrapper("token 验证失败")

    user = models.User.objects.filter(user_id = userId).first()

    if not user:
        return util.errorJsonWrapper("不存在该用户名")
    else:
        user.user_token_overdue = str(datetime.datetime.now())
        user.save()
        return util.simpleOkJsonWrapper()
Example #18
0
def logout(data):

    try:
        userId = data["user_id"]
    except KeyError:
        return util.errorJsonWrapper("请求数据没有user_id字段")
    try:
        userToken = data["user_token"]
    except KeyError:
        return util.errorJsonWrapper("请求数据没有token字段")

    if not util.checkToken(userId, userToken):
        return util.errorJsonWrapper("token 验证失败")

    user = models.User.objects.filter(user_id=userId).first()

    if not user:
        return util.errorJsonWrapper("不存在该用户名")
    else:
        user.user_token_overdue = str(datetime.datetime.now())
        user.save()
        return util.simpleOkJsonWrapper()
Example #19
0
def issueFosterPetInfo(data):
    try:
        userId = data["user_id"]
    except KeyError:
        return util.errorJsonWrapper("请求数据没有user_id字段")
    try:
        userToken = data["user_token"]
    except KeyError:
        return util.errorJsonWrapper("请求数据没有token字段")

    if not util.checkToken(userId, userToken):
        return util.errorJsonWrapper("token 验证失败")

    try:
        activityId = data["activity_id"]
    except KeyError:
        return util.errorJsonWrapper("寄养消息没有activity_id字段")

    checkUserId = models.User.objects.filter(user_id=userId)
    if len(checkUserId) == 0:
        return util.errorJsonWrapper("不存在该userId用户")

    checkActivityId = models.Activity.objects.filter(pk=activityId)
    if len(checkActivityId) == 0:
        return util.errorJsonWrapper("不存在该activity_id活动")

    #判断该活动是否已经被别人寄养
    isParAdopted = models.Participant.objects.filter(
        participant_activity=checkActivityId[0],
        participant_user_type=1,
        participant_status=1)

    if isParAdopted:
        return util.errorJsonWrapper("该活动已经被别人寄养")

    #判断是否已经有取消状态的订单
    parti = models.Participant.objects.filter(
        participant_user=checkUserId[0],
        participant_activity=checkActivityId[0],
        participant_user_type=2,
        participant_status=2)
    try:
        if parti:
            parti.participant_status = 1
            parti.save()
        else:
            tmpParticipant = models.Participant(
                participant_user=checkUserId[0],
                participant_activity=checkActivityId[0],
                participant_user_type=2,
                participant_status=1)
            tmpParticipant.save()

        adoptParticipant = models.Participant.objects.filter(
            participant_activity=checkActivityId[0], participant_user_type=1)
        for parti in adoptParticipant:
            parti.participant_status = 1
            parti.save()

        return util.simpleOkJsonWrapper()
    except Exception:
        return util.errorJsonWrapper("Participant 数据写入数据库出错")