Exemplo n.º 1
0
func getCookie(w *webby.Web) *http.Cookie {
	cookie, err := w.GetCookie(cookieName)
	if err != nil {
		cookie = w.NewCookie(cookieName).Value(genKey()).Expires(time.Now().AddDate(0, 1, 0)).SaveRes().SaveReq().Get()
	}
	return cookie
}
Exemplo n.º 2
0
func getCookie(w *webby.Web) *http.Cookie {
	cookie, err := w.Cookie(cookieName).Get()
	if err != nil {
		cookie, _ = w.Cookie(cookieName).Value(webby.KeyGen()).Month().SaveRes().SaveReq().Get()
	}
	return cookie
}
Exemplo n.º 3
0
// For the more complexed form!
func (f *Form) IsValidSlot(w *webby.Web, slot int) bool {
	var files FileHeaders
	form := w.Form().Slot(slot)
	values := Values(form.Value)
	files = nil
	if form.File != nil {
		files = FileHeaders(form.File)
	}
	return f.isValid(w, values, files)
}
Exemplo n.º 4
0
func (ro RouteHandler) View(w *webby.Web) {
	truth := ro.Init(w)

	if w.CutOut() {
		return
	}

	if !truth {
		w.Error403()
		return
	}

	var form *Form

	switch t := w.Session.(type) {
	case Form:
		form = &t
		w.DestroySession()
	case *Form:
		form = t
		w.DestroySession()
	default:
		form = ro.FetchForm(w)
	}

	if w.Req.Method == "POST" {
		goto post
	}

	if w.Req.URL.RawQuery != "" {
		if form.IsValid(w) {
			goto pass
		} else {
			goto get
		}
	}

get:
	ro.Get(w, form)
	return

post:
	if !form.IsValid(w) {
		goto fail
	}

pass:
	ro.PostPass(w)
	return

fail:
	w.SetSession(form)
	ro.PostFail(w)
}
Exemplo n.º 5
0
func (f *Form) IsValid(w *webby.Web) bool {
	var values Values
	var files FileHeaders
	w.ParseForm()

	if w.Req.MultipartForm != nil {
		values = Values(w.Req.MultipartForm.Value)
		files = FileHeaders(w.Req.MultipartForm.File)
	} else {
		values = Values(w.Req.Form)
		files = nil
	}

	return f.isValid(w, values, files)
}
Exemplo n.º 6
0
func (_ Check) Boot(w *webby.Web) {
	if IncludeGetRequest {
		goto parse_form
	}

	if w.Req.Method == "GET" {
		return
	}

parse_form:

	w.ParseForm()

	if w.Req.MultipartForm != nil {
		multipartCheck(w)
		return
	}

	formCheck(w)
}
Exemplo n.º 7
0
Arquivo: put.go Projeto: jlertle/webby
func (p Put) Validate(w *webby.Web) {
	var data struct {
		Pass bool   `json:"pass"`
		Url  string `json:"url"`
		Html string `json:"html"`
	}
	data.Pass = true
	data.Url = p.url

	if !p.form.IsValid(w) {
		data.Pass = false
		data.Html = p.form.Render()
		if p.failFunc != nil {
			p.failFunc(w)
		}
	} else {
		if p.passFunc != nil {
			p.passFunc(w)
		}
	}

	w.Json().Send(data)
}
Exemplo n.º 8
0
func formCheck(w *webby.Web) {
	form := w.Form()
	if len(form.Value) <= 0 {
		return
	}

	if len(form.Value[cookieName]) <= 0 {
		w.Error403()
		return
	}

	if form.Value[cookieName][0] != getCookie(w).Value {
		w.Error403()
		return
	}
}
Exemplo n.º 9
0
func fail(w *webby.Web) {
	w.Error403()
}
Exemplo n.º 10
0
func (rss RssRouteHandler) View(w *webby.Web) {
	w.InitCompression()
	w.Print(rss.Feed(w).RSS())
}
Exemplo n.º 11
0
func (at AtomRouteHandler) View(w *webby.Web) {
	w.InitCompression()
	w.Print(at.Feed(w).Atom())
}
Exemplo n.º 12
0
func LoggerStd(w *webby.Web) string {
	return fmt.Sprintf("%s %s %s %s ?%s IP:%s %v", w.Req.Proto, w.Req.Method,
		w.Req.Host, w.Req.URL.Path,
		w.Req.URL.RawQuery, w.RemoteAddr(), time.Now())
}