joindin/joind.in — pull request #473 by mvriel (2012-03-01 21:13:56+00:00)
Title: JOINDIN-167: Bug in Facebook auth

After some debugging it was discovered that the cause of the issue was twofold:

1. Facebook user can have _no_ username
2. the user_mode::getByUser() method tries to find a user by id if the given argument is numeric

What happens is that the Facebook integration uses the Facebook username as basis for a Joindin username; if no Facebook username is returned than the duplicate detection will create a username 11 (12, 13, 14, etc).

Since the getByUser() method tries to find the user by id if the given argument is numeric is a new user created with a pure numeric name but a user with the id corresponding with that name logged in _the first time_.

Every subsequential time is the user logged in using the correct user as a different part of the code handles that user retrieval.

**Fix**
The issue is resolved by doing two actions:

1. replacing the getByUser() method with getByUsername(), this forces Joindin to find the user by name and never by id
2. if no username is provided by Facebook then Joindin will sluggify the full name (which always contains a value; this was checked) and on that result use the duplication detection.

**Test scenarios**
This issue has been tested with the following scenarios:

1. Sign on with a Facebook user that has a username but is not in Joind.in
2. Sign on with a Facebook user that has no username and is not in Joind.in
3. Sign on with a Facebook user that has a username and is registered in Joind.in
4. Sign on with a Facebook user that has no username and is registered in Joind.in

It is recommended to test the above on the test environment before going live.