Ejemplo n.º 1
0
func GET_profile(rw http.ResponseWriter, r *http.Request, identity *data.Identity,
	render render.Render, db *sqlx.DB) {
	var (
		tx      = db.MustBegin()
		success bool
		page    struct {
			Accounts          []*data.Account
			OwnedApplications []*data.Application
		}
	)

	defer func() {
		if success {
			tx.Commit()
		} else {
			tx.Rollback()
		}
	}()

	accounts, err := data.GetAccountsWithIdentityId(tx, identity.Id)
	if err != nil {
		panic(err)
	}

	owned_applications, err := data.GetApplicationsOwnedByIdentity(tx, identity.Id)
	if err != nil {
		panic(err)
	}

	page.Accounts = accounts
	page.OwnedApplications = owned_applications
	render.HTML(200, "profile", &page)
}
Ejemplo n.º 2
0
func GET_me(identity *data.Identity, render render.Render, db *sqlx.DB) {
	type account struct {
		Id      string `json:"id"`
		Name    string `json:"name"`
		Email   string `json:"email,omitempty"`
		Picture string `json:"picture,omitempty"`
	}

	var (
		tx      = db.MustBegin()
		success bool
		err     error
		resp    struct {
			Id       string     `json:"id"`
			Accounts []*account `json:"accounts"`
		}
	)

	defer func() {
		if success {
			tx.Commit()
		} else {
			tx.Rollback()
		}
	}()

	resp.Id = strconv.FormatInt(identity.Id, 10)

	accounts, err := data.GetAccountsWithIdentityId(tx, identity.Id)
	if err != nil {
		panic(err)
	}

	for _, acc := range accounts {
		resp.Accounts = append(resp.Accounts, &account{
			Id:      acc.RemoteId,
			Name:    acc.Name,
			Email:   acc.Email,
			Picture: acc.Picture,
		})
	}

	success = true
	render.JSON(200, &resp)
}