Exemplo n.º 1
0
func RegisterDropbox(req *http.Request, render render.Render, registerDropboxForm RegisterDropboxForm, account *models.Account, logger *middlewares.Logger, ds *appx.Datastore) {
	logger.Infof("You are in register dropbox")

	authorization := &models.ExternalServiceAuthorization{
		AuthorizationType: models.DropBox,
		AccessToken:       registerDropboxForm.AccessToken,
		UserId:            models.DropBox.String() + "-" + registerDropboxForm.UserId,
	}

	authorization.SetParentKey(account.Key())

	err := ds.Load(authorization)
	if err != nil {
		println("I failed you becasue: %v", err.Error())
	}
	exists := err == nil

	if err := ds.Save(authorization); err != nil {
		logger.Errorf("Unable to register for dropbox %v", err)
		render.JSON(http.StatusInternalServerError, "Unable to register dropbox")
		return
	}

	if exists {
		DropboxDelta(req, ds, account, authorization)
	} else {
		DropboxInit(req, ds, account, authorization)
	}

	render.Status(http.StatusOK)
}
func ExternalServiceAuthorizationProvider(ds *appx.Datastore, martiniContext martini.Context, account *models.Account) {
	authorization := &models.ExternalServiceAuthorization{}
	authorization.SetParentKey(account.Key())

	if err := ds.Load(authorization); err != nil {
		panic(err)
	}

	martiniContext.Map(authorization)
}
Exemplo n.º 3
0
func UpdateAccount(render render.Render, accountUpdateForm AccountUpdateForm, account *models.Account, db *appx.Datastore) {
	account.FirstName = accountUpdateForm.FirstName
	account.LastName = accountUpdateForm.LastName
	account.Email = accountUpdateForm.Email

	if err := db.Save(account); err != nil {
		render.JSON(http.StatusInternalServerError, "Unable to register dropbox")
	}

	render.Status(http.StatusOK)
}