Exemplo n.º 1
0
func (p *GeneratePrivateKeyRequestHandler) ContentTypesProvided(req wm.Request, cxt wm.Context) ([]wm.MediaTypeHandler, wm.Request, wm.Context, int, error) {
	gpkc := cxt.(GeneratePrivateKeyContext)
	user := gpkc.User()
	consumer := gpkc.Consumer()
	var userId, consumerId string
	if user != nil {
		userId = user.Id
	}
	if consumer != nil {
		consumerId = consumer.Id
	}
	accessKey, err := p.authDS.StoreAccessKey(dm.NewAccessKey(userId, consumerId))
	gpkc.SetAccessKey(accessKey)
	obj := make(map[string]interface{})
	if user != nil {
		obj["user_id"] = user.Id
		obj["username"] = user.Username
		obj["name"] = user.Name
	}
	if consumer != nil {
		obj["consumer_id"] = consumer.Id
		obj["consumer_short_name"] = consumer.ShortName
	}
	if accessKey != nil {
		obj["access_key_id"] = accessKey.Id
		obj["private_key"] = accessKey.PrivateKey
	}
	theobj, _ := jsonhelper.MarshalWithOptions(obj, dm.UTC_DATETIME_FORMAT)
	jsonObj, _ := theobj.(jsonhelper.JSONObject)
	if err != nil {
		return []wm.MediaTypeHandler{apiutil.NewJSONMediaTypeHandler(jsonObj, time.Time{}, "")}, req, gpkc, http.StatusInternalServerError, err
	}
	return []wm.MediaTypeHandler{apiutil.NewJSONMediaTypeHandler(jsonObj, time.Time{}, "")}, req, gpkc, 0, nil
}
Exemplo n.º 2
0
func (p *LogoutAccountRequestHandler) ContentTypesProvided(req wm.Request, cxt wm.Context) ([]wm.MediaTypeHandler, wm.Request, wm.Context, int, error) {
	lac := cxt.(LogoutAccountContext)
	var err error
	if lac.AccessKey() != nil {
		_, err = p.authDS.DeleteAccessKey(lac.AccessKey().Id)
	}
	if err != nil {
		return []wm.MediaTypeHandler{apiutil.NewJSONMediaTypeHandler(nil, time.Time{}, "")}, req, lac, http.StatusInternalServerError, err
	}
	return []wm.MediaTypeHandler{apiutil.NewJSONMediaTypeHandler(nil, time.Time{}, "")}, req, lac, 0, nil
}
Exemplo n.º 3
0
func (p *ViewAccountRequestHandler) ContentTypesProvided(req wm.Request, cxt wm.Context) ([]wm.MediaTypeHandler, wm.Request, wm.Context, int, error) {
	vac := cxt.(ViewAccountContext)
	obj := vac.ToObject()
	lastModified := vac.LastModified()
	etag := vac.ETag()
	var jsonObj jsonhelper.JSONObject
	if obj != nil {
		theobj, _ := jsonhelper.MarshalWithOptions(obj, dm.UTC_DATETIME_FORMAT)
		jsonObj, _ = theobj.(jsonhelper.JSONObject)
	}
	return []wm.MediaTypeHandler{apiutil.NewJSONMediaTypeHandler(jsonObj, lastModified, etag)}, req, vac, 0, nil
}