A 7.2-magnitude earthquake has hit New Zealand's second-largest town, with aftershocks ongoing.