Beispiel #1
0
func setupRouting() *mux.Router {
	r := mux.NewRouter().
		PathPrefix("/api").
		Subrouter().
		StrictSlash(true)

	r.HandleFunc("/users", registerHandler).
		Methods("POST")

	r.HandleFunc("/users", loginHandler).
		Methods("GET")

	r.HandleFunc("/users/me", restrict.R(secretHandler)).
		Methods("GET")

	r.HandleFunc("/servers/{host}/{channel}/scrollback", restrict.R(messagesHandler)).
		Methods("GET")

	r.HandleFunc("/servers/default", defaultServerHandler).
		Methods("GET")

	r.HandleFunc("/ws", restrict.R(dispatchHandler))

	return r
}
Beispiel #2
0
func main() {
	conf.Use(configure.NewEnvironment())
	conf.Use(configure.NewFlag())

	conf.Parse()

	restrict.ReadCryptoKey(*crypto)

	models.Init(
		*dbUser,
		*dbPass,
		*dbService,
		*dbPort,
		*dbName,
	)

	fmt.Println("Welcome to pay.")

	r := mux.NewRouter().PathPrefix("/api").Subrouter().StrictSlash(true)

	r.HandleFunc("/ping", restrict.R(pingHandler)).
		Methods("GET")

	r.HandleFunc("/users", registerHandler).
		Methods("POST")
	r.HandleFunc("/users", loginHandler).
		Methods("GET")

	fmt.Println(http.ListenAndServe(":8080", r))
}
Beispiel #3
0
func GetUserHandler(w http.ResponseWriter, r *http.Request) {
	c := communicator.New(w)
	username := r.FormValue("username")
	sid := r.FormValue("id")

	if sid != "" {
		var id int64
		fmt.Sscanf(sid, "%d", &id)
		fmt.Println(id)

		u, err := models.GetUserByID(id)
		if err != nil {
			c.Fail("Error getting user")
			return
		}

		c.OKWithData("Here is your user: "******"" {
		u, err := models.GetUser("username", username)
		if err != nil {
			c.Fail("Could not get that username")
			return
		}

		c.OKWithData("Here is your user: "******"hello?")
		c := communicator.New(w)
		fid, ok := t.Claims["id"].(float64)
		if !ok {
			c.Fail("Could not get that ID")
			return
		}

		id := int64(fid)

		u, err := models.GetUserByID(id)
		if err != nil {
			c.Fail("Error getting user")
			return
		}

		c.OKWithData("Here is your user", u)

	})(w, r)
}
Beispiel #4
0
func main() {
	var err error
	db, err = sql.Open("sqlite3", "database.db")
	if err != nil {
		log.Println("Could not open DB")
		return
	}

	// Twilio Config
	from = "+14847184408"
	accountSid := "AC800a64542126d28255c7c82aa375627f"
	authToken := "f8c3c917be8b7ec2225a6066eff08719"
	twilio = gotwilio.NewTwilioClient(accountSid, authToken)

	r := mux.NewRouter()

	// User authentication, registration and management
	r.HandleFunc("/users/register", RegisterUserHandler).Methods("POST")
	r.HandleFunc("/users/login", LoginUserHandler).Methods("POST")
	r.HandleFunc("/users/info", restrict.R(InfoHandler)).Methods("GET")

	// Food graph handling
	r.HandleFunc("/foods/graph", FoodGraphHandler).Methods("GET")

	// Pantry management
	r.HandleFunc("/pantry", restrict.R(RegisterFoodHandler)).Methods("POST")
	r.HandleFunc("/pantry", restrict.R(AllFoodInPantryHandler)).Methods("GET")
	r.HandleFunc("/pantry/consume", restrict.R(ConsumeFoodHandler)).Methods("POST")

	r.HandleFunc("/pantry/queue", restrict.R(AddItemToQueueHandler)).Methods("POST")
	r.HandleFunc("/pantry/mass_change", restrict.R(MassChangeHandler)).Methods("POST")
	r.HandleFunc("/pantry/remove_poll", restrict.R(RemovePollHandler)).Methods("GET")

	http.Handle("/", r)

	log.Fatal(http.ListenAndServe(":8080", nil))
}
Beispiel #5
0
func main() {
	conf.Parse()

	restrict.ReadCryptoKey("keys/app.rsa")

	router := mux.NewRouter()
	router.HandleFunc("/users", GetUserHandler).Methods("GET")
	router.HandleFunc("/users/login", LoginHandler).Methods("POST")
	router.HandleFunc("/users/register", RegisterHandler).Methods("POST")
	router.HandleFunc("/classes", restrict.R(CreateClassHandler)).Methods("POST")
	router.HandleFunc("/classes", restrict.R(GetClassesHandler)).Methods("GET")
	router.HandleFunc("/classes/{class_id}/workshops", restrict.R(CreateWorkshopHandler)).Methods("POST")
	router.HandleFunc("/classes/{class_id}/workshops/{workshop_id}/pages", restrict.R(CreateWorkshopPageHandler)).Methods("POST")
	router.HandleFunc("/classes/{class_id}/workshops/{workshop_id}/pages", restrict.R(GetWorkshopPagesHandler)).Methods("GET")
	router.HandleFunc("/classes/{class_id}/workshops/{workshop_id}/pages/{page_id}/edit", restrict.R(EditPageHandler)).Methods("POST")
	router.HandleFunc("/classes/{class_id}/workshops/{workshop_id}", restrict.R(GetWorkshopHandler)).Methods("GET")
	router.HandleFunc("/classes/{class_id}/workshops/{workshop_id}", restrict.R(EditWorkshopHandler)).Methods("PUT")
	router.HandleFunc("/classes/{class_id}/workshops/{workshop_id}", restrict.R(DeleteWorkshopHandler)).Methods("DELETE")
	router.HandleFunc("/classes/{class_id}/workshops", restrict.R(GetWorkshopsHandler)).Methods("GET")
	router.HandleFunc("/classes/{class_id}/students", restrict.R(GetStudentHandler)).Methods("GET")
	router.HandleFunc("/classes/{class_id}/image", restrict.R(SetClassImageHandler)).Methods("POST")
	router.HandleFunc("/classes/{class_id}/admin/students", restrict.R(AddUserToClassHandler)).Methods("POST")

	n := negroni.New()
	n.Use(negroni.NewStatic(http.Dir("static")))
	n.Use(negroni.NewLogger())
	n.UseHandler(router)

	models.InitDB(*dbFile)

	http.ListenAndServe("localhost:8080", n)
}