// 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 }, ) }
// Nav returns user navigation links depending on if there is an user session. // If a user session is active, logout and profile will be returned, // if there is no active user session, login and signup will be returned. // separator will be put between the returned links. // signup, profile, and separator are optional and can be nil. func Nav(login, signup, logout, profile *view.Link, separator view.View) view.View { return view.DynamicView( func(ctx *view.Context) (view.View, error) { if ctx.Session.ID() != "" { if profile == nil { return logout, nil } return view.Views{logout, separator, profile}, nil } if signup == nil { return login, nil } return view.Views{login, separator, signup}, nil }, ) }
// Nav returns user navigation links depending on if there is an user session. // If a user session is active, logout and profile will be returned, // if there is no active user session, login and signup will be returned. // separator will be put between the returned links. // signup, profile, and separator are optional and can be nil. func Nav(login, signup, logout, profile *view.Link, separator view.View) view.View { return view.DynamicView( func(context *view.Context) (view.View, error) { if _, ok := context.SessionID(); ok { if profile == nil { return logout, nil } return view.Views{logout, separator, profile}, nil } if signup == nil { return login, nil } return view.Views{login, separator, signup}, nil }, ) }
func NewLoginForm(buttonText, class, errorMessageClass, successMessageClass string, redirectURL view.URL) view.View { return view.DynamicView( func(context *view.Context) (v view.View, err error) { if from, ok := context.Params["from"]; ok { redirectURL = view.StringURL(from) } model := &LoginFormModel{} if email, ok := context.Params["email"]; ok { model.Email.Set(email) } form := &view.Form{ Class: class, ErrorMessageClass: errorMessageClass, SuccessMessageClass: successMessageClass, SuccessMessage: "Login successful", SubmitButtonText: buttonText, FormID: "gostart_user_login", GetModel: view.FormModel(model), Redirect: redirectURL, OnSubmit: func(form *view.Form, formModel interface{}, context *view.Context) (string, view.URL, error) { m := formModel.(*LoginFormModel) ok, err := LoginEmailPassword(context, m.Email.Get(), m.Password.Get()) if err != nil { if view.Config.Debug.Mode { return "", nil, err } else { return "", nil, errors.New("An internal error ocoured") } } if !ok { return "", nil, errors.New("Wrong email and password combination") } return "", nil, nil }, } return form, nil }, ) }
func (self ImageRefController) NewInput(withLabel bool, metaData *model.MetaData, form *view.Form) (input view.View, err error) { imageRef := metaData.Value.Addr().Interface().(*ImageRef) thumbnailSize := Config.ImageRefController.ThumbnailSize var img view.View if imageRef.IsEmpty() { img = view.IMG(Config.dummyImageURL, thumbnailSize, thumbnailSize) } else { image, found, err := imageRef.TryGet() if err != nil { return nil, err } if found { version, err := image.Thumbnail(thumbnailSize) if err != nil { return nil, err } img = version.View("") } else { imageRef.Set(nil) img = view.IMG(Config.dummyImageURL, thumbnailSize, thumbnailSize) } } hiddenInput := &view.HiddenInput{Name: metaData.Selector(), Value: imageRef.String()} thumbnailFrame := &view.Div{ Class: Config.ImageRefController.ThumbnailFrameClass, Style: fmt.Sprintf("width:%dpx;height:%dpx;", thumbnailSize, thumbnailSize), Content: img, } uploadList := &view.List{Class: "qq-upload-list"} removeButton := &view.Div{ Class: "qq-upload-button", Content: view.HTML("Remove"), OnClick: fmt.Sprintf( `jQuery("#%s").attr("value", ""); jQuery("#%s").empty().append("<img src='%s' width='%d' height='%d'/>"); jQuery("#%s").empty();`, hiddenInput.ID(), thumbnailFrame.ID(), Config.dummyImageURL, thumbnailSize, thumbnailSize, uploadList.ID(), ), } chooseDialogThumbnails := view.DIV("") chooseDialogThumbnailsID := chooseDialogThumbnails.ID() chooseDialog := &view.ModalDialog{ Style: "width:600px;height:400px;", Content: view.Views{ view.H3("Choose Image:"), chooseDialogThumbnails, view.ModalDialogCloseButton("Close"), }, } chooseButton := view.DynamicView( func(ctx *view.Context) (view.View, error) { return &view.Div{ Class: "qq-upload-button", Content: view.HTML("Choose existing"), OnClick: fmt.Sprintf( `gostart_media.fillChooseDialog('#%s', '%s', function(value){ jQuery('#%s').attr('value', value.id); var img = '<img src=\"'+value.url+'\" alt=\"'+value.title+'\"/>'; jQuery('#%s').empty().append(img); %s }); %s;`, chooseDialogThumbnailsID, AllThumbnailsAPI.URL(ctx.ForURLArgsConvert(Config.ImageRefController.ThumbnailSize)), hiddenInput.ID(), thumbnailFrame.ID(), view.ModalDialogCloseScript, chooseDialog.OpenScript(), ), }, nil }, ) uploadButton := view.DIV("") uploadButtonID := uploadButton.ID() uploadButton.Content = UploadImageButton( "#"+uploadButtonID, "#"+thumbnailFrame.ID(), "#"+uploadList.ID(), thumbnailSize, fmt.Sprintf( `function(id, fileName, responseJSON) { var img = "<img src='" + responseJSON.thumbnailURL + "' width='%d' height='%d'/>"; jQuery("#%s").empty().html(img); jQuery("#%s").attr("value", responseJSON.imageID); }`, thumbnailSize, thumbnailSize, thumbnailFrame.ID(), hiddenInput.ID(), ), ) editor := view.DIV(Config.ImageRefController.Class, view.RequireScriptURL("/media/media.js", 0), view.RequireStyle( `.qq-upload-button { margin: 0 0 5px 10px; cursor: pointer; } .qq-upload-button:hover { background-color: #cc0000; }`, 10, ), chooseDialog, hiddenInput, thumbnailFrame, &view.Div{ Class: Config.ImageRefController.ActionsClass, Style: fmt.Sprintf("margin-left: %dpx", thumbnailSize+10), Content: view.Views{ removeButton, chooseButton, uploadButton, }, }, uploadList, ) if withLabel { return view.AddStandardLabel(form, editor, metaData), nil } return editor, nil }