Exemplo n.º 1
0
// ConvertUser converts a complete Identity object into REST representation
func ConvertUser(request *goa.RequestData, identity *account.Identity, user *account.User) *app.Identity {
	uuid := identity.ID
	id := uuid.String()
	fullName := identity.Username
	userName := identity.Username
	provider := identity.Provider
	var imageURL string
	var bio string
	var userURL string
	var email string
	if user != nil {
		fullName = user.FullName
		imageURL = user.ImageURL
		bio = user.Bio
		userURL = user.URL
		email = user.Email
	}
	converted := app.Identity{
		Data: &app.IdentityData{
			ID:   &id,
			Type: "identities",
			Attributes: &app.IdentityDataAttributes{
				Username: &userName,
				FullName: &fullName,
				ImageURL: &imageURL,
				Bio:      &bio,
				URL:      &userURL,
				Provider: &provider,
				Email:    &email,
			},
			Links: createUserLinks(request, uuid),
		},
	}
	return &converted
}
Exemplo n.º 2
0
// ContextIdentity returns the identity's ID found in given context
// Uses tokenManager.Locate to fetch the identity of currently logged in user
func ContextIdentity(ctx context.Context) (string, error) {
	tm := ReadTokenManagerFromContext(ctx)
	if tm == nil {
		log.Error(ctx, map[string]interface{}{
			"token": tm,
		}, "missing token manager")

		return "", errs.New("Missing token manager")
	}
	uuid, err := tm.Locate(ctx)
	if err != nil {
		// TODO : need a way to define user as Guest
		log.Error(ctx, map[string]interface{}{
			"uuid": uuid,
			"tm":   tm,
			"err":  err,
		}, "identity belongs to a Guest User")

		return "", errs.WithStack(err)
	}
	return uuid.String(), nil
}