Exemplo n.º 1
0
func (rc *RegistrationController) PostRegistration(w http.ResponseWriter, r *http.Request) {
	var um *models.User

	decoder := json.NewDecoder(r.Body)
	if err := decoder.Decode(&um); err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}

	if registered, dbUserModel := um.GetUser(um.AsanaId); registered {
		http.Redirect(w, r, pathPrefix+"/login?registered=1", http.StatusMovedPermanently)
	} else if dbUserModel == nil {
		// Bad Asana Id. Should not have happened.
		http.Error(w, "Please login with Asana to continue registration. Invalid Asana Id.", http.StatusForbidden)
	} else {
		// Register User (Save to db)
		if ok, _ := dbUserModel.RegisterUser(um); !ok {
			http.Error(w, "Error occured during registration.", http.StatusInternalServerError)
		}
	}
}