Beispiel #1
0
// HTTPRequest returns the *http.Request associated with ctx using NewContext,
// if any.
func HTTPRequest(ctx context.Context) (*http.Request, bool) {
	// We cannot use ctx.(*wrapper).req to get the request because ctx may
	// be a Context derived from a *wrapper. Instead, we use Value to
	// access the request if it is anywhere up the Context tree.
	req, ok := ctx.Value(reqKey).(*http.Request)
	return req, ok
}
func (handler *HomeWebserviceHandler) SetProfileImage(ctx context.Context, w http.ResponseWriter, r *http.Request) {
	user := ctx.Value(KeyUser).(*usecases.User)

	imgData, hndl, err := r.FormFile("File")
	if err != nil {
		handler.Webservice.Error(w, err)
		return
	}

	handler.Webservice.Log(fmt.Sprintf("Upload file %s", hndl.Filename))

	image, err := handler.ImageUtils.Load(imgData)
	if err != nil {
		handler.Webservice.Error(w, err)
		return
	}

	image = handler.ImageUtils.Resize(image, 192, 192)

	data, err := handler.ImageUtils.Save(image, ".png")

	err = handler.FileStore.Create(fmt.Sprintf("upload/profile_%d.png", user.Id), data)
	if err != nil {
		handler.Webservice.Error(w, err)
		return
	}

	if err != nil {
		handler.Webservice.Error(w, err)
		return
	}

	handler.Webservice.SendJson(w, setProfileImageResponse{Result: true})
}
Beispiel #3
0
// NewReader creates a new io.ReadCloser to read the contents
// of the object.
func NewReader(ctx context.Context, bucket, name string) (io.ReadCloser, error) {
	c := ctx.Value(internal.Key(0)).(map[string]interface{})["http_client"].(*http.Client)
	resp, err := c.Get(fmt.Sprintf(templURLMedia, bucket, name))
	if err != nil {
		return nil, err
	}
	if resp.StatusCode == http.StatusNotFound {
		return nil, ErrObjectNotExists
	}
	return resp.Body, nil
}
Beispiel #4
0
// RemoteAddr accesses the remote address of the rpcwrap call connection in this context.
func RemoteAddr(ctx context.Context) (addr string, ok bool) {
	val := ctx.Value(remoteAddrKey)
	if val == nil {
		return "", false
	}
	addr, ok = val.(string)
	if !ok {
		return "", false
	}
	return addr, true
}
Beispiel #5
0
// Username accesses the authenticated username of the rpcwrap call connection in this context.
func Username(ctx context.Context) (user string, ok bool) {
	val := ctx.Value(usernameKey)
	if val == nil {
		return "", false
	}
	user, ok = val.(string)
	if !ok {
		return "", false
	}
	return user, ok
}
Beispiel #6
0
// SetUsername sets the authenticated username associated with the rpcwrap call connection for this context.
// NOTE: For internal use by the rpcwrap library only. Contexts are supposed to be readonly, and
// this somewhat circumvents this intent.
func SetUsername(ctx context.Context, username string) (ok bool) {
	val := ctx.Value(usernameSlotKey)
	if val == nil {
		return false
	}
	slot, ok := val.(*string)
	if !ok {
		return false
	}
	*slot = username
	return true
}
func (handler *AuthentificationWebserviceHandler) Logout(ctx context.Context, w http.ResponseWriter, r *http.Request) {
	user := ctx.Value(KeyUser).(*usecases.User)

	if err := handler.ChatInteractor.Disconnect(user.Id); err != nil {
		handler.Webservice.Error(w, err)
		return
	}

	handler.Webservice.EndSession(ctx, w, r)

	reponse := &LogoutResponseModel{
		Result: true,
	}

	handler.Webservice.SendJson(w, reponse)
}
func (handler *HomeWebserviceHandler) GetProfileModel(ctx context.Context, w http.ResponseWriter, r *http.Request) {
	user := ctx.Value(KeyUser).(*usecases.User)
	client, err := handler.HomeInteractor.GetClient(user.Id)
	if err != nil {
		handler.Webservice.Error(w, err)
	}

	model := &profileModel{
		Username:     user.Username,
		DisplayName:  client.DisplayName,
		FirstName:    client.FirstName,
		LastName:     client.LastName,
		Email:        client.Email,
		ProfileImage: fmt.Sprintf("/getProfileImage?clientId=%d", client.Id),
	}
	response := ModelResponse{
		Model: model,
	}
	handler.Webservice.SendJson(w, response)
}
Beispiel #9
0
func rawService(ctx context.Context) *raw.Service {
	return ctx.Value(internal.Key(0)).(map[string]interface{})["pubsub_service"].(*raw.Service)
}
Beispiel #10
0
func projID(ctx context.Context) string {
	return ctx.Value(internal.Key(0)).(map[string]interface{})["project_id"].(string)
}
Beispiel #11
0
func FromContext(ctx context.Context) (RequestID, bool) {
	reqID, ok := ctx.Value(reqIDKey).(RequestID)
	return reqID, ok
}
Beispiel #12
0
func ContextualTwo(ctx context.Context, rw http.ResponseWriter, r *http.Request) {
	message := ctx.Value(key).(string)
	rw.Write([]byte(message))
}
Beispiel #13
0
// FromContext returns the pool assigned to the context.
func FromContext(c context.Context) *PubSub {
	return c.Value(reqkey).(*PubSub)
}
Beispiel #14
0
// FromContext returns the Blobstore associated with this context.
func FromContext(c context.Context) Blobstore {
	return c.Value(reqkey).(Blobstore)
}
Beispiel #15
0
// FromContext returns the pool assigned to the context.
func FromContext(c context.Context) *Pool {
	return c.Value(reqkey).(*Pool)
}
Beispiel #16
0
// FromContext returns the capability map for the
// current context.
func FromContext(c context.Context) Capability {
	return c.Value(reqkey).(Capability)
}
Beispiel #17
0
// ServiceNameFromContext extracts a servicename from passed context
func ServiceNameFromContext(ctx context.Context) (string, bool) {
	// ctx.Value returns nil if ctx has no value for the key;
	// the string type assertion returns ok=false for nil.
	serviceName, ok := ctx.Value(serviceNameKey).(string)
	return serviceName, ok
}
Beispiel #18
0
func FromContext(ctx context.Context) (*log.Entry, bool) {
	l, ok := ctx.Value(loggerKey).(*log.Entry)
	return l, ok
}
Beispiel #19
0
// FromContext returns the sql.DB associated with this context.
func FromContext(c context.Context) Datastore {
	return c.Value(reqkey).(Datastore)
}
Beispiel #20
0
// FromContext returns the worker queue associated with this context.
func FromContext(c context.Context) Worker {
	return c.Value(reqkey).(Worker)
}
Beispiel #21
0
// FromContext extracts the user IP address from ctx, if present.
func FromContext(ctx context.Context) (net.IP, bool) {
	// ctx.Value returns nil if ctx has no value for the key;
	// the net.IP type assertion returns ok=false for nil.
	userIP, ok := ctx.Value(&key).(net.IP)
	return userIP, ok
}
Beispiel #22
0
// return server.Context
func NewContext(ctx context.Context) (Context, bool) {
	c, ok := ctx.Value("serverContext").(*serverContext)
	return c, ok
}