func SignupAction(env Env) (status Status, headers Headers, body Body) { user := users.NewUser() formdata.UnmarshalByNames(env.Request().Request, user, []string{"Email", "Name", "Password", "ConfirmPassword"}) if validated := user.ValidateSignupForm(); validated.HasError() { mangotemplate.ForRender(env, "sessions/signup", &SessionData{User: user, Validated: validated}) return } if validated := user.ValidateEmailExist(); validated.HasError() { mangotemplate.ForRender(env, "sessions/signup", &SessionData{User: user, Validated: validated}) return } if err := user.Signup(); err != nil { panic(err) return } services.PutUserIdToSession(env, user.Id.Hex()) return Redirect(http.StatusFound, "/") }
func Update(env Env) (status Status, headers Headers, body Body) { userInput := &duoerlapi.UserInput{Id: services.FetchUserIdFromSession(env)} formdata.UnmarshalByNames(env.Request().Request, userInput, userFields) err := services.UpdateProfile(userInput) if err != nil { panic(err) } return Redirect(http.StatusFound, "/user/edit") }
func Create(env Env) (status Status, headers Headers, body Body) { ownItemInput := new(duoerlapi.OwnItemInput) formdata.UnmarshalByNames(env.Request().Request, &ownItemInput, ownItemFields) ownItemInput.UserId = services.FetchUserIdFromSession(env) err := services.AddOwnItem(ownItemInput) if err != nil { panic(err) } return }
func Create(env Env) (status Status, headers Headers, body Body) { brandInput := new(duoerlapi.BrandInput) formdata.UnmarshalByNames(env.Request().Request, &brandInput, brandFields) result, err := services.CreateBrand(brandInput) if validated, ok := err.(*govalidations.Validated); ok { mangotemplate.ForRender(env, "brands/new", newBrandViewData(result, validated)) return } if err != nil { panic(err) } return Redirect(http.StatusFound, "/brand/"+result.Id) }
func Create(env Env) (status Status, headers Headers, body Body) { reviewInput := new(duoerlapi.ReviewInput) formdata.UnmarshalByNames(env.Request().Request, &reviewInput, reviewFields) reviewInput.AuthorId = services.FetchUserIdFromSession(env) result, err := services.CreateReview(reviewInput) if validated, ok := err.(*govalidations.Validated); ok { // TODO: Ajax needed here mangotemplate.ForRender(env, "products/new", validated) return } if err != nil { panic(err) } return Redirect(http.StatusFound, "/product/"+result.ProductId) }
func Update(env Env) (status Status, headers Headers, body Body) { newsInput := new(duoerlapi.NewsInput) formdata.UnmarshalByNames(env.Request().Request, &newsInput, newsFields) result, err := services.UpdateNews(newsInput) if validated, ok := err.(*govalidations.Validated); ok { viewData := &NewsViewData{ NewsInput: newsInput, Validated: validated, } mangotemplate.ForRender(env, "news/edit", viewData) return } if err != nil { panic(err) } return Redirect(http.StatusFound, "/news/"+result.Id) }
func Update(env Env) (status Status, headers Headers, body Body) { productInput := new(duoerlapi.ProductInput) formdata.UnmarshalByNames(env.Request().Request, &productInput, productFields) result, err := services.UpdateProduct(productInput) if validated, ok := err.(*govalidations.Validated); ok { viewData := &ProductViewData{ ProductInput: result, Validated: validated, } mangotemplate.ForRender(env, "products/edit", viewData) return } if err != nil { panic(err) } return Redirect(http.StatusFound, "/product/"+result.Id) }
func LoginAction(env Env) (status Status, headers Headers, body Body) { user := users.NewUser() formdata.UnmarshalByNames(env.Request().Request, user, []string{"Email", "Password"}) validated := user.ValidateLoginForm() if validated.HasError() { mangotemplate.ForRender(env, "sessions/login", &SessionData{User: user, Validated: validated}) return } loginUser := users.LoginWith(user.Email, user.Password) if loginUser == nil { validated.AddError("Password", "User and password do not match!") mangotemplate.ForRender(env, "sessions/login", &SessionData{User: user, Validated: validated}) return } services.PutUserIdToSession(env, loginUser.Id.Hex()) return Redirect(http.StatusFound, "/") }
func Create(env Env) (status Status, headers Headers, body Body) { postInput := new(duoerlapi.PostInput) formdata.UnmarshalByNames(env.Request().Request, &postInput, postFields) postInput.AuthorId = services.FetchUserIdFromSession(env) result, err := services.CreatePost(postInput) if validated, ok := err.(*govalidations.Validated); ok { b, _ := json.Marshal(validated) body = Body(b) return } if err != nil { panic(err) } b, _ := json.Marshal(result) body = Body(b) return }
func Create(env Env) (status Status, headers Headers, body Body) { noteInput := new(duoerlapi.NoteInput) formdata.UnmarshalByNames(env.Request().Request, ¬eInput, noteFields) noteInput.AuthorId = services.FetchUserIdFromSession(env) result, err := services.CreateNote(noteInput) if validated, ok := err.(*govalidations.Validated); ok { viewData := &NoteViewData{ NoteInput: noteInput, Validated: validated, } mangotemplate.ForRender(env, "notes/new", viewData) return } if err != nil { panic(err) } return Redirect(http.StatusFound, "/note/"+result.Id) }
func Create(env Env) (status Status, headers Headers, body Body) { categoryInput := new(duoerlapi.CategoryInput) formdata.UnmarshalByNames(env.Request().Request, &categoryInput, categoryFields) viewData := &AdminCategoryViewData{ CategoryInput: categoryInput, ApiCategories: services.GetCategories(), } _, err := services.CreateCategory(categoryInput) if validated, ok := err.(*govalidations.Validated); ok { viewData.Validated = validated mangotemplate.ForRender(env, "admin/categories", viewData) return } if err != nil { panic(err) } return Redirect(http.StatusFound, "/admin/categories") }