Example #1
0
func New(rw http.ResponseWriter, r *http.Request, authPanel bool, section ...string) *Controller {
	c := new(Controller)
	c.Request = r
	c.Response = rw
	c.AuthPanel = authPanel
	c.Router = mux.Router
	if len(section) > 0 {
		c.section = section[0]
	}
	c.Local = httphead.GetLang(r)
	return c
}
Example #2
0
func New() negroni.Handler {
	return negroni.HandlerFunc(func(rw http.ResponseWriter, r *http.Request, next http.HandlerFunc) {
		rd := &reader{request: r, response: rw, local: httphead.GetLang(r)}

		if cookie, err := rd.readCookie(); err == nil {
			rd.readToken(cookie)
		}

		// If authorization is passed
		next(rw, r)
	})
}
Example #3
0
// Validate, if the user is authorized to use the handler.
// Will use like middleware.
func AllowVisit(handler http.Handler) http.Handler {
	n := negroni.New(negroni.HandlerFunc(func(rw http.ResponseWriter, r *http.Request, next http.HandlerFunc) {

		signed := IsSignedInUser(r)

		if !signed {
			flash.Set(r, "E", i18n.Translate(httphead.GetLang(r), i18nSec, "text12"))
			http.Redirect(rw, r, "/user/signin", 303)
			return
		}
		// If authorization is passed
		next(rw, r)
	}))
	n.UseHandler(handler)
	return n
}
Example #4
0
// Validate if the entered numbers match to stored number
func Validate(r *http.Request, certification, human string) error {

	// Error object
	err := errors.New(i18n.Translate(httphead.GetLang(r), "controller/account", "text09"))

	if human == "" {
		return err
	}

	decoded, err := base64.StdEncoding.DecodeString(certification)
	if err != nil {
		return err
	}

	c := redis.Get()
	// Configure out, if the image still available.
	values, err := goredis.Bytes(c.Do("GET", string(decoded)))
	if err != nil {
		return err
	}

	ns := make([]byte, len(human))
	for i := range ns {
		d := human[i]
		switch {
		case '0' <= d && d <= '9':
			ns[i] = d - '0'
		case d == ' ' || d == ',':
			// ignore
		default:
			return err
		}
	}

	if !bytes.Equal(values, ns) {
		return err
	}

	return nil

}