Exemplo n.º 1
0
// todo move to media.js
func uploadImageButtonScript(ctx *view.Context, parentSelector, dropZoneSelector, listSelector string, thumbnailSize int, onComplete string) string {
	extraDropzones := "[]"
	if dropZoneSelector != "" {
		dropZoneSelector = fmt.Sprintf(`[jQuery("%s")[0]]`, dropZoneSelector)
	}
	listElement := "null"
	if listSelector != "" {
		listElement = fmt.Sprintf(`jQuery("%s")[0]`, listSelector)
	}
	if onComplete == "" {
		onComplete = "function(){}"
	}
	uploadURL := UploadImage.URL(ctx.ForURLArgsConvert(thumbnailSize))
	return fmt.Sprintf(
		`jQuery(function() {
			var uploader = new qq.FileUploader({
				debug: true,
			    element: jQuery("%s")[0],
			    extraDropzones: %s,
			    listElement: %s,
			    action: "%s",
			    allowedExtensions: ["png", "jpg", "jpeg", "gif", "bmp", "tif", "tiff"],
			    acceptFiles: ["image/png", "image/jpeg", "image/gif", "image/bmp", "image/tiff"],
			    sizeLimit: 1024*1024*64,
			    multiple: false,
			    onComplete: %s
			});
		});`,
		parentSelector,
		extraDropzones,
		listElement,
		uploadURL,
		onComplete,
	)
}
Exemplo n.º 2
0
func (self *Auth) Authenticate(context *view.Context) (ok bool, err error) {
	id, ok := context.SessionID()
	if !ok {
		return false, nil
	}

	ok, err = IsConfirmedUserID(id)
	if !ok && err == nil && self.LoginURL != nil {
		err = view.Redirect(self.LoginURL.URL(context.PathArgs...))
	}
	return ok, err
}
Exemplo n.º 3
0
// Returns nil if there is no session user
func OfSession(context *view.Context) (userDoc interface{}) {
	if context.User != nil {
		return context.User
	}
	//	if userDoc, ok := context.Cached(ContextCacheKey); ok {
	//		return userDoc
	//	}
	id, ok := context.SessionID()
	if !ok {
		return nil
	}
	userDoc, _, _ = FindByID(id)
	context.User = userDoc
	return userDoc
}
Exemplo n.º 4
0
func Logout(context *view.Context) {
	context.DeleteSessionID()
	//context.DeleteCached(ContextCacheKey)
	context.User = nil
}
Exemplo n.º 5
0
func Login(context *view.Context, userDoc interface{}) {
	context.SetSessionID(userDoc.(mongo.Document).ObjectId().Hex())
	//context.Cache(ContextCacheKey, userDoc)
	context.User = userDoc
}