コード例 #1
0
ファイル: ride.go プロジェクト: hdiwan/RedRoute
func PutRideLikesUser(reqJson []byte, qs map[string][]string, uri []string, ac *dozy.AuthContext, rawDb interface{}) (uint, []byte, string) {
	db := rawDb.(PutRideLikesUserDb)

	rideId, err := strconv.Atoi(uri[1])
	if err != nil {
		panic(err)
	}

	userId, err := strconv.Atoi(uri[3])
	if err != nil {
		panic(err)
	}

	if !ac.GetLoggedIn() || ac.GetUserId() != uint(userId) {
		return dozy.StatusIncorrectPermissions, []byte(""), ""
	}

	isLiked := bson.M{}
	unmarshalErr := json.Unmarshal(reqJson, &isLiked)
	if unmarshalErr != nil {
		panic(unmarshalErr)
	}

	status, returnJson := db.AddLike(uint(rideId), uint(userId), isLiked["isLiked"].(bool))
	if status != mongodb.WriteSucceeded {
		return dozy.StatusBadRequest, []byte(""), ""
	}

	return dozy.StatusGetOk, returnJson, ""
}
コード例 #2
0
ファイル: ride.go プロジェクト: hdiwan/RedRoute
func PostRideComments(reqJson []byte, qs map[string][]string, uri []string, ac *dozy.AuthContext, rawDb interface{}) (uint, []byte, string) {
	db := rawDb.(PostRideCommentsDb)

	comment := bson.M{}
	unmarshalErr := json.Unmarshal(reqJson, &comment)
	if unmarshalErr != nil {
		panic(unmarshalErr)
	}

	rideId, err := strconv.Atoi(uri[1])
	if err != nil {
		panic(err)
	}

	if !ac.GetLoggedIn() {
		return dozy.StatusIncorrectPermissions, []byte(""), ""
	}

	status, returnJson, location := db.PostComment(uint(rideId), ac.GetUserId(), comment["content"].(string))
	if status != mongodb.WriteSucceeded {
		return dozy.StatusBadRequest, []byte(""), ""
	}

	return dozy.StatusPutOk, returnJson, location

}
コード例 #3
0
ファイル: ride.go プロジェクト: hdiwan/RedRoute
func PutRideTip(reqJson []byte, qs map[string][]string, uri []string, ac *dozy.AuthContext, rawDb interface{}) (uint, []byte, string) {
	db := rawDb.(PutRideTipDb)

	tip := bson.M{}
	unmarshalErr := json.Unmarshal(reqJson, &tip)
	if unmarshalErr != nil {
		panic(unmarshalErr)
	}

	rideId, err := strconv.Atoi(uri[1])
	if err != nil {
		panic(err)
	}

	if !ac.GetLoggedIn() {
		return dozy.StatusIncorrectPermissions, []byte(""), ""
	}

	status, returnJson := db.UpdateTip(uint(rideId), ac.GetUserId(), uint(tip["tip"].(int)))
	if status != mongodb.WriteSucceeded {
		return dozy.StatusBadRequest, []byte(""), ""
	}

	return dozy.StatusPutOk, returnJson, ""

}
コード例 #4
0
ファイル: users.go プロジェクト: hdiwan/RedRoute
func PutUsersDebtsPaymentToken(reqJson []byte, qs map[string][]string, uri []string, ac *dozy.AuthContext, rawDb interface{}) (uint, []byte, string) {
	db := rawDb.(PutUsersDebtsPaymentTokenDb)

	userId, convErr := strconv.Atoi(uri[1])
	if convErr != nil {
		return dozy.StatusBadRequest, []byte(""), ""
	}

	if !ac.GetLoggedIn() || ac.GetUserId() != uint(userId) {
		return dozy.StatusIncorrectPermissions, []byte(""), ""
	}

	paymentToken := bson.M{}
	unmarshalErr := json.Unmarshal(reqJson, &paymentToken)
	if unmarshalErr != nil {
		panic(unmarshalErr)
	}

	paymentToken["timeStamp"] = time.Now().Unix()

	status, returnJson := db.UpdatePaymentInfo(ac.GetUserId(), paymentToken)
	if status != mongodb.WriteSucceeded {
		return dozy.StatusNotFound, []byte(""), ""
	}

	return dozy.StatusPutOk, returnJson, ""
}
コード例 #5
0
ファイル: users.go プロジェクト: hdiwan/RedRoute
func PutUsersSettings(reqJson []byte, qs map[string][]string, uri []string, ac *dozy.AuthContext, rawDb interface{}) (uint, []byte, string) {
	db := rawDb.(PutUsersSettingsDb)
	userId, convErr := strconv.Atoi(uri[1])
	if convErr != nil {
		return dozy.StatusBadRequest, []byte(""), ""
	}

	if !ac.GetLoggedIn() || ac.GetUserId() != uint(userId) {
		return dozy.StatusIncorrectPermissions, []byte(""), ""
	}

	j := dozy.JsonObj{}
	unmarshalErr := json.Unmarshal(reqJson, &j)
	if unmarshalErr != nil {
		panic(unmarshalErr)
	}

	updateStatus, emailExists := db.UpdateSettings(ac.GetUserId(), j)
	if updateStatus != mongodb.WriteSucceeded {
		if emailExists {
			return dozy.StatusBadRequest, []byte(`{"succeeded": false, "failedBecauseEmailAlreadyExists": true}`), ""
		}
		return dozy.StatusBadRequest, []byte(`"{succeeded": false, "failedBecauseEmailAlreadyExists": false}`), ""
	}

	return dozy.StatusPutOk, []byte(`"{succeeded": true}`), ""
}
コード例 #6
0
ファイル: authtoken.go プロジェクト: hdiwan/RedRoute
func GetAuthtokenEmail(reqJson []byte, qs map[string][]string, uri []string, ac *dozy.AuthContext, rawDb interface{}) (uint, []byte, string) {
	db := rawDb.(GetAuthtokenEmailDb)

	var resJson map[string]interface{}

	if ac.GetLoggedIn() {
		return dozy.StatusIncorrectPermissions, []byte(""), ""
	}

	getHashStatus, hash, userId := db.GetUserHashIdByEmail(qs["email"][0])

	if getHashStatus == mongodb.ReadSucceeded {
		loginOk, needNewHash, newHash := ac.Login(userId, qs["password"][0], hash)

		if loginOk {
			resJson = map[string]interface{}{
				"succeeded": true,
				"authtoken": ac.GetAuthtoken(),
				"userId":    ac.GetUserId(),
			}

			if needNewHash {
				updateHashStatus := db.UpdateHashById(userId, newHash)

				if updateHashStatus != mongodb.WriteSucceeded {
					panic(updateHashStatus)
				}
			}
		} else {
			resJson = map[string]interface{}{
				"succeeded":              false,
				"failedDueToBadPassword": true,
				"failedDueToBadUsername": false,
			}
		}
	} else if getHashStatus == mongodb.ReadNotFound {
		resJson = map[string]interface{}{
			"succeeded":              false,
			"failedDueToBadPassword": false,
			"failedDueToBadUsername": true,
		}
	} else {
		panic(getHashStatus)
	}

	resJsonBytes, marshalErr := json.Marshal(resJson)
	if marshalErr != nil {
		panic(marshalErr)
	}
	return dozy.StatusGetOk, resJsonBytes, ""
}
コード例 #7
0
ファイル: ride.go プロジェクト: hdiwan/RedRoute
func PostRide(reqJson []byte, qs map[string][]string, uri []string, ac *dozy.AuthContext, rawDb interface{}) (uint, []byte, string) {
	db := rawDb.(PostRideDb)

	ride := bson.M{}
	unmarshalErr := json.Unmarshal(reqJson, &ride)
	if unmarshalErr != nil {
		panic(unmarshalErr)
	}

	if !ac.GetLoggedIn() {
		return dozy.StatusIncorrectPermissions, []byte(""), ""
	}

	returnJson, location := db.SetRide(ride, ac.GetUserId())

	return dozy.StatusPostOk, returnJson, location
}
コード例 #8
0
ファイル: users.go プロジェクト: hdiwan/RedRoute
func GetUsersNotificationsCount(reqJson []byte, qs map[string][]string, uri []string, ac *dozy.AuthContext, rawDb interface{}) (uint, []byte, string) {
	db := rawDb.(GetUsersNotificationsCountDb)

	userId, convErr := strconv.Atoi(uri[1])
	if convErr != nil {
		return dozy.StatusBadRequest, []byte(""), ""
	}

	if !ac.GetLoggedIn() || ac.GetUserId() != uint(userId) {
		return dozy.StatusIncorrectPermissions, []byte(""), ""
	}

	status, returnJson := db.GetNotificationsCount(ac.GetUserId())
	if status != mongodb.ReadSucceeded {
		return dozy.StatusNotFound, []byte(""), ""
	}

	return dozy.StatusGetOk, returnJson, ""
}
コード例 #9
0
ファイル: ride.go プロジェクト: hdiwan/RedRoute
func PutRideAcceptSplit(reqJson []byte, qs map[string][]string, uri []string, ac *dozy.AuthContext, rawDb interface{}) (uint, []byte, string) {
	db := rawDb.(PutAcceptSplitDb)

	splitDetails := bson.M{}
	unmarshalErr := json.Unmarshal(reqJson, &splitDetails)
	if unmarshalErr != nil {
		panic(unmarshalErr)
	}

	rideId, err := strconv.Atoi(uri[1])
	if err != nil {
		panic(err)
	}

	status, returnJson := db.AcceptSplit(uint(rideId), ac.GetUserId(), splitDetails["paymentNonce"].(string), uint(splitDetails["tip"].(int)))
	if status != mongodb.WriteSucceeded {
		return dozy.StatusBadRequest, []byte(""), ""
	}

	return dozy.StatusPutOk, returnJson, ""

}
コード例 #10
0
ファイル: users.go プロジェクト: hdiwan/RedRoute
func PutUsersMyPlaces(reqJson []byte, qs map[string][]string, uri []string, ac *dozy.AuthContext, rawDb interface{}) (uint, []byte, string) {
	db := rawDb.(PutUsersMyPlacesDb)
	userId, convErr := strconv.Atoi(uri[1])
	if convErr != nil {
		return dozy.StatusBadRequest, []byte(""), ""
	}

	if !ac.GetLoggedIn() || ac.GetUserId() != uint(userId) {
		return dozy.StatusIncorrectPermissions, []byte(""), ""
	}

	j := dozy.JsonObj{}
	unmarshalErr := json.Unmarshal(reqJson, &j)
	if unmarshalErr != nil {
		panic(unmarshalErr)
	}

	updateStatus := db.UpdateMyPlaces(ac.GetUserId(), j)
	if updateStatus != mongodb.WriteSucceeded {
		return dozy.StatusBadRequest, []byte(""), ""
	}

	return dozy.StatusPutOk, []byte(""), ""
}
コード例 #11
0
ファイル: users.go プロジェクト: hdiwan/RedRoute
func GetUsersProfile(reqJson []byte, qs map[string][]string, uri []string, ac *dozy.AuthContext, rawDb interface{}) (uint, []byte, string) {
	db := rawDb.(GetUsersProfileDb)

	userId, convErr := strconv.Atoi(uri[1])
	if convErr != nil {
		return dozy.StatusBadRequest, []byte(""), ""
	}

	numPostsToFetch, convErr1 := strconv.Atoi(qs["numPostsToFetch"][0])
	if convErr1 != nil {
		return dozy.StatusBadRequest, []byte(""), ""
	}

	startingPostNum, convErr2 := strconv.Atoi(qs["startingPostNum"][0])
	if convErr2 != nil {
		return dozy.StatusBadRequest, []byte(""), ""
	}

	status, responseJson := db.GetProfile(uint(userId), uint(numPostsToFetch), uint(startingPostNum), db.AreFriends(ac.GetUserId(), uint(userId)))
	if status != mongodb.WriteSucceeded {
		return dozy.StatusNotFound, []byte(""), ""
	}

	return dozy.StatusGetOk, responseJson, ""
}