Exemplo n.º 1
0
func dairy(writer http.ResponseWriter, req *http.Request) {
	vars := mux.Vars(req)
	date := vars["date"]
	from := input.Get(req, "from", RE_FROM, service.FROM_GLOBAL)

	dairies := service.Dairy.Dairies(date, from)

	output.Puts(writer, "dairys", dairies)
	output.Puts(writer, "code", CODE_OK)
}
Exemplo n.º 2
0
func signUp(writer http.ResponseWriter, req *http.Request) {
	name, password := nameAndPassword(req)
	if service.User.Exist(name) {
		output.Puts(writer, "code", CODE_EXIST)
		return
	}
	code := CODE_FAIL
	if service.User.Create(name, password) {
		code = CODE_OK
	}
	service.User.SignIn(writer, name, password)
	output.Puts(writer, "code", code)
}
Exemplo n.º 3
0
func signIn(writer http.ResponseWriter, req *http.Request) {
	name, password := nameAndPassword(req)
	code := CODE_FAIL
	if service.User.CanSignIn(name, password) {
		code = CODE_OK
	}
	service.User.SignIn(writer, name, password)
	output.Puts(writer, "code", code)
}
Exemplo n.º 4
0
func Before2Sign(writer http.ResponseWriter, req *http.Request) (e error) {
	if ok, name := User.IsSignIn(req); ok {
		cookie := &http.Cookie{
			Name:  "name",
			Value: name,
			Path:  "/",
		}
		req.AddCookie(cookie)
		return
	}
	output.Puts(writer, "code", CODE_SIGN_IN_REQUIRED)
	return err.AccessError{Status: http.StatusBadRequest, Msg: "required sign in"}
}
Exemplo n.º 5
0
func signOut(writer http.ResponseWriter, req *http.Request) {
	service.User.SignOut(writer, req)
	output.Puts(writer, "code", CODE_OK)
}