//生成cookie,放到reponse对象
func generateCookie(w http.ResponseWriter, r *http.Request, userNmae string, number int) {
	timeLength := 24 * time.Hour
	cookieValue := authcookie.NewSinceNow(userNmae, timeLength, []byte(KEY))
	expire := time.Now().Add(timeLength)
	cookie := http.Cookie{Name: COOKIENAME, Value: cookieValue, Path: "/", Expires: expire, MaxAge: 86400}
	http.SetCookie(w, &cookie)
}
Example #2
0
// CreateStream will generate a token and create a new
// channel over which messages streams (ie build output)
// are sent.
func CreateStream(name string) string {
	mu.Lock()
	defer mu.Unlock()

	if _, ok := hubs[name]; !ok {
		hub := newHub(true, false)
		hubs[name] = hub
		go hub.run()
	}
	return authcookie.NewSinceNow(name, 24*time.Hour, secret)
}
Example #3
0
// NewToken returns a new password reset token for the given login, which
// expires after the given time duration since now, signed by the key generated
// from the given password value (which can be any value that will be changed
// once a user resets their password, such as password hash or salt used to
// generate it), and the given secret key.
func NewToken(login string, dur time.Duration, pwdval, secret []byte) string {
	sk := getUserSecretKey(pwdval, secret)
	return authcookie.NewSinceNow(login, dur, sk)
}
Example #4
0
// Token will generate a token, but will not create
// a new channel.
func Token(name string) string {
	return authcookie.NewSinceNow(name, 24*time.Hour, secret)
}
Example #5
0
func GenerateToken(id string) string {
	secret := generateSalt(40)
	return authcookie.NewSinceNow(id, 24*time.Hour, secret)
}