The second noether theorem as the basis of the theory of singular Lagrangians and Hamiltonians constraints