Some LDAP refactoring and fallback to User Principal Name if no email address is found

Some refactorings related to how the LDAP authentication works (first authenticate then gather information).

Some LDAP servers do not explicitly expose a mail attribute. Therefore we use the User Principal Name as an email address if we are not able to use the attribute define by ldap_mail_attr.