Beispiel #1
0
func RouteReminders(m *martini.ClassicMartini, model models.Api) {
	m.Get("/api/reminders", model.Authenticated, model.GetAllReminders)
	m.Get("/reminders/:id", model.GetReminder)
	m.Post("/reminders", model.PostReminder)
	m.Put("/reminders/:id", model.PutReminder)
	m.Delete("/reminders/:id", model.DeleteReminder)
}
Beispiel #2
0
func AdministationHandlers(m *martini.ClassicMartini) {
	log.Println("Initializing Administration pages.")

	m.Get("/admin", adminIndexHandler)

	// accounts.
	m.Post("/api/admin/account", binding.Bind(UserModel{}), adminNewAccount)
}
func setupTemplate(m *martini.ClassicMartini, t Template) {
	handler := func(r render.Render, req *http.Request, s ServerList) {
		handleTemplate(r, req, t, s)
	}
	for _, name := range t.Handlers {
		m.Get("/"+name, handler)
	}
}
Beispiel #4
0
/**
* Martini application configuration.
 */
func configuration(app *martini.ClassicMartini) {
	app.Use(martini.Static("public"))
	app.Use(render.Renderer(render.Options{
		Directory:  "templets",
		Layout:     "layout",
		Extensions: []string{".tmpl", ".html"},
		Charset:    "UTF-8",
		IndentJSON: true,
	}))
}
Beispiel #5
0
func Signup(m *martini.ClassicMartini) {
	m.Get("/signup", func(r render.Render) {
		r.HTML(200, "signup", nil)
	})

	m.Post("/signup", binding.Bind(UserPost{}), func(userpost UserPost) string {
		// This function won't execute if there were errors
		if InsertUser(userpost) {
			//http.Redirect(w, r, "/profile", http.StatusFound)
			//return userpost.UName
			s := "<html>"
			s += userpost.UName
			s += `,恭喜你注册成功,请 <a href="/signin">登录</a></html>`
			return s
			//return `"<html>恭喜你", userpost.UName, "通过验证,请 <a href="/signin">登录</a></html>"`
		} else {
			return "insert DB failed"
		}
	})
}
Beispiel #6
0
func Signin(m *martini.ClassicMartini) {
	m.Get("/signin", func(r render.Render) {
		r.HTML(200, "signin", nil)
	})
	m.Post("/signin", func(session sessions.Session) {
		fmt.Println("session set..")
		session.Set("hello", "world")
		//	return "OK"
	})
	m.Post("/signin", binding.Bind(UserSignin{}), func(usersingin UserSignin) string {
		// This function won't execute if there were errors
		if userpost, err := QueryUser(usersingin); err != false {
			//http.Redirect(w, r, "/profile", http.StatusFound)
			//return userpost.UName
			s := "<html>"
			s += userpost.UName
			s += `,恭喜你通过验证,请 <a href="/">回首页</a></html>`

			//sessions.Session.Set(userpost.UEmail, userpost.UName)
			//sessions.Session.("hello", "world")
			fmt.Println(s)
			//martini.Context.Next()
			return s
		} else {
			return "query DB failed"
		}
	})

}
Beispiel #7
0
func AccountHandlers(m *martini.ClassicMartini) {

	m.Use(BearerTokenValidation)
	m.Get("/account", func(r render.Render) {
		r.HTML(200, "account/login", nil)
	})
	// Authenticate user
	m.Post("/account", binding.Bind(LoginUserModel{}), func(user LoginUserModel, r *http.Request, render render.Render) {

		log.Println("user", user.Username)
		log.Println("pass", user.Password)

		if user.Username == ValidUser && user.Password == ValidPass {

			// Create JWT token
			token := jwt.New(jwt.GetSigningMethod("HS256"))
			token.Claims["username"] = user.Username
			// Expire in 5 mins
			token.Claims["exp"] = time.Now().Add(time.Minute * 5).Unix()
			tokenString, err := token.SignedString([]byte(SecretKey))

			if err == nil {
				data := map[string]string{"token": tokenString}
				render.JSON(201, data)
				return
			}

			r.Header.Add("Authorization", tokenString)

		}

		render.Redirect("/")
	})
}
Beispiel #8
0
func RegisterWebService(webservice WebService, classicMartini *martini.ClassicMartini) {
	classicMartini.Get("/:id", func(params martini.Params, req *http.Request) string {
		fmt.Println(params)
		fmt.Println(req.Header.Get("Content-Disposition"))
		fmt.Println(req.URL.RawQuery)
		return "Hello"
	})
	classicMartini.Post("/**", webservice.InitiateMultipartUpload)
	classicMartini.Put("/**", webservice.UploadPart)
}
Beispiel #9
0
func (ctrl FoodController) Register(m *martini.ClassicMartini) {
	m.Get("/food", ctrl.Get)
	m.Get("/food/:name", ctrl.GetOne)
	m.Post("/food", ctrl.Create)
}
Beispiel #10
0
func RouteAuth(m *martini.ClassicMartini, model models.Api) {
	m.Get("/api/login", model.Login)
	m.Get("/api/logout", model.Logout)
	m.Get("/api/isauthenticated", model.Authenticated, model.IsAuthenticated)
}
Beispiel #11
0
func Route(m *martini.ClassicMartini) {
	m.Use(render.Renderer())

	m.Get("/", func(r render.Render) {
		r.HTML(200, "index", nil)
	})

	//post handlers
	Signup(m)
	Signin(m)

	m.Get("/inspect", func() string {
		return "Hello inspect!"
	})
	m.Get("/add", func() string {
		return "Hello add!"
	})

	m.Post("/inspect", func() string {
		return "Hello inspect!"
	})
	m.Post("/add", func() string {
		return "Hello add!"
	})
}
// RegisterWebService adds martini routes to the relevant webservice methods
// based on the path returned by GetPath. Each method is registered once for
// the collection and once for each id in the collection.
func RegisterWebService(webService WebService,
	classicMartini *martini.ClassicMartini) {
	path := webService.GetPath()

	classicMartini.Get(path, webService.WebGet)
	classicMartini.Get(path+"/:id", webService.WebGet)

	classicMartini.Post(path, webService.WebPost)
	classicMartini.Post(path+"/:id", webService.WebPost)

	classicMartini.Delete(path, webService.WebDelete)
	classicMartini.Delete(path+"/:id", webService.WebDelete)
}