コード例 #1
0
ファイル: create.go プロジェクト: twitchyliquid64/CNC
//Called when a user logged in to create a new session
//pass the UserID (PK in the DB) and a string describing what
//they are logging in to (ie: web, IRC etc)
func CreateSession(userID int, component string, db gorm.DB) string {
	s := Session{
		Key:       util.RandAlphaKey(DEFAULT_KEY_SIZE),
		UserID:    userID,
		Component: component,
		Expires:   time.Now().Add(DEFAULT_EXPIRY),
		Revoked:   false,
	}
	db.Create(&s)
	return s.Key
}
コード例 #2
0
ファイル: factories.go プロジェクト: twitchyliquid64/CNC
func NewEntity(ent *Entity, usrID uint, db gorm.DB) (*Entity, error) {
	ent.CreatorUserID = int(usrID)
	ent.APIKey = util.RandAlphaKey(DEFAULT_APIKEY_SIZE)
	ent.LastStatString = ""
	return ent, db.Save(ent).Error
}