I'm having hard time understanding how magnet works...

Be reassured: it's less than trivial for about everybody. But theories about what effects a magnet has are well established, and some people get decently easy with. There are always tricky cases, though.

[When a magnet in a generator produces electricity], does the magnet's northpole attract electrons and its southpole repel the electrons?

No. Without a relative movement, there is no force between a magnet and an electron. At least if neglecting the electron's magnetic moment, which is perfectly legitimate in electric machines.

But with a relative movement, yes. A moving magnetic field is equivalent to a static one plus an electric field, and it does apply a force on electrons. So a generator comprises permanent magnets or electromagnets, and it has conductors to scoop the produced current, and turning the shaft of a rotating generator moves the magnets relative to the conductors.

More numerically, a relative speed v an an induction B (both are 3D vectors, with a strength and a direction) create an electric field E=vΛB, where Λ is a vector product: E is perpendicular to both v and B, with a strength equal to the product of their absolute values times the cosine of the angle between v and B. That is, v and B must be perpendicular to achieve the biggest E. Look at a generator: v, B and the conductors are engineered pretty much perpendicular to an other.