// Registers a new user account based on the given verified email address. // Username will be the same as the verified email address. Password will be random. // The user will have access to no channels. func (auth *Authenticator) RegisterNewUser(username, email string) (User, error) { user, err := auth.NewUser(username, base.GenerateRandomSecret(), base.Set{}) if err != nil { return nil, err } user.SetEmail(email) err = auth.Save(user) if err != nil { return nil, err } return user, err }
func (auth *Authenticator) CreateSession(username string, ttl time.Duration) (*LoginSession, error) { ttlSec := int(ttl.Seconds()) if ttlSec <= 0 { return nil, base.HTTPErrorf(400, "Invalid session time-to-live") } session := &LoginSession{ ID: base.GenerateRandomSecret(), Username: username, Expiration: time.Now().Add(ttl), Ttl: ttl, } if err := auth.bucket.Set(docIDForSession(session.ID), ttlSec, session); err != nil { return nil, err } return session, nil }