Fix duplicated student preferences when a student's email has changed
Students whose emails were changed since they last logged in but before they were added as a student preference can be added twice.
Refactored this entire part of the code as it was quite messy.
Related to #701 (closed), but I doubt this was the root cause of the issue (emails don't change very often).
Edited by Martin Mladenov