Exemplo n.º 1
0
func (this *TimeFrame) parseThisNUnits(n int, units string) bool {
	n = n - 1
	switch units {
	case "minutes":
		this.Start = now.BeginningOfMinute().Add(time.Duration(-n) * time.Minute)
		this.End = now.EndOfMinute()
	case "hours":
		this.Start = now.BeginningOfHour().Add(time.Duration(-n) * time.Hour)
		this.End = now.EndOfHour()
	case "days":
		this.Start = now.BeginningOfDay().AddDate(0, 0, -n)
		this.End = now.EndOfDay()
	case "weeks":
		this.Start = now.BeginningOfWeek().AddDate(0, 0, -n*7)
		this.End = now.EndOfWeek()
	case "months":
		this.Start = now.BeginningOfMonth().AddDate(0, -n, 0)
		this.End = now.EndOfMonth()
	case "years":
		this.Start = now.BeginningOfYear().AddDate(-n, 0, 0)
		this.End = now.EndOfYear()
	default:
		return false
	}
	return true
}
Exemplo n.º 2
0
// Generate generates new jwt tokens, only claim is expire date which is after one
// year.
func (j *JWTTokenGen) Generate() string {
	exp := now.EndOfYear()
	token := jwt.New(jwt.SigningMethodRS256)
	token.Claims["exp"] = exp.Unix()
	tok, err := token.SignedString(j.privateKey)
	if err != nil {
		panic(err)
	}
	return tok
}
Exemplo n.º 3
0
Arquivo: jwt.go Projeto: jwulf/zedlist
import (
	"errors"

	"github.com/dgrijalva/jwt-go"
	"github.com/gernest/zedlist/models"
	"github.com/gernest/zedlist/modules/query"

	"github.com/jinzhu/now"
)

var (

	// TokenExpireDate is the expiry time for a generated token
	// defaults to at the end of the current year.
	TokenExpireDate = now.EndOfYear()
)

// RSAKeyHolder is an interface for public and private RSA keys.
type RSAKeyHolder interface {

	// GetPublicBytes returns rsa public key in []byte
	GetPublicBytes() []byte

	// GetPrivateBytes returns private rsa key in []byte
	GetPrivateBytes() []byte
}

// NewJWTAuth returns a JWTValidateFunc for the echo.s JWTAuth middleware.
func NewJWTAuth(keys RSAKeyHolder) func(string, jwt.SigningMethod) ([]byte, error) {
	return func(token string, method jwt.SigningMethod) ([]byte, error) {