func main() { debug.Nop() /////////////////////////////////////////////////////////////////////////// // Load configuration defer config.Close() // Close all packages on exit config.Load("config.json", &EmailConfig{&email.Config}, &mongo.Config, &user.Config, &view.Config, &media.Config, &mongomedia.Config, ) /////////////////////////////////////////////////////////////////////////// // Ensure that an admin user exists var admin models.User _, err := user.EnsureExists("admin", "*****@*****.**", "test", true, &admin) errs.PanicOnError(err) admin.Admin = true err = admin.Save() errs.PanicOnError(err) /////////////////////////////////////////////////////////////////////////// // Config view view.Config.NamedAuthenticators["admin"] = views.Admin_Auth view.Config.Debug.Mode = true // view.Config.Debug.LogPaths = true // view.Config.Debug.LogRedirects = true // view.Config.DisableCachedViews = true // view.Config.GlobalAuth = view.NewBasicAuth("statuplive.in", "gostart", "gostart") /////////////////////////////////////////////////////////////////////////// // Run server view.RunServer(views.Paths()) }
func init() { Profile = NewPublicPage("My Profile | go-start Tutorial", DIV("public-content", DynamicView( func(ctx *Context) (view View, err error) { var usr models.User found, err := user.OfSession(ctx.Session, &usr) if err != nil { return nil, err } if !found { return H1("You have to be logged in to edit your startup"), nil } email := usr.PrimaryEmail() view = DIV("row", DIV("cell right-border", TitleBar("My Profile"), DIV("main-content", H3("Email: ", email), H3("Name:"), P(&Form{ SubmitButtonText: "Save name", SubmitButtonClass: "button", FormID: "profile", GetModel: func(form *Form, ctx *Context) (interface{}, error) { return &usr.Name, nil }, OnSubmit: func(form *Form, formModel interface{}, ctx *Context) (string, URL, error) { return "", StringURL("."), usr.Save() }, }), H3("Password:"******"Save password", SubmitButtonClass: "button", FormID: "password", GetModel: func(form *Form, ctx *Context) (interface{}, error) { return new(user.PasswordFormModel), nil }, OnSubmit: func(form *Form, formModel interface{}, ctx *Context) (string, URL, error) { m := formModel.(*user.PasswordFormModel) usr.Password.SetHashed(m.Password1.Get()) return "", StringURL("."), usr.Save() }, }), ), ), DivClearBoth(), ) return view, nil }, ), ), ) }
func init() { Admin_UserX = NewAdminPage("Admin Users", DynamicView( func(ctx *Context) (view View, err error) { var u models.User id := bson.ObjectIdHex(ctx.URLArgs[0]) found, err := models.Users.TryDocumentWithID(id, &u) if err != nil { return nil, err } if !found { return nil, NotFound("404: User not found") } views := Views{ H2(u.Name.String()), Printf("Email confirmed: %v", u.EmailPasswordConfirmed()), HR(), &Form{ SubmitButtonText: "Save password and mark email as confirmed", SubmitButtonClass: "button", FormID: "password", DisabledFields: []string{"Current_password"}, GetModel: func(form *Form, ctx *Context) (interface{}, error) { return &passwordFormModel{Current_password: u.Password}, nil }, OnSubmit: func(form *Form, formModel interface{}, ctx *Context) (string, URL, error) { m := formModel.(*passwordFormModel) u.Password.SetHashed(m.New_password.Get()) u.ConfirmEmailPassword() return "", StringURL("."), u.Save() }, }, HR(), &Form{ SubmitButtonText: "Save User Data", SubmitButtonClass: "button", FormID: "user" + u.ID.Hex(), GetModel: FormModel(&u), GeneralErrorOnFieldError: true, OnSubmit: OnFormSubmitSaveModelAndRedirect(Admin_Users), }, } return views, nil }, ), ) }
func init() { Admin_Users = NewAdminPage("Admin Users", Views{ A(Admin_ExportEmails, "Download all emails as .csv"), HR(), &Form{ SubmitButtonText: "Add Person", SubmitButtonClass: "button", FormID: "addperson", OnSubmit: func(form *Form, formModel interface{}, ctx *Context) (string, URL, error) { var u models.User models.Users.InitDocument(&u) u.Name.First = "[First]" u.Name.Last = "[Last]" u.AddEmail("", "") err := u.Save() if err != nil { return "", nil, err } return "", NewURLWithArgs(Admin_UserX, u.ID.Hex()), nil }, }, HR(), &ModelIteratorTableView{ Class: "visual-table", GetModelIterator: func(ctx *Context) model.Iterator { // return models.Users.Iterator() return models.Users.SortFunc( func(a, b *models.User) bool { return utils.CompareCaseInsensitive(a.Name.String(), b.Name.String()) }, ) }, GetRowModel: func(ctx *Context) (interface{}, error) { return new(models.User), nil }, GetHeaderRowViews: func(ctx *Context) (views Views, err error) { return Views{HTML("Nr"), HTML("Name"), HTML("Email"), HTML("Edit"), HTML("Delete")}, nil }, GetRowViews: func(row int, rowModel interface{}, ctx *Context) (views Views, err error) { u := rowModel.(*models.User) editURL := Admin_UserX.URL(ctx.ForURLArgs(u.ID.Hex())) return Views{ Printf("%d", row+1), Escape(u.Name.String()), Escape(u.PrimaryEmail()), A(editURL, "Edit"), &Form{ SubmitButtonText: "Delete", SubmitButtonConfirm: "Are you sure you want to delete " + u.Name.String() + "?", FormID: "delete" + u.ID.Hex(), OnSubmit: func(form *Form, formModel interface{}, ctx *Context) (string, URL, error) { config.Logger.Printf("Deleting user '%s' with ID %s", u.Name.String(), u.ID.Hex()) config.Logger.Printf("FormID: " + form.FormID) return "", StringURL("."), u.Delete() }, }, }, nil }, }, }, ) }