Пример #1
0
//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
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
}