Exemplo n.º 1
0
// Deletes an existing User account.
func TestDeleteUser(t *testing.T) {
	Setup()
	defer Teardown()

	// get the user we plan to update
	if err := database.DeleteUser(1); err != nil {
		t.Error(err)
	}

	// now try to get the user from the database
	_, err := database.GetUser(1)
	if err == nil {
		t.Fail()
	}
}
Exemplo n.º 2
0
// delete a specific user.
func UserDelete(w http.ResponseWriter, r *http.Request, u *User) error {
	// the user must confirm their password before deleting
	password := r.FormValue("password")
	if err := u.ComparePassword(password); err != nil {
		return RenderError(w, err, http.StatusBadRequest)
	}
	// TODO we need to delete all repos, builds, commits, branches, etc
	// TODO we should transfer ownership of all team-owned projects to the team owner
	// delete the account
	if err := database.DeleteUser(u.ID); err != nil {
		return RenderError(w, err, http.StatusBadRequest)
	}

	Logout(w, r)
	return nil
}
Exemplo n.º 3
0
func AdminUserDelete(w http.ResponseWriter, r *http.Request, u *User) error {
	// get the ID from the URL parameter
	idstr := r.FormValue("id")
	id, err := strconv.Atoi(idstr)
	if err != nil {
		return err
	}

	// cannot delete self
	if u.ID == int64(id) {
		return RenderForbidden(w)
	}

	// delete the user
	if err := database.DeleteUser(int64(id)); err != nil {
		return err
	}

	http.Redirect(w, r, "/account/admin/users", http.StatusSeeOther)
	return nil
}