{"action":"created","comment":{"url":"https://api.github.com/repos/CredoReference/edx-platform/pulls/comments/44787081","id":44787081,"diff_hunk":"@@ -51,13 +60,32 @@ def create_lti_user(lti_user_id, lti_consumer):\n     created = False\n     while not created:\n         try:\n-            edx_user_id = generate_random_edx_username()\n-            edx_email = \"{}@{}\".format(edx_user_id, settings.LTI_USER_EMAIL_DOMAIN)\n+            if lti_email is not None:\n+                edx_email=cut_to_max_len(lti_email, EMAIL_SIZE)\n+                edx_username=cut_to_max_len(lti_email, USERNAME_SIZE)\n+                try:\n+                    #if this username already exists then use the random username\n+                    edx_user = User.objects.get(username=edx_username)\n+                    edx_username=generate_random_edx_username()\n+                except User.DoesNotExist:\n+                    pass\n+            else:\n+                edx_username=generate_random_edx_username()\n+                edx_email = \"{}@{}\".format(edx_username, settings.LTI_USER_EMAIL_DOMAIN)\n+\n             edx_user = User.objects.create_user(\n-                username=edx_user_id,\n+                username=edx_username,\n                 password=edx_password,\n                 email=edx_email,\n             )\n+\n+            if edx_user is not None:","path":"lms/djangoapps/lti_provider/users.py","position":64,"original_position":64,"commit_id":"e433086eb6348ef376953999ee134a45d943c990","original_commit_id":"e433086eb6348ef376953999ee134a45d943c990","user":{"login":"lenacom","id":7777978,"avatar_url":"https://avatars.githubusercontent.com/u/7777978?v=3","gravatar_id":"","url":"https://api.github.com/users/lenacom","html_url":"https://github.com/lenacom","followers_url":"https://api.github.com/users/lenacom/followers","following_url":"https://api.github.com/users/lenacom/following{/other_user}","gists_url":"https://api.github.com/users/lenacom/gists{/gist_id}","starred_url":"https://api.github.com/users/lenacom/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lenacom/subscriptions","organizations_url":"https://api.github.com/users/lenacom/orgs","repos_url":"https://api.github.com/users/lenacom/repos","events_url":"https://api.github.com/users/lenacom/events{/privacy}","received_events_url":"https://api.github.com/users/lenacom/received_events","type":"User","site_admin":false},"body":"In edx-platform code users with additional fields are created in the same way. In django.contrib.auth.models.User.create_user(username, email=None, password=None, **extra_fields) there is the param **extra_fields, the doc says \"The extra_fields keyword arguments are passed through to the User’s __init__ method to allow setting arbitrary fields on a custom User model.\" https://docs.djangoproject.com/en/dev/ref/contrib/auth/","created_at":"2015-11-13T14:29:27Z","updated_at":"2015-11-13T14:29:27Z","html_url":"https://github.com/CredoReference/edx-platform/pull/1#discussion_r44787081","pull_request_url":"https://api.github.com/repos/CredoReference/edx-platform/pulls/1","_links":{"self":{"href":"https://api.github.com/repos/CredoReference/edx-platform/pulls/comments/44787081"},"html":{"href":"https://github.com/CredoReference/edx-platform/pull/1#discussion_r44787081"},"pull_request":{"href":"https://api.github.com/repos/CredoReference/edx-platform/pulls/1"}}},"pull_request":{"url":"https://api.github.com/repos/CredoReference/edx-platform/pulls/1","id":50621464,"html_url":"https://github.com/CredoReference/edx-platform/pull/1","diff_url":"https://github.com/CredoReference/edx-platform/pull/1.diff","patch_url":"https://github.com/CredoReference/edx-platform/pull/1.patch","issue_url":"https://api.github.com/repos/CredoReference/edx-platform/issues/1","number":1,"state":"open","locked":false,"title":"Feature/edx 2","user":{"login":"lenacom","id":7777978,"avatar_url":"https://avatars.githubusercontent.com/u/7777978?v=3","gravatar_id":"","url":"https://api.github.com/users/lenacom","html_url":"https://github.com/lenacom","followers_url":"https://api.github.com/users/lenacom/followers","following_url":"https://api.github.com/users/lenacom/following{/other_user}","gists_url":"https://api.github.com/users/lenacom/gists{/gist_id}","starred_url":"https://api.github.com/users/lenacom/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lenacom/subscriptions","organizations_url":"https://api.github.com/users/lenacom/orgs","repos_url":"https://api.github.com/users/lenacom/repos","events_url":"https://api.github.com/users/lenacom/events{/privacy}","received_events_url":"https://api.github.com/users/lenacom/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-11-13T09:46:19Z","updated_at":"2015-11-13T14:29:27Z","closed_at":null,"merged_at":null,"merge_commit_sha":"80dadcf05ce8dff39417116cc1a2c93f223c983f","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/CredoReference/edx-platform/pulls/1/commits","review_comments_url":"https://api.github.com/repos/CredoReference/edx-platform/pulls/1/comments","review_comment_url":"https://api.github.com/repos/CredoReference/edx-platform/pulls/comments{/number}","comments_url":"https://api.github.com/repos/CredoReference/edx-platform/issues/1/comments","statuses_url":"https://api.github.com/repos/CredoReference/edx-platform/statuses/e433086eb6348ef376953999ee134a45d943c990","head":{"label":"CredoReference:feature/edx-2","ref":"feature/edx-2","sha":"e433086eb6348ef376953999ee134a45d943c990","user":{"login":"CredoReference","id":15221069,"avatar_url":"https://avatars.githubusercontent.com/u/15221069?v=3","gravatar_id":"","url":"https://api.github.com/users/CredoReference","html_url":"https://github.com/CredoReference","followers_url":"https://api.github.com/users/CredoReference/followers","following_url":"https://api.github.com/users/CredoReference/following{/other_user}","gists_url":"https://api.github.com/users/CredoReference/gists{/gist_id}","starred_url":"https://api.github.com/users/CredoReference/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CredoReference/subscriptions","organizations_url":"https://api.github.com/users/CredoReference/orgs","repos_url":"https://api.github.com/users/CredoReference/repos","events_url":"https://api.github.com/users/CredoReference/events{/privacy}","received_events_url":"https://api.github.com/users/CredoReference/received_events","type":"Organization","site_admin":false},"repo":{"id":44635152,"name":"edx-platform","full_name":"CredoReference/edx-platform","owner":{"login":"CredoReference","id":15221069,"avatar_url":"https://avatars.githubusercontent.com/u/15221069?v=3","gravatar_id":"","url":"https://api.github.com/users/CredoReference","html_url":"https://github.com/CredoReference","followers_url":"https://api.github.com/users/CredoReference/followers","following_url":"https://api.github.com/users/CredoReference/following{/other_user}","gists_url":"https://api.github.com/users/CredoReference/gists{/gist_id}","starred_url":"https://api.github.com/users/CredoReference/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CredoReference/subscriptions","organizations_url":"https://api.github.com/users/CredoReference/orgs","repos_url":"https://api.github.com/users/CredoReference/repos","events_url":"https://api.github.com/users/CredoReference/events{/privacy}","received_events_url":"https://api.github.com/users/CredoReference/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/CredoReference/edx-platform","description":"The Open edX platform, the software that powers edX!","fork":true,"url":"https://api.github.com/repos/CredoReference/edx-platform","forks_url":"https://api.github.com/repos/CredoReference/edx-platform/forks","keys_url":"https://api.github.com/repos/CredoReference/edx-platform/keys{/key_id}","collaborators_url":"https://api.github.com/repos/CredoReference/edx-platform/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/CredoReference/edx-platform/teams","hooks_url":"https://api.github.com/repos/CredoReference/edx-platform/hooks","issue_events_url":"https://api.github.com/repos/CredoReference/edx-platform/issues/events{/number}","events_url":"https://api.github.com/repos/CredoReference/edx-platform/events","assignees_url":"https://api.github.com/repos/CredoReference/edx-platform/assignees{/user}","branches_url":"https://api.github.com/repos/CredoReference/edx-platform/branches{/branch}","tags_url":"https://api.github.com/repos/CredoReference/edx-platform/tags","blobs_url":"https://api.github.com/repos/CredoReference/edx-platform/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/CredoReference/edx-platform/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/CredoReference/edx-platform/git/refs{/sha}","trees_url":"https://api.github.com/repos/CredoReference/edx-platform/git/trees{/sha}","statuses_url":"https://api.github.com/repos/CredoReference/edx-platform/statuses/{sha}","languages_url":"https://api.github.com/repos/CredoReference/edx-platform/languages","stargazers_url":"https://api.github.com/repos/CredoReference/edx-platform/stargazers","contributors_url":"https://api.github.com/repos/CredoReference/edx-platform/contributors","subscribers_url":"https://api.github.com/repos/CredoReference/edx-platform/subscribers","subscription_url":"https://api.github.com/repos/CredoReference/edx-platform/subscription","commits_url":"https://api.github.com/repos/CredoReference/edx-platform/commits{/sha}","git_commits_url":"https://api.github.com/repos/CredoReference/edx-platform/git/commits{/sha}","comments_url":"https://api.github.com/repos/CredoReference/edx-platform/comments{/number}","issue_comment_url":"https://api.github.com/repos/CredoReference/edx-platform/issues/comments{/number}","contents_url":"https://api.github.com/repos/CredoReference/edx-platform/contents/{+path}","compare_url":"https://api.github.com/repos/CredoReference/edx-platform/compare/{base}...{head}","merges_url":"https://api.github.com/repos/CredoReference/edx-platform/merges","archive_url":"https://api.github.com/repos/CredoReference/edx-platform/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/CredoReference/edx-platform/downloads","issues_url":"https://api.github.com/repos/CredoReference/edx-platform/issues{/number}","pulls_url":"https://api.github.com/repos/CredoReference/edx-platform/pulls{/number}","milestones_url":"https://api.github.com/repos/CredoReference/edx-platform/milestones{/number}","notifications_url":"https://api.github.com/repos/CredoReference/edx-platform/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/CredoReference/edx-platform/labels{/name}","releases_url":"https://api.github.com/repos/CredoReference/edx-platform/releases{/id}","created_at":"2015-10-20T21:10:15Z","updated_at":"2015-10-20T21:11:16Z","pushed_at":"2015-11-13T10:05:40Z","git_url":"git://github.com/CredoReference/edx-platform.git","ssh_url":"git@github.com:CredoReference/edx-platform.git","clone_url":"https://github.com/CredoReference/edx-platform.git","svn_url":"https://github.com/CredoReference/edx-platform","homepage":"http://open.edx.org/","size":535931,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"CredoReference:master","ref":"master","sha":"5f528ddd16b50106dbb90c5a220e4c999d75701c","user":{"login":"CredoReference","id":15221069,"avatar_url":"https://avatars.githubusercontent.com/u/15221069?v=3","gravatar_id":"","url":"https://api.github.com/users/CredoReference","html_url":"https://github.com/CredoReference","followers_url":"https://api.github.com/users/CredoReference/followers","following_url":"https://api.github.com/users/CredoReference/following{/other_user}","gists_url":"https://api.github.com/users/CredoReference/gists{/gist_id}","starred_url":"https://api.github.com/users/CredoReference/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CredoReference/subscriptions","organizations_url":"https://api.github.com/users/CredoReference/orgs","repos_url":"https://api.github.com/users/CredoReference/repos","events_url":"https://api.github.com/users/CredoReference/events{/privacy}","received_events_url":"https://api.github.com/users/CredoReference/received_events","type":"Organization","site_admin":false},"repo":{"id":44635152,"name":"edx-platform","full_name":"CredoReference/edx-platform","owner":{"login":"CredoReference","id":15221069,"avatar_url":"https://avatars.githubusercontent.com/u/15221069?v=3","gravatar_id":"","url":"https://api.github.com/users/CredoReference","html_url":"https://github.com/CredoReference","followers_url":"https://api.github.com/users/CredoReference/followers","following_url":"https://api.github.com/users/CredoReference/following{/other_user}","gists_url":"https://api.github.com/users/CredoReference/gists{/gist_id}","starred_url":"https://api.github.com/users/CredoReference/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CredoReference/subscriptions","organizations_url":"https://api.github.com/users/CredoReference/orgs","repos_url":"https://api.github.com/users/CredoReference/repos","events_url":"https://api.github.com/users/CredoReference/events{/privacy}","received_events_url":"https://api.github.com/users/CredoReference/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/CredoReference/edx-platform","description":"The Open edX platform, the software that powers edX!","fork":true,"url":"https://api.github.com/repos/CredoReference/edx-platform","forks_url":"https://api.github.com/repos/CredoReference/edx-platform/forks","keys_url":"https://api.github.com/repos/CredoReference/edx-platform/keys{/key_id}","collaborators_url":"https://api.github.com/repos/CredoReference/edx-platform/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/CredoReference/edx-platform/teams","hooks_url":"https://api.github.com/repos/CredoReference/edx-platform/hooks","issue_events_url":"https://api.github.com/repos/CredoReference/edx-platform/issues/events{/number}","events_url":"https://api.github.com/repos/CredoReference/edx-platform/events","assignees_url":"https://api.github.com/repos/CredoReference/edx-platform/assignees{/user}","branches_url":"https://api.github.com/repos/CredoReference/edx-platform/branches{/branch}","tags_url":"https://api.github.com/repos/CredoReference/edx-platform/tags","blobs_url":"https://api.github.com/repos/CredoReference/edx-platform/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/CredoReference/edx-platform/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/CredoReference/edx-platform/git/refs{/sha}","trees_url":"https://api.github.com/repos/CredoReference/edx-platform/git/trees{/sha}","statuses_url":"https://api.github.com/repos/CredoReference/edx-platform/statuses/{sha}","languages_url":"https://api.github.com/repos/CredoReference/edx-platform/languages","stargazers_url":"https://api.github.com/repos/CredoReference/edx-platform/stargazers","contributors_url":"https://api.github.com/repos/CredoReference/edx-platform/contributors","subscribers_url":"https://api.github.com/repos/CredoReference/edx-platform/subscribers","subscription_url":"https://api.github.com/repos/CredoReference/edx-platform/subscription","commits_url":"https://api.github.com/repos/CredoReference/edx-platform/commits{/sha}","git_commits_url":"https://api.github.com/repos/CredoReference/edx-platform/git/commits{/sha}","comments_url":"https://api.github.com/repos/CredoReference/edx-platform/comments{/number}","issue_comment_url":"https://api.github.com/repos/CredoReference/edx-platform/issues/comments{/number}","contents_url":"https://api.github.com/repos/CredoReference/edx-platform/contents/{+path}","compare_url":"https://api.github.com/repos/CredoReference/edx-platform/compare/{base}...{head}","merges_url":"https://api.github.com/repos/CredoReference/edx-platform/merges","archive_url":"https://api.github.com/repos/CredoReference/edx-platform/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/CredoReference/edx-platform/downloads","issues_url":"https://api.github.com/repos/CredoReference/edx-platform/issues{/number}","pulls_url":"https://api.github.com/repos/CredoReference/edx-platform/pulls{/number}","milestones_url":"https://api.github.com/repos/CredoReference/edx-platform/milestones{/number}","notifications_url":"https://api.github.com/repos/CredoReference/edx-platform/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/CredoReference/edx-platform/labels{/name}","releases_url":"https://api.github.com/repos/CredoReference/edx-platform/releases{/id}","created_at":"2015-10-20T21:10:15Z","updated_at":"2015-10-20T21:11:16Z","pushed_at":"2015-11-13T10:05:40Z","git_url":"git://github.com/CredoReference/edx-platform.git","ssh_url":"git@github.com:CredoReference/edx-platform.git","clone_url":"https://github.com/CredoReference/edx-platform.git","svn_url":"https://github.com/CredoReference/edx-platform","homepage":"http://open.edx.org/","size":535931,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/CredoReference/edx-platform/pulls/1"},"html":{"href":"https://github.com/CredoReference/edx-platform/pull/1"},"issue":{"href":"https://api.github.com/repos/CredoReference/edx-platform/issues/1"},"comments":{"href":"https://api.github.com/repos/CredoReference/edx-platform/issues/1/comments"},"review_comments":{"href":"https://api.github.com/repos/CredoReference/edx-platform/pulls/1/comments"},"review_comment":{"href":"https://api.github.com/repos/CredoReference/edx-platform/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/CredoReference/edx-platform/pulls/1/commits"},"statuses":{"href":"https://api.github.com/repos/CredoReference/edx-platform/statuses/e433086eb6348ef376953999ee134a45d943c990"}}}}