示例#1
0
// martini router
func route(m *martini.ClassicMartini) {
	// find a device by key
	m.Get("/application/v1/device/info", GetDeviceInfoByKey)

	// find a device by identifier
	m.Get("/application/v1/devices/:identifier/info", ApplicationAuthOnDeviceIdentifer, GetDeviceInfoByIdentifier)

	// get devie current status
	m.Get("/application/v1/devices/:identifier/status/current",
		ApplicationAuthOnDeviceIdentifer, CheckDeviceOnline, CheckProductConfig,
		GetDeviceCurrentStatus)

	// get devie latest status
	m.Get("/application/v1/devices/:identifier/status/latest",
		ApplicationAuthOnDeviceIdentifer, CheckDeviceOnline, CheckProductConfig,
		GetDeviceLatestStatus)

	// set device status
	m.Put("/application/v1/devices/:identifier/status",
		ApplicationAuthOnDeviceIdentifer, CheckDeviceOnline, CheckProductConfig,
		SetDeviceStatus)

	// send a command to device
	m.Post("/application/v1/devices/:identifier/commands",
		ApplicationAuthOnDeviceIdentifer, CheckDeviceOnline, CheckProductConfig,
		SendCommandToDevice)

}
示例#2
0
文件: user.go 项目: xrstf/raziel
func setupUsersCtrl(app *martini.ClassicMartini) {
	app.Group("/users", func(r martini.Router) {
		app.Get("", usersIndexAction)
		app.Get("/add", usersAddAction)
		app.Post("", sessions.RequireCsrfToken, usersCreateAction)
		app.Get("/:id", usersEditAction)
		app.Put("/:id", sessions.RequireCsrfToken, usersUpdateAction)
		app.Delete("/:id", sessions.RequireCsrfToken, usersDeleteAction)
		app.Get("/:id/delete", usersDeleteConfirmAction)
	}, sessions.RequireLogin)
}
示例#3
0
文件: api.go 项目: aramalipoor/farmer
func registerRoutes(server *martini.ClassicMartini) {
	// Box
	server.Post("/boxes", binding.Bind(request.CreateRequest{}), boxCreate)
	server.Put("/boxes/:name", binding.Bind(request.DeployRequest{}), boxDeploy)
	server.Get("/boxes", boxList)
	server.Get("/boxes/:name", boxInspect)
	server.Delete("/boxes/:name", boxDelete)

	// Domain
	server.Post("/boxes/:name/domain", binding.Bind(request.Domain{}), domainAdd)
	server.Delete("/boxes/:name/domain/:domain", domainDelete)
}
示例#4
0
func addLatestNewsRoutes(m *martini.ClassicMartini) {
	m.Get("/latest_news", ShowLatestNewsCollection)

	m.Get("/latest_news/:id", EditLatestNews)

	m.Post("/latest_news", CreateLatestNews)
	m.Post("/latest_news/new", CreateLatestNews)

	m.Put("/latest_news/:id", UpdateLatestNews)
	m.Post("/latest_news/:id", UpdateLatestNews)

	m.Delete("/latest_news/:id", DeleteLatestNews)
	m.Get("/latest_news/del/:id", DeleteLatestNews)
}
示例#5
0
func addComponentRoutes(m *martini.ClassicMartini) {
	m.Get("/component", ShowComponents)

	m.Get("/component/:id", EditComponent)

	m.Post("/component", CreateComponent)
	m.Post("/component/new", CreateComponent)

	m.Put("/component/:id", UpdateComponent)
	m.Post("/component/:id", UpdateComponent)

	m.Delete("/component/:id", DeleteComponent)
	m.Get("/component/del/:id", DeleteComponent)
}
示例#6
0
func addInvertebrateRoutes(m *martini.ClassicMartini) {
	m.Get("/invertebrate", ShowInvertebrates)

	m.Get("/invertebrate/:id", EditInvertebrate)

	m.Post("/invertebrate", CreateInvertebrate)
	m.Post("/invertebrate/new", CreateInvertebrate)

	m.Put("/invertebrate/:id", UpdateInvertebrate)
	m.Post("/invertebrate/:id", UpdateInvertebrate)

	m.Delete("/invertebrate/:id", DeleteInvertebrate)
	m.Get("/invertebrate/del/:id", DeleteInvertebrate)
}
示例#7
0
func addCoralRoutes(m *martini.ClassicMartini) {
	m.Get("/coral", ShowCorals)

	m.Get("/coral/:id", EditCoral)

	m.Post("/coral", CreateCoral)
	m.Post("/coral/new", CreateCoral)

	m.Put("/coral/:id", UpdateCoral)
	m.Post("/coral/:id", UpdateCoral)

	m.Delete("/coral/:id", DeleteCoral)
	m.Get("/coral/del/:id", DeleteCoral)
}
示例#8
0
func addPlantRoutes(m *martini.ClassicMartini) {
	m.Get("/plant", ShowPlants)

	m.Get("/plant/:id", EditPlant)

	m.Post("/plant", CreatePlant)
	m.Post("/plant/new", CreatePlant)

	m.Put("/plant/:id", UpdatePlant)
	m.Post("/plant/:id", UpdatePlant)

	m.Delete("/plant/:id", DeletePlant)
	m.Get("/plant/del/:id", DeletePlant)
}
示例#9
0
func addInhabitantRoutes(m *martini.ClassicMartini) {
	m.Get("/inhabitant", ShowInhabitants)

	m.Get("/inhabitant/:id", EditInhabitant)

	m.Post("/inhabitant", CreateInhabitant)
	m.Post("/inhabitant/new", CreateInhabitant)

	m.Put("/inhabitant/:id", UpdateInhabitant)
	m.Post("/inhabitant/:id", UpdateInhabitant)

	m.Delete("/inhabitant/:id", DeleteInhabitant)
	m.Get("/inhabitant/del/:id", DeleteInhabitant)
}
示例#10
0
文件: consumer.go 项目: xrstf/raziel
func setupConsumersCtrl(app *martini.ClassicMartini) {
	app.Group("/consumers", func(r martini.Router) {
		app.Get("", consumersIndexAction)
		app.Get("/add", consumersAddAction)
		app.Post("", sessions.RequireCsrfToken, consumersCreateAction)
		app.Get("/:id", consumersEditAction)
		app.Put("/:id", sessions.RequireCsrfToken, consumersUpdateAction)
		app.Delete("/:id", sessions.RequireCsrfToken, consumersDeleteAction)
		app.Get("/:id/delete", consumersDeleteConfirmAction)
		app.Get("/:id/urls", consumersUrlsAction)
	}, sessions.RequireLogin)

	// public
	app.Get("/info/:consumer/:token", consumerInfoAction)
}
示例#11
0
// martini router
func route(m *martini.ClassicMartini) {
	// find a device by key
	m.Get("/application/v1/device/info", GetDeviceInfoByKey)

	// find a device by identifier
	m.Get("/application/v1/devices/:identifier/info", GetDeviceInfoByIdentifier)

	// get devie current status
	m.Get("/application/v1/devices/:identifier/status/current", GetDeviceCurrentStatus)

	// get devie latest status
	m.Get("/application/v1/devices/:identifier/status/latest", GetDeviceLatestStatus)

	// set devie status
	m.Put("/application/v1/devices/:identifier/status", SetDeviceStatus)

}
示例#12
0
func SetupAuth(martini *martini.ClassicMartini) {
	os.Mkdir(backendfile, 0755)
	backend_, err := httpauth.NewLeveldbAuthBackend(backendfile)
	if err != nil {
		log.Fatal(err.Error())
	}
	backend = backend_

	roles = make(map[string]httpauth.Role)
	roles["user"] = 30
	roles["admin"] = 80

	aaa, err = httpauth.NewAuthorizer(backend, []byte("cookie-encryption-key"), "user", roles)
	if err != nil {
		log.Fatal(err.Error())
	}

	users, err := backend.Users()
	if err != nil || len(users) == 0 {
		// create a default user
		hash, err := bcrypt.GenerateFromPassword([]byte("toor"), bcrypt.DefaultCost)
		//hash, err := bcrypt.GenerateFromPassword([]byte("l4ngu4g3"), bcrypt.DefaultCost)
		if err != nil {
			panic(err)
		}
		defaultUser := httpauth.UserData{Username: "******", Email: "", Hash: hash, Role: "admin"}
		//defaultUser := httpauth.UserData{Username: "******", Email: "", Hash: hash, Role: "admin"}
		err = backend.SaveUser(defaultUser)
		if err != nil {
			panic(err)
		}
	}

	martini.Post("/auth/login", doLogin)
	martini.Get("/auth/logout", doLogout)
	martini.Get("/auth/token", doGetToken)

	martini.Post("/auth/user", AssertRole("admin"), doAddUser)

	martini.Get("/auth/currentuser", doGetCurrentUser)
	martini.Get("/auth/user", AssertRole("admin"), doGetUsers)
	martini.Get("/auth/user/:username", AssertRole("admin"), doGetUser)

	martini.Put("/auth/user/:username", AssertRole("admin"), doUpdateUser)
	martini.Delete("/auth/user/:username", AssertRole("admin"), doDeleteUser)
	martini.Post("/auth/user/:username/allow", AssertRole("admin"), doAllow)
	martini.Post("/auth/user/:username/forbid", AssertRole("admin"), doForbid)

}
示例#13
0
/**
 * attach all api endpoints
 */
func SetupApiEndpoints(m *martini.ClassicMartini) {
	m.Get("/api/:project", GetProject)
	m.Put("/api/:project", PutProject)
	m.Delete("/api/:project", DeleteProject)
	m.Get("/api/:project/translation/:key", GetTranslation)
	m.Put("/api/:project/translation/:key/:locale", PutLocale)
	m.Delete("/api/:project/translation/:key/:locale", DeleteLocale)
	m.Get("/api/:project/file/:locale", GetLanguageFile)
	m.Put("/api/:project/file/:locale", PutLanguageFile)
}
示例#14
0
文件: profile.go 项目: xrstf/raziel
func setupProfileCtrl(app *martini.ClassicMartini) {
	app.Get("/profile", sessions.RequireLogin, profileAction)
	app.Put("/profile", sessions.RequireLogin, sessions.RequireCsrfToken, updateProfileAction)
	app.Put("/profile/password", sessions.RequireLogin, sessions.RequireCsrfToken, changePasswordAction)
}