// Handles the http request for creating a new user // // The Accept/Content-type header should be set appropriately for which // kind of respone is being sent. func CreateNewUser(self *ss.AppServer, w http.ResponseWriter, req *http.Request) error { switch req.Header.Get("Content-type") { case "application/json": type CreateUserRequest struct { Email string `json:"EMAIL"` Password string `json:"PASSWORD"` Generate bool `json:"GENERATE"` } b, err := ioutil.ReadAll(req.Body) defer req.Body.Close() if err != nil { return err } cur := &CreateUserRequest{} err = json.Unmarshal(b, cur) if err != nil { return err } if cur.Generate { cur.Password = ss.GenerateNewPassword() } err = ss.CreateUser(cur.Email, cur.Password) if err != nil { io.WriteString(w, fmt.Sprintf(`{"error": "%s"}`, utils.EscapeQuotes(err.Error()))) } else { io.WriteString(w, `{"success": true}`) } return err } panic("unreachable") }
// Not implemented properly at the moment. func CreateUser(self *bk.AppServer, w http.ResponseWriter, req *http.Request) error { fmt.Println(bk.CreateUser("aero", "something")) io.WriteString(w, "done!") return nil }