terminal42 / contao-mailusername

MIT License
7 stars 5 forks source link

Check for existing username in save_callback #21

Closed fritzmg closed 2 years ago

fritzmg commented 2 years ago

There can be edge cases where the following error occurs:

PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'foobar@example.com' for key 'username'

during the createNewUser hook. This can occur when parallel requests with the same POST data are processed. This is hard to reproduce though. In the real world it can only happen with browsers that allow sending the same form multiple times (by clicking the submit button multiple times) - which most modern browsers don't (I can only reproduce it sometimes with Internet Explorer).

This PR introduces an additional safety check in the save_callback for tl_member.email, so that the form will not validate, if a username with the same e-mail address is already in the database at this point in time.

fritzmg commented 2 years ago

I think we should probably also lock the table to be sure that between the username check and the username update no new entry with the same username is made.

aschempp commented 2 years ago

Thank you @fritzmg