Example #1
0
func (app *App) Create(owner User, team Team) error {
	app.Owner = owner.Email
	app.Team = team.Alias

	if err := app.valid(); err != nil {
		Logger.Info("Failed to create an app with invalid data: %+v.", app)
		return err
	}

	if app.ClientId == "" {
		app.ClientId = goutils.GenerateSlug(app.Name)
	} else {
		app.ClientId = goutils.GenerateSlug(app.ClientId)
	}
	if app.ClientSecret == "" {
		app.ClientSecret = util.GenerateRandomStr(32)
	}

	if app.Exists() {
		Logger.Info("Failed to create an app with duplicate data: %+v.", app)
		return errors.NewValidationError(errors.ErrAppDuplicateEntry)
	}

	err := store.UpsertApp(*app)
	Logger.Info("app.Create: %+v. Err: %s.", app, err)
	return err
}
Example #2
0
func (a *auth) CreateUserToken(user *account.User) (*account.Token, error) {
	api := account.Token{
		CreatedAt:   time.Now().In(time.UTC).Format("2006-01-02T15:04:05Z07:00"),
		Expires:     EXPIRES_IN_SECONDS,
		Type:        TOKEN_TYPE,
		AccessToken: util.GenerateRandomStr(32),
		User:        user,
	}

	err := a.store.CreateToken(api)
	if err != nil {
		return nil, err
	}

	return &api, err
}