Output current and voltage levels regulation in ac/dc adapter
In your second schematic, opamp 2, is amplifying the voltage across the current sense resistor R2. 

That voltage is simply the product of R2 and the current through the secondary side of the transformer.

Now, if that current is high, then the opamp has a very high output voltage.  That means no current is sunk into the opamp output. If opamp 1's output also has high output voltage, then no current can be sunk there, either, turning off the LED in the optocoupler.

That Opamp1's output is also turned high when opamp2's output is high is ensured by the voltage divider R3R4-R5.