You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
760 B
33 lines
760 B
package rest
|
|
|
|
import (
|
|
"net/http"
|
|
"time"
|
|
|
|
"github.com/eyebluecn/tank/code/core"
|
|
"github.com/eyebluecn/tank/code/tool/util"
|
|
)
|
|
|
|
func handleSessionAndCookie(writer http.ResponseWriter, request *http.Request, seDao *SessionDao, user *User) {
|
|
//set cookie. expire after 30 days.
|
|
expiration := time.Now()
|
|
expiration = expiration.AddDate(0, 0, 30)
|
|
|
|
//save session to db.
|
|
session := &Session{
|
|
UserUuid: user.Uuid,
|
|
Ip: util.GetIpAddress(request),
|
|
ExpireTime: expiration,
|
|
}
|
|
session.UpdateTime = time.Now()
|
|
session.CreateTime = time.Now()
|
|
session = seDao.Create(session)
|
|
|
|
//set cookie
|
|
cookie := http.Cookie{
|
|
Name: core.COOKIE_AUTH_KEY,
|
|
Path: "/",
|
|
Value: session.Uuid,
|
|
Expires: expiration}
|
|
http.SetCookie(writer, &cookie)
|
|
}
|
|
|