Ejemplo n.º 1
0
func (user *User) checkBodyCreate(request *restful.Request, response *restful.Response, chain *restful.FilterChain) {
	private := UserCreate{}
	errors := api.Error{}

	err := request.ReadEntity(&private)
	if err != nil {
		response.AddHeader("Content-Type", "text/plain")
		response.WriteErrorString(http.StatusInternalServerError, err.Error())
		helpers.PrintLog(request, response, user.Name)
		return
	}

	user.Email = strings.TrimSpace(private.Email)
	user.Name = helpers.RemoveManySpaces(helpers.MakeFirstUpperCase(strings.ToLower(private.Name)))

	if user.isTwoPasswordAreIdentical(private.Password, private.Password2) == false {
		errors.ListErrors = append(errors.ListErrors, "Two passwords aren't identical")
		response.WriteHeaderAndEntity(http.StatusNotAcceptable, errors)
		helpers.PrintLog(request, response, user.Name)
		return
	}
	if len(private.Password) < 6 {
		errors.ListErrors = append(errors.ListErrors, "Your password must contain at least 6 characters")
		response.WriteHeaderAndEntity(http.StatusNotAcceptable, errors)
		helpers.PrintLog(request, response, user.Name)
		return
	}
	user.Password = private.Password
	chain.ProcessFilter(request, response)
}
Ejemplo n.º 2
0
//check body of create request
func (post *Post) checkBodyCreate(request *restful.Request, response *restful.Response, chain *restful.FilterChain) {
	create := CreatePost{}
	err := request.ReadEntity(&create)

	if err != nil {
		response.AddHeader("Content-Type", "text/plain")
		response.WriteErrorString(http.StatusInternalServerError, err.Error())
		helpers.PrintLog(request, response, post.user.Name)
		return
	}
	post.Content = helpers.RemoveManySpaces(create.Content)
	post.StartAt = create.StartAt
	post.EndAt = create.EndAt
	chain.ProcessFilter(request, response)
}
Ejemplo n.º 3
0
func (place *Place) checkFormParameter(request *restful.Request, response *restful.Response, chain *restful.FilterChain) {
	place.Name = helpers.RemoveManySpaces(sanitize.Accents(request.Request.FormValue("name")))
	place.City = helpers.RemoveManySpaces(sanitize.Accents(request.Request.FormValue("city")))
	place.Country = helpers.RemoveManySpaces(sanitize.Accents(request.Request.FormValue("country")))
	place.Type = helpers.RemoveManySpaces(sanitize.Accents(request.Request.FormValue("type")))
	place.Recurring, _ = strconv.ParseBool(request.Request.FormValue("recurring"))
	place.Address = helpers.RemoveManySpaces(sanitize.Accents(request.Request.FormValue("address")))
	place.PostalCode = helpers.RemoveManySpaces(sanitize.Accents(request.Request.FormValue("postalcode")))
	place.StartAt, _ = time.Parse("2006-01-02T15:04:05.000Z", request.Request.FormValue("startAt"))
	place.EndAt, _ = time.Parse("2006-01-02T15:04:05.000Z", request.Request.FormValue("endAt"))
	chain.ProcessFilter(request, response)
}
Ejemplo n.º 4
0
func (message *Message) checkContent(request *restful.Request, response *restful.Response, chain *restful.FilterChain) {
	message.Content = helpers.RemoveManySpaces(request.Request.FormValue("content"))
	if len(message.Content) > 2000 {
		errors := api.Error{}
		errors.ListErrors = append(errors.ListErrors, "a message must be maximum 2000 characters")
		response.WriteHeaderAndEntity(http.StatusNotAcceptable, errors)
		helpers.PrintLog(request, response, message.user.Name)
		return
	}
	if len(message.Content) == 0 {
		errors := api.Error{}
		errors.ListErrors = append(errors.ListErrors, "you're message is empty")
		response.WriteHeaderAndEntity(http.StatusNotAcceptable, errors)
		helpers.PrintLog(request, response, message.user.Name)
		return
	}
	chain.ProcessFilter(request, response)
}
Ejemplo n.º 5
0
func (place *Place) checkBody(request *restful.Request, response *restful.Response, chain *restful.FilterChain) {
	create := CreatePlace{}
	err := request.ReadEntity(&create)
	if err != nil {
		helpers.PrintLog(request, response, place.user.Name)

		response.AddHeader("Content-Type", "text/plain")
		response.WriteErrorString(http.StatusInternalServerError, err.Error())
		return
	}
	place.City = helpers.RemoveManySpaces(sanitize.Accents(create.City))
	place.Country = helpers.RemoveManySpaces(sanitize.Accents(create.Country))
	place.Name = helpers.RemoveManySpaces(sanitize.Accents(create.Name))
	place.Type = helpers.RemoveManySpaces(create.Type)
	place.Recurring, _ = strconv.ParseBool(create.Recurring)
	place.StartAt = create.StartAt
	place.EndAt = create.EndAt
	place.Address = helpers.RemoveManySpaces(create.Address)
	place.PostalCode = helpers.RemoveManySpaces(create.PostalCode)
	chain.ProcessFilter(request, response)
}
Ejemplo n.º 6
0
func (post *Post) checkFormParameter(request *restful.Request, response *restful.Response, chain *restful.FilterChain) {
	post.Content = helpers.RemoveManySpaces(request.Request.FormValue("content"))
	post.StartAt, _ = time.Parse("2006-01-02T15:04:05.000Z", "1999-08-08T16:07:29.174Z")
	post.EndAt, _ = time.Parse("2006-01-02T15:04:05.000Z", "1999-08-08T16:07:29.174Z")
	chain.ProcessFilter(request, response)
}