{"action":"created","issue":{"url":"https://api.github.com/repos/HabitRPG/habitrpg/issues/5126","labels_url":"https://api.github.com/repos/HabitRPG/habitrpg/issues/5126/labels{/name}","comments_url":"https://api.github.com/repos/HabitRPG/habitrpg/issues/5126/comments","events_url":"https://api.github.com/repos/HabitRPG/habitrpg/issues/5126/events","html_url":"https://github.com/HabitRPG/habitrpg/issues/5126","id":72612938,"number":5126,"title":"Accounts uniqueness","user":{"login":"paglias","id":589911,"avatar_url":"https://avatars.githubusercontent.com/u/589911?v=3","gravatar_id":"","url":"https://api.github.com/users/paglias","html_url":"https://github.com/paglias","followers_url":"https://api.github.com/users/paglias/followers","following_url":"https://api.github.com/users/paglias/following{/other_user}","gists_url":"https://api.github.com/users/paglias/gists{/gist_id}","starred_url":"https://api.github.com/users/paglias/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/paglias/subscriptions","organizations_url":"https://api.github.com/users/paglias/orgs","repos_url":"https://api.github.com/users/paglias/repos","events_url":"https://api.github.com/users/paglias/events{/privacy}","received_events_url":"https://api.github.com/users/paglias/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":16,"created_at":"2015-05-02T08:40:44Z","updated_at":"2015-05-06T10:39:27Z","closed_at":null,"body":"cc @Alys @lefnire \r\n\r\nSee also #3986 .\r\n\r\nThe fields we want to enforce uniqueness on are:\r\n\r\n- [ ] `auth.local.email` (sparse)\r\n- [x] `auth.facebook.id` (sparse)\r\n- [ ] `auth.local.username` (sparse)\r\n\r\n## Steps\r\n\r\n1. Delete all duplicates\r\n1. Create compound index on this fields so we can drop the existing indexes without slowing down the site. For example `{email: 1}` could become `{email: 1, _id: 1}` so that emails can be searched without problems when we temporarily drop the index\r\n1. Delete existing, non unique indexes\r\n1. Block new registrations\r\n1. Create new unique indexes\r\n1. Drop temporary compound indexes\r\n\r\n## Possible problems\r\n\r\n- [ ] Sparse indexes have some limitations http://docs.mongodb.org/manual/core/index-sparse/#index-type-sparse\r\n- [x] Indexes creation: background or foreground? See http://docs.mongodb.org/manual/core/index-creation/#background-construction\r\n- [ ] What about emails: should be case sensitive or not? Currently registration is case insentive but login is case sensitive (to allow old accounts that may have case sensitive emails to be accessed). If we don't identify any duplicate when transforming all emails to lower cases we should simply force lower cases at registration and then migrate the rest. \r\n- [ ] Duplicates with different combination of email/username. For example same username, but different emails: probably belong to two different people.\r\n- [ ] Handle mongo errors\r\n- [ ] Block multiple submissions of signup form (#5141)\r\n\r\n<bountysource-plugin>\r\n---\r\nWant to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/12804439-accounts-uniqueness?utm_campaign=plugin&utm_content=tracker%2F68393&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F68393&utm_medium=issues&utm_source=github).\r\n</bountysource-plugin>"},"comment":{"url":"https://api.github.com/repos/HabitRPG/habitrpg/issues/comments/99413962","html_url":"https://github.com/HabitRPG/habitrpg/issues/5126#issuecomment-99413962","issue_url":"https://api.github.com/repos/HabitRPG/habitrpg/issues/5126","id":99413962,"user":{"login":"Alys","id":1495809,"avatar_url":"https://avatars.githubusercontent.com/u/1495809?v=3","gravatar_id":"","url":"https://api.github.com/users/Alys","html_url":"https://github.com/Alys","followers_url":"https://api.github.com/users/Alys/followers","following_url":"https://api.github.com/users/Alys/following{/other_user}","gists_url":"https://api.github.com/users/Alys/gists{/gist_id}","starred_url":"https://api.github.com/users/Alys/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Alys/subscriptions","organizations_url":"https://api.github.com/users/Alys/orgs","repos_url":"https://api.github.com/users/Alys/repos","events_url":"https://api.github.com/users/Alys/events{/privacy}","received_events_url":"https://api.github.com/users/Alys/received_events","type":"User","site_admin":false},"created_at":"2015-05-06T10:39:27Z","updated_at":"2015-05-06T10:39:27Z","body":"I won't because it's a bit too close to my bedtime for me to be trying something new. \r\n\r\nHopefully you'll be able to create it, without too many new accounts to clean up first! Good luck. :)"}}