func SaveUser(w http.ResponseWriter, r *http.Request) { reqBody := userReqPostBody{} appErr := decode(r, &reqBody) if appErr != nil { reply.Err(w, appErr) return } user := model.User{} user.Email = reqBody.Email user.Password = reqBody.Password exists, err := user.EmailExists() if exists { reply.Err(w, ae.UserNameExists("", "email")) return } else if err != nil { reply.Err(w, ae.DB("", err)) return } user.HashPassword("") err = user.Save() if err != nil { reply.Err(w, ae.DB("", err)) return } reply.OK(w, user) }
func EmailExists(w http.ResponseWriter, r *http.Request) { urlParams := context.Get(r, "params").(httprouter.Params) email := urlParams.ByName("email") if len(email) == 0 { reply.Err(w, ae.Required("", "email")) return } user := model.User{} user.Email = email exists, err := user.EmailExists() if err != nil { reply.Err(w, ae.DB("", err)) return } result := make(map[string]interface{}) result["exists"] = exists reply.OK(w, result) }