コード例 #1
0
ファイル: views.go プロジェクト: sedzinreri/go-start
// The confirmation code will be passed in the GET parameter "code"
func EmailConfirmationView(profileURL view.URL) view.View {
	return view.DynamicView(
		func(context *view.Context) (view.View, error) {
			confirmationCode, ok := context.Params["code"]
			if !ok {
				return view.DIV("error", view.HTML("Invalid email confirmation code!")), nil
			}

			doc, email, confirmed, err := ConfirmEmail(confirmationCode)
			if !confirmed {
				return view.DIV("error", view.HTML("Invalid email confirmation code!")), err
			}

			Login(context, doc)

			return view.Views{
				view.DIV("success", view.Printf("Email address %s confirmed!", email)),
				&view.If{
					Condition: profileURL != nil,
					Content: view.P(
						view.HTML("Continue to your "),
						view.A(profileURL, "profile..."),
					),
				},
			}, nil
		},
	)
}
コード例 #2
0
ファイル: blobsadmin.go プロジェクト: alexchipliev/go-start
func BlobsAdmin() view.View {
	return view.Views{
		UploadBlobButton("", "", "function(){window.location.reload()}"),
		&view.ModelIteratorView{
			GetModelIterator: func(ctx *view.Context) model.Iterator {
				// debug.Dump(Config.Backend.Blobs.Count())
				return Config.Backend.BlobIterator()
			},
			GetModel: func(ctx *view.Context) (interface{}, error) {
				return new(Blob), nil
			},
			GetModelView: func(ctx *view.Context, m interface{}) (view.View, error) {
				blob := *m.(*Blob) // copy by value because it will be used in a closure later on
				refCount, err := blob.CountRefs()
				if err != nil {
					return nil, err
				}
				deleteConfirmation := fmt.Sprintf("Are you sure you want to delete the blob %s?", blob.Title)
				if refCount > 0 {
					deleteConfirmation += fmt.Sprintf(" It is used %d times!", refCount)
				}
				editor := view.DIV(Config.Admin.ImageEditorClass,
					view.H3(blob.Title.Get()),
					view.P("Link to file: ", view.A_blank(blob.FileURL()) /*, view.Printf(" | Used %d times", refCount)*/),
					view.P(view.Printf("Size: %d kb", blob.Size.Get()/1024.0)),
					&view.Form{
						FormID:            "edit" + blob.ID.Get(),
						SubmitButtonClass: Config.Admin.ButtonClass,
						GetModel: func(form *view.Form, ctx *view.Context) (interface{}, error) {
							return &blobData{
								Title:    blob.Title,
								Filename: blob.Filename,
								Link:     blob.Link,
							}, nil
						},
						OnSubmit: func(form *view.Form, formModel interface{}, ctx *view.Context) (message string, redirect view.URL, err error) {
							model := formModel.(*blobData)
							blob.Title = model.Title
							blob.Filename = model.Filename
							blob.Link = model.Link
							err = blob.Save()
							return "", view.StringURL("."), err
						},
					},
					&view.Form{
						SubmitButtonText:    "Delete",
						SubmitButtonConfirm: deleteConfirmation,
						SubmitButtonClass:   Config.Admin.ButtonClass,
						FormID:              "delete" + blob.ID.Get(),
						OnSubmit: func(form *view.Form, formModel interface{}, ctx *view.Context) (message string, redirect view.URL, err error) {
							_, err = blob.RemoveAllRefs()
							if err != nil {
								return "", nil, err
							}
							return "", view.StringURL("."), blob.Delete()
						},
					},
					view.DivClearBoth(),
				)
				return editor, nil
			},
		},
	}
}
コード例 #3
0
ファイル: imagesadmin.go プロジェクト: JessonChan/go-start
func ImagesAdmin() view.View {
	uploader := view.DIV("")
	uploaderID := uploader.ID()
	uploader.Content = UploadImageButton("#"+uploaderID, "", "", Config.ImagesAdmin.ThumbnailSize, "function(){window.location.reload()}")
	return view.Views{
		uploader,
		&view.ModelIteratorView{
			GetModelIterator: func(ctx *view.Context) model.Iterator {
				return Config.Backend.ImageIterator()
			},
			GetModelIteratorView: func(ctx *view.Context, m interface{}) (view.View, error) {
				image := m.(*Image)
				refCount, err := image.CountRefs()
				if err != nil {
					return nil, err
				}
				thumbnail, err := image.Thumbnail(Config.ImagesAdmin.ThumbnailSize)
				if err != nil {
					return nil, err
				}
				deleteConfirmation := fmt.Sprintf("Are you sure you want to delete the image %s?", image.TitleOrFilename())
				if refCount > 0 {
					deleteConfirmation += fmt.Sprintf(" It is used %d times!", refCount)
				}
				editor := view.DIV(Config.ImagesAdmin.ImageEditorClass,
					view.H3(image.TitleOrFilename()),
					view.P(
						view.A_blank(image.GetURL(), "Link to original"),
						view.Printf(" | Used %d times", refCount),
					),
					view.DIV(Config.ImagesAdmin.ThumbnailFrameClass,
						thumbnail.View(""),
					),
					&view.Form{
						FormID:            "edit" + image.ID.Get(),
						SubmitButtonClass: Config.ImagesAdmin.ButtonClass,
						GetModel: func(form *view.Form, ctx *view.Context) (interface{}, error) {
							return &imageData{
								Title:    image.Title,
								Filename: model.String(image.Filename()),
								Link:     image.Link,
							}, nil
						},
						OnSubmit: func(form *view.Form, formModel interface{}, ctx *view.Context) (message string, redirect view.URL, err error) {
							model := formModel.(*imageData)
							image.Title = model.Title
							image.Link = model.Link
							for i := range image.Versions {
								image.Versions[i].Filename = model.Filename
							}
							err = image.Save()
							return "", view.StringURL("."), err
						},
					},
					&view.Form{
						SubmitButtonText:    "Delete",
						SubmitButtonConfirm: deleteConfirmation,
						SubmitButtonClass:   Config.ImagesAdmin.ButtonClass,
						FormID:              "delete" + image.ID.Get(),
						OnSubmit: func(form *view.Form, formModel interface{}, ctx *view.Context) (message string, redirect view.URL, err error) {
							err = image.RemoveAllRefs()
							if err != nil {
								return "", nil, err
							}
							return "", view.StringURL("."), image.Delete()
						},
					},
					view.DivClearBoth(),
				)
				return editor, nil
			},
		},
	}
}
コード例 #4
0
ファイル: imagesadmin.go プロジェクト: WaylandGod/go-start
func ImagesAdmin() view.View {
	return view.Views{
		UploadImageButton("", "", Config.Admin.ThumbnailSize, "function(){window.location.reload()}"),
		view.HR(),
		&view.Form{
			SubmitButtonText:  "Delete smaller image versions (they will be regenerated)",
			SubmitButtonClass: Config.Admin.ButtonClass,
			FormID:            "deleteVersions",
			OnSubmit: func(form *view.Form, formModel interface{}, ctx *view.Context) (message string, redirect view.URL, err error) {
				var image Image

				for i := ImageIterator(); i.Next(&image); {
					err = image.DeleteVersions()
					if err != nil {
						return "", nil, err
					}
					err = image.Save()
					if err != nil {
						return "", nil, err
					}
				}
				return "", view.StringURL("."), nil
			},
		},
		&view.ModelIteratorView{
			GetModelIterator: func(ctx *view.Context) model.Iterator {
				return Config.Backend.ImageIterator()
			},
			GetModel: func(ctx *view.Context) (interface{}, error) {
				return new(Image), nil
			},
			GetModelView: func(ctx *view.Context, m interface{}) (view.View, error) {
				image := *m.(*Image) // copy by value because it will be used in a closure later on
				refCount, err := image.CountRefs()
				if err != nil {
					return nil, err
				}
				thumbnail, err := image.Thumbnail(Config.Admin.ThumbnailSize)
				if err != nil {
					return nil, err
				}
				deleteConfirmation := fmt.Sprintf("Are you sure you want to delete the image %s?", image.Title)
				if refCount > 0 {
					deleteConfirmation += fmt.Sprintf(" It is used %d times!", refCount)
				}
				editor := view.DIV(Config.Admin.ImageEditorClass,
					view.H3(image.Title.Get()),
					view.P(view.A_blank(image.FileURL(), "Link to original") /*, view.Printf(" | Used %d times", refCount)*/),
					view.P("Size in MB: ", view.Printf("%f", (float32)(image.Size.Get())/(1024.0*1024.0))),
					view.DIV(Config.Admin.ThumbnailFrameClass,
						thumbnail.View(""),
					),
					&view.Form{
						FormID:            "edit" + image.ID.Get(),
						SubmitButtonClass: Config.Admin.ButtonClass,
						GetModel: func(form *view.Form, ctx *view.Context) (interface{}, error) {
							return &imageData{
								Title:    image.Title,
								Filename: model.String(image.Filename()),
								Link:     image.Link,
							}, nil
						},
						OnSubmit: func(form *view.Form, formModel interface{}, ctx *view.Context) (message string, redirect view.URL, err error) {
							model := formModel.(*imageData)
							image.Title = model.Title
							image.Link = model.Link
							for i := range image.Versions {
								image.Versions[i].Filename = model.Filename
							}
							err = image.Save()
							return "", view.StringURL("."), err
						},
					},
					&view.Form{
						SubmitButtonText:    "Delete",
						SubmitButtonConfirm: deleteConfirmation,
						SubmitButtonClass:   Config.Admin.ButtonClass,
						FormID:              "delete" + image.ID.Get(),
						OnSubmit: func(form *view.Form, formModel interface{}, ctx *view.Context) (message string, redirect view.URL, err error) {
							_, err = image.RemoveAllRefs()
							if err != nil {
								return "", nil, err
							}
							return "", view.StringURL("."), image.Delete()
						},
					},
					view.DivClearBoth(),
				)
				return editor, nil
			},
		},
	}
}