Esempio n. 1
0
func registerUser(request router.Request) (int, []byte) {
	var registration UserResgistration
	err := json.Unmarshal(request.GetContent(), &registration)

	//Check for correct desrialization
	if err != nil {
		log.Errorf(request.GetContext(), "error: %v", err)
		return http.StatusBadRequest, []byte(err.Error())
	}

	//check if username already exists
	if IsUsernameAvailable(registration.UserName, request.GetContext()) {

		// generate a random salt with default rounds of complexity
		salt, _ := bcrypt.Salt()

		// hash and verify a password with random salt
		hash, _ := bcrypt.Hash(registration.Password)

		var user = UserData{registration.UserName, nil, salt, hash}
		err = SaveUserToGAE(user, request.GetContext())
		if err != nil {
			log.Errorf(request.GetContext(), "error: %v", err)
			return http.StatusInternalServerError, []byte(err.Error())
		} else {
			return http.StatusOK, nil
		}
	} else {
		return http.StatusConflict, []byte("Username not avaiable")
	}
}
//Create/Update an subscription for the given project
func postSubscription(request router.Request) (int, []byte) {

	var subscription Subscription
	err := json.Unmarshal(request.GetContent(), &subscription)
	if err != nil {
		log.Errorf(request.GetContext(), "error: %v", err)
		return http.StatusBadRequest, []byte(err.Error())
	}

	subscription.Project = request.GetPathParams()["project_id"]
	err = SaveSubscriptionToGAE(subscription, request.GetContext())

	if err != nil {
		log.Errorf(request.GetContext(), "error: %v", err)
		return http.StatusInternalServerError, []byte(err.Error())
	}

	return http.StatusOK, nil

}
Esempio n. 3
0
//Create/Update an alert for the given project
func postAlert(request router.Request) (int, []byte) {

	var alert Alert
	err := json.Unmarshal(request.GetContent(), &alert)
	if err != nil {
		log.Infof(request.GetContext(), "error: %v", err)
		return http.StatusBadRequest, []byte(err.Error())
	}

	//TODO Check Project Exists
	alert.Project = request.GetPathParams()["project_id"]
	err = SaveAlertToGAE(alert, request.GetContext())
	if err != nil {
		log.Infof(request.GetContext(), "error: %v", err)
		return http.StatusInternalServerError, []byte(err.Error())
	}

	return http.StatusOK, nil

}
Esempio n. 4
0
//Create/Update a project
//TODO: Check Admin/User Permissions
//TODO: Check required config present
//TODO: If create add to user project list
func updateProject(request router.Request) (int, []byte) {

	var project ProjectStruct
	err := json.Unmarshal(request.GetContent(), &project)
	if err != nil {
		log.Infof(request.GetContext(), "error: %v", err)
		return http.StatusBadRequest, []byte(err.Error())
	}

	projectDTO, err := project.GetDTO()
	if err != nil {
		return http.StatusInternalServerError, []byte(err.Error())

	}
	err = SaveProjectDTOToGAE(projectDTO, request.GetContext())

	if err != nil {
		log.Infof(request.GetContext(), "error: %v", err)
		return http.StatusInternalServerError, []byte(err.Error())
	}

	return http.StatusOK, nil
}