{"action":"created","comment":{"url":"https://api.github.com/repos/matrix-org/matrix-react-sdk/pulls/comments/45371214","id":45371214,"diff_hunk":"@@ -1,16 +1,276 @@\n \"use strict\";\n var MatrixClientPeg = require(\"./MatrixClientPeg\");\n+var SignupStages = require(\"./SignupStages\");\n var dis = require(\"./dispatcher\");\n var q = require(\"q\");\n \n-class Register {\n+const EMAIL_STAGE_TYPE = \"m.login.email.identity\";\n \n-}\n-\n-class Login {\n+/**\n+ * A base class for common functionality between Registration and Login e.g.\n+ * storage of HS/IS URLs.\n+ */\n+class Signup {\n     constructor(hsUrl, isUrl) {\n         this._hsUrl = hsUrl;\n         this._isUrl = isUrl;\n+    }\n+\n+    getHomeserverUrl() {\n+        return this._hsUrl;\n+    }\n+\n+    getIdentityServerUrl() {\n+        return this._isUrl;\n+    }\n+\n+    setHomeserverUrl(hsUrl) {\n+        this._hsUrl = hsUrl;\n+    }\n+\n+    setIdentityServerUrl(isUrl) {\n+        this._isUrl = isUrl;\n+    }\n+}\n+\n+/**\n+ * Registration logic class\n+ */\n+class Register extends Signup {\n+    constructor(hsUrl, isUrl) {\n+        super(hsUrl, isUrl);\n+        this.setStep(\"START\");\n+        this.data = null; // from the server\n+        // random other stuff (e.g. query params, NOT params from the server)\n+        this.params = {};\n+        this.credentials = null;\n+        this.activeStage = null;\n+        this.registrationPromise = null;\n+        // These values MUST be undefined else we'll send \"username: null\" which\n+        // will error on Synapse rather than having the key absent.\n+        this.username = undefined; // desired\n+        this.email = undefined; // desired\n+        this.password = undefined; // desired\n+    }\n+\n+    setClientSecret(secret) {\n+        this.params.clientSecret = secret;\n+    }\n+\n+    setSessionId(sessionId) {\n+        this.params.sessionId = sessionId;\n+    }\n+\n+    setRegistrationUrl(regUrl) {\n+        this.params.registrationUrl = regUrl;\n+    }\n+\n+    setIdSid(idSid) {\n+        this.params.idSid = idSid;\n+    }\n+\n+    getStep() {\n+        return this._step;\n+    }\n+\n+    getCredentials() {\n+        return this.credentials;\n+    }\n+\n+    getServerData() {\n+        return this.data || {};\n+    }\n+\n+    getPromise() {\n+        return this.registrationPromise;\n+    }\n+\n+    setStep(step) {\n+        this._step = 'Register.' + step;\n+        // TODO:\n+        // It's a shame this is going to the global dispatcher, we only really\n+        // want things which have an instance of this class to be able to add\n+        // listeners...\n+        console.log(\"Dispatching 'registration_step_update' for step %s\", this._step);","path":"src/Signup.js","position":98,"original_position":98,"commit_id":"23467de016463aa0e94c69862f71c75985fca62b","original_commit_id":"23467de016463aa0e94c69862f71c75985fca62b","user":{"login":"dbkr","id":986903,"avatar_url":"https://avatars.githubusercontent.com/u/986903?v=3","gravatar_id":"","url":"https://api.github.com/users/dbkr","html_url":"https://github.com/dbkr","followers_url":"https://api.github.com/users/dbkr/followers","following_url":"https://api.github.com/users/dbkr/following{/other_user}","gists_url":"https://api.github.com/users/dbkr/gists{/gist_id}","starred_url":"https://api.github.com/users/dbkr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dbkr/subscriptions","organizations_url":"https://api.github.com/users/dbkr/orgs","repos_url":"https://api.github.com/users/dbkr/repos","events_url":"https://api.github.com/users/dbkr/events{/privacy}","received_events_url":"https://api.github.com/users/dbkr/received_events","type":"User","site_admin":false},"body":"Was the console.log left in intentionally?","created_at":"2015-11-19T17:20:57Z","updated_at":"2015-11-19T17:20:57Z","html_url":"https://github.com/matrix-org/matrix-react-sdk/pull/34#discussion_r45371214","pull_request_url":"https://api.github.com/repos/matrix-org/matrix-react-sdk/pulls/34","_links":{"self":{"href":"https://api.github.com/repos/matrix-org/matrix-react-sdk/pulls/comments/45371214"},"html":{"href":"https://github.com/matrix-org/matrix-react-sdk/pull/34#discussion_r45371214"},"pull_request":{"href":"https://api.github.com/repos/matrix-org/matrix-react-sdk/pulls/34"}}},"pull_request":{"url":"https://api.github.com/repos/matrix-org/matrix-react-sdk/pulls/34","id":51244520,"html_url":"https://github.com/matrix-org/matrix-react-sdk/pull/34","diff_url":"https://github.com/matrix-org/matrix-react-sdk/pull/34.diff","patch_url":"https://github.com/matrix-org/matrix-react-sdk/pull/34.patch","issue_url":"https://api.github.com/repos/matrix-org/matrix-react-sdk/issues/34","number":34,"state":"open","locked":false,"title":"Refactor registration","user":{"login":"Kegsay","id":7190048,"avatar_url":"https://avatars.githubusercontent.com/u/7190048?v=3","gravatar_id":"","url":"https://api.github.com/users/Kegsay","html_url":"https://github.com/Kegsay","followers_url":"https://api.github.com/users/Kegsay/followers","following_url":"https://api.github.com/users/Kegsay/following{/other_user}","gists_url":"https://api.github.com/users/Kegsay/gists{/gist_id}","starred_url":"https://api.github.com/users/Kegsay/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Kegsay/subscriptions","organizations_url":"https://api.github.com/users/Kegsay/orgs","repos_url":"https://api.github.com/users/Kegsay/repos","events_url":"https://api.github.com/users/Kegsay/events{/privacy}","received_events_url":"https://api.github.com/users/Kegsay/received_events","type":"User","site_admin":false},"body":"This PR refactors Registration logic. It also unbreaks the world by allowing people to register without an email address.\r\n\r\nAn overview of the changes are:\r\n - Add a `Signup` class to serve as a base class for `Register` and `Login` to share common code like setting/getting HS/IS URLs. This can be expanded more in another PR (we can share more code).\r\n - Migrate logic which was in the `Register` controller to the `Signup.Register` class. Trim off unused functions. This class has no real knowledge of how to handle a particular stage (except when email comes into play, there is very limited knowledge of how email is handled).\r\n - Add a `SignupStages` file which has classes for each kind of `m.login.*` that React SDK recognises. These classes contain the logic for handling that particular stage. They all follow the same interface outlined in the `Stage` class. Primarily the API is `complete() => Promise` which resolves to the \"auth dictionary\" to send to the HS. This list is currently:\r\n  * `m.login.email.identity` - Handles client secret generation, crafting the redirect URL, requesting the token from the IS, returning the auth dict for verification post-redirect.\r\n  * `m.login.recaptcha` - Handles rendering to the global `grecaptcha`. Extracts public key from the server response. Returns an auth dict with the recaptcha response.\r\n  * `m.login.dummy` - Nothing, returns an empty auth dict with the right type as per spec.\r\n\r\nSee also: https://github.com/vector-im/vector-web/pull/399","created_at":"2015-11-19T16:21:10Z","updated_at":"2015-11-19T17:20:57Z","closed_at":null,"merged_at":null,"merge_commit_sha":"92f78a6e387617bec7c7f57f25c237b86e7beeff","assignee":{"login":"dbkr","id":986903,"avatar_url":"https://avatars.githubusercontent.com/u/986903?v=3","gravatar_id":"","url":"https://api.github.com/users/dbkr","html_url":"https://github.com/dbkr","followers_url":"https://api.github.com/users/dbkr/followers","following_url":"https://api.github.com/users/dbkr/following{/other_user}","gists_url":"https://api.github.com/users/dbkr/gists{/gist_id}","starred_url":"https://api.github.com/users/dbkr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dbkr/subscriptions","organizations_url":"https://api.github.com/users/dbkr/orgs","repos_url":"https://api.github.com/users/dbkr/repos","events_url":"https://api.github.com/users/dbkr/events{/privacy}","received_events_url":"https://api.github.com/users/dbkr/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/matrix-org/matrix-react-sdk/pulls/34/commits","review_comments_url":"https://api.github.com/repos/matrix-org/matrix-react-sdk/pulls/34/comments","review_comment_url":"https://api.github.com/repos/matrix-org/matrix-react-sdk/pulls/comments{/number}","comments_url":"https://api.github.com/repos/matrix-org/matrix-react-sdk/issues/34/comments","statuses_url":"https://api.github.com/repos/matrix-org/matrix-react-sdk/statuses/23467de016463aa0e94c69862f71c75985fca62b","head":{"label":"matrix-org:kegan/reg-refactor","ref":"kegan/reg-refactor","sha":"23467de016463aa0e94c69862f71c75985fca62b","user":{"login":"matrix-org","id":8418310,"avatar_url":"https://avatars.githubusercontent.com/u/8418310?v=3","gravatar_id":"","url":"https://api.github.com/users/matrix-org","html_url":"https://github.com/matrix-org","followers_url":"https://api.github.com/users/matrix-org/followers","following_url":"https://api.github.com/users/matrix-org/following{/other_user}","gists_url":"https://api.github.com/users/matrix-org/gists{/gist_id}","starred_url":"https://api.github.com/users/matrix-org/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/matrix-org/subscriptions","organizations_url":"https://api.github.com/users/matrix-org/orgs","repos_url":"https://api.github.com/users/matrix-org/repos","events_url":"https://api.github.com/users/matrix-org/events{/privacy}","received_events_url":"https://api.github.com/users/matrix-org/received_events","type":"Organization","site_admin":false},"repo":{"id":37144575,"name":"matrix-react-sdk","full_name":"matrix-org/matrix-react-sdk","owner":{"login":"matrix-org","id":8418310,"avatar_url":"https://avatars.githubusercontent.com/u/8418310?v=3","gravatar_id":"","url":"https://api.github.com/users/matrix-org","html_url":"https://github.com/matrix-org","followers_url":"https://api.github.com/users/matrix-org/followers","following_url":"https://api.github.com/users/matrix-org/following{/other_user}","gists_url":"https://api.github.com/users/matrix-org/gists{/gist_id}","starred_url":"https://api.github.com/users/matrix-org/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/matrix-org/subscriptions","organizations_url":"https://api.github.com/users/matrix-org/orgs","repos_url":"https://api.github.com/users/matrix-org/repos","events_url":"https://api.github.com/users/matrix-org/events{/privacy}","received_events_url":"https://api.github.com/users/matrix-org/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/matrix-org/matrix-react-sdk","description":"Matrix SDK for React Javascript","fork":false,"url":"https://api.github.com/repos/matrix-org/matrix-react-sdk","forks_url":"https://api.github.com/repos/matrix-org/matrix-react-sdk/forks","keys_url":"https://api.github.com/repos/matrix-org/matrix-react-sdk/keys{/key_id}","collaborators_url":"https://api.github.com/repos/matrix-org/matrix-react-sdk/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/matrix-org/matrix-react-sdk/teams","hooks_url":"https://api.github.com/repos/matrix-org/matrix-react-sdk/hooks","issue_events_url":"https://api.github.com/repos/matrix-org/matrix-react-sdk/issues/events{/number}","events_url":"https://api.github.com/repos/matrix-org/matrix-react-sdk/events","assignees_url":"https://api.github.com/repos/matrix-org/matrix-react-sdk/assignees{/user}","branches_url":"https://api.github.com/repos/matrix-org/matrix-react-sdk/branches{/branch}","tags_url":"https://api.github.com/repos/matrix-org/matrix-react-sdk/tags","blobs_url":"https://api.github.com/repos/matrix-org/matrix-react-sdk/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/matrix-org/matrix-react-sdk/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/matrix-org/matrix-react-sdk/git/refs{/sha}","trees_url":"https://api.github.com/repos/matrix-org/matrix-react-sdk/git/trees{/sha}","statuses_url":"https://api.github.com/repos/matrix-org/matrix-react-sdk/statuses/{sha}","languages_url":"https://api.github.com/repos/matrix-org/matrix-react-sdk/languages","stargazers_url":"https://api.github.com/repos/matrix-org/matrix-react-sdk/stargazers","contributors_url":"https://api.github.com/repos/matrix-org/matrix-react-sdk/contributors","subscribers_url":"https://api.github.com/repos/matrix-org/matrix-react-sdk/subscribers","subscription_url":"https://api.github.com/repos/matrix-org/matrix-react-sdk/subscription","commits_url":"https://api.github.com/repos/matrix-org/matrix-react-sdk/commits{/sha}","git_commits_url":"https://api.github.com/repos/matrix-org/matrix-react-sdk/git/commits{/sha}","comments_url":"https://api.github.com/repos/matrix-org/matrix-react-sdk/comments{/number}","issue_comment_url":"https://api.github.com/repos/matrix-org/matrix-react-sdk/issues/comments{/number}","contents_url":"https://api.github.com/repos/matrix-org/matrix-react-sdk/contents/{+path}","compare_url":"https://api.github.com/repos/matrix-org/matrix-react-sdk/compare/{base}...{head}","merges_url":"https://api.github.com/repos/matrix-org/matrix-react-sdk/merges","archive_url":"https://api.github.com/repos/matrix-org/matrix-react-sdk/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/matrix-org/matrix-react-sdk/downloads","issues_url":"https://api.github.com/repos/matrix-org/matrix-react-sdk/issues{/number}","pulls_url":"https://api.github.com/repos/matrix-org/matrix-react-sdk/pulls{/number}","milestones_url":"https://api.github.com/repos/matrix-org/matrix-react-sdk/milestones{/number}","notifications_url":"https://api.github.com/repos/matrix-org/matrix-react-sdk/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/matrix-org/matrix-react-sdk/labels{/name}","releases_url":"https://api.github.com/repos/matrix-org/matrix-react-sdk/releases{/id}","created_at":"2015-06-09T16:37:07Z","updated_at":"2015-11-09T19:19:16Z","pushed_at":"2015-11-19T16:47:31Z","git_url":"git://github.com/matrix-org/matrix-react-sdk.git","ssh_url":"git@github.com:matrix-org/matrix-react-sdk.git","clone_url":"https://github.com/matrix-org/matrix-react-sdk.git","svn_url":"https://github.com/matrix-org/matrix-react-sdk","homepage":null,"size":915,"stargazers_count":7,"watchers_count":7,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":5,"mirror_url":null,"open_issues_count":3,"forks":5,"open_issues":3,"watchers":7,"default_branch":"master"}},"base":{"label":"matrix-org:develop","ref":"develop","sha":"caabe02fca8c2fe44cfe13360b3139784e1ace7f","user":{"login":"matrix-org","id":8418310,"avatar_url":"https://avatars.githubusercontent.com/u/8418310?v=3","gravatar_id":"","url":"https://api.github.com/users/matrix-org","html_url":"https://github.com/matrix-org","followers_url":"https://api.github.com/users/matrix-org/followers","following_url":"https://api.github.com/users/matrix-org/following{/other_user}","gists_url":"https://api.github.com/users/matrix-org/gists{/gist_id}","starred_url":"https://api.github.com/users/matrix-org/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/matrix-org/subscriptions","organizations_url":"https://api.github.com/users/matrix-org/orgs","repos_url":"https://api.github.com/users/matrix-org/repos","events_url":"https://api.github.com/users/matrix-org/events{/privacy}","received_events_url":"https://api.github.com/users/matrix-org/received_events","type":"Organization","site_admin":false},"repo":{"id":37144575,"name":"matrix-react-sdk","full_name":"matrix-org/matrix-react-sdk","owner":{"login":"matrix-org","id":8418310,"avatar_url":"https://avatars.githubusercontent.com/u/8418310?v=3","gravatar_id":"","url":"https://api.github.com/users/matrix-org","html_url":"https://github.com/matrix-org","followers_url":"https://api.github.com/users/matrix-org/followers","following_url":"https://api.github.com/users/matrix-org/following{/other_user}","gists_url":"https://api.github.com/users/matrix-org/gists{/gist_id}","starred_url":"https://api.github.com/users/matrix-org/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/matrix-org/subscriptions","organizations_url":"https://api.github.com/users/matrix-org/orgs","repos_url":"https://api.github.com/users/matrix-org/repos","events_url":"https://api.github.com/users/matrix-org/events{/privacy}","received_events_url":"https://api.github.com/users/matrix-org/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/matrix-org/matrix-react-sdk","description":"Matrix SDK for React Javascript","fork":false,"url":"https://api.github.com/repos/matrix-org/matrix-react-sdk","forks_url":"https://api.github.com/repos/matrix-org/matrix-react-sdk/forks","keys_url":"https://api.github.com/repos/matrix-org/matrix-react-sdk/keys{/key_id}","collaborators_url":"https://api.github.com/repos/matrix-org/matrix-react-sdk/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/matrix-org/matrix-react-sdk/teams","hooks_url":"https://api.github.com/repos/matrix-org/matrix-react-sdk/hooks","issue_events_url":"https://api.github.com/repos/matrix-org/matrix-react-sdk/issues/events{/number}","events_url":"https://api.github.com/repos/matrix-org/matrix-react-sdk/events","assignees_url":"https://api.github.com/repos/matrix-org/matrix-react-sdk/assignees{/user}","branches_url":"https://api.github.com/repos/matrix-org/matrix-react-sdk/branches{/branch}","tags_url":"https://api.github.com/repos/matrix-org/matrix-react-sdk/tags","blobs_url":"https://api.github.com/repos/matrix-org/matrix-react-sdk/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/matrix-org/matrix-react-sdk/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/matrix-org/matrix-react-sdk/git/refs{/sha}","trees_url":"https://api.github.com/repos/matrix-org/matrix-react-sdk/git/trees{/sha}","statuses_url":"https://api.github.com/repos/matrix-org/matrix-react-sdk/statuses/{sha}","languages_url":"https://api.github.com/repos/matrix-org/matrix-react-sdk/languages","stargazers_url":"https://api.github.com/repos/matrix-org/matrix-react-sdk/stargazers","contributors_url":"https://api.github.com/repos/matrix-org/matrix-react-sdk/contributors","subscribers_url":"https://api.github.com/repos/matrix-org/matrix-react-sdk/subscribers","subscription_url":"https://api.github.com/repos/matrix-org/matrix-react-sdk/subscription","commits_url":"https://api.github.com/repos/matrix-org/matrix-react-sdk/commits{/sha}","git_commits_url":"https://api.github.com/repos/matrix-org/matrix-react-sdk/git/commits{/sha}","comments_url":"https://api.github.com/repos/matrix-org/matrix-react-sdk/comments{/number}","issue_comment_url":"https://api.github.com/repos/matrix-org/matrix-react-sdk/issues/comments{/number}","contents_url":"https://api.github.com/repos/matrix-org/matrix-react-sdk/contents/{+path}","compare_url":"https://api.github.com/repos/matrix-org/matrix-react-sdk/compare/{base}...{head}","merges_url":"https://api.github.com/repos/matrix-org/matrix-react-sdk/merges","archive_url":"https://api.github.com/repos/matrix-org/matrix-react-sdk/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/matrix-org/matrix-react-sdk/downloads","issues_url":"https://api.github.com/repos/matrix-org/matrix-react-sdk/issues{/number}","pulls_url":"https://api.github.com/repos/matrix-org/matrix-react-sdk/pulls{/number}","milestones_url":"https://api.github.com/repos/matrix-org/matrix-react-sdk/milestones{/number}","notifications_url":"https://api.github.com/repos/matrix-org/matrix-react-sdk/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/matrix-org/matrix-react-sdk/labels{/name}","releases_url":"https://api.github.com/repos/matrix-org/matrix-react-sdk/releases{/id}","created_at":"2015-06-09T16:37:07Z","updated_at":"2015-11-09T19:19:16Z","pushed_at":"2015-11-19T16:47:31Z","git_url":"git://github.com/matrix-org/matrix-react-sdk.git","ssh_url":"git@github.com:matrix-org/matrix-react-sdk.git","clone_url":"https://github.com/matrix-org/matrix-react-sdk.git","svn_url":"https://github.com/matrix-org/matrix-react-sdk","homepage":null,"size":915,"stargazers_count":7,"watchers_count":7,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":5,"mirror_url":null,"open_issues_count":3,"forks":5,"open_issues":3,"watchers":7,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/matrix-org/matrix-react-sdk/pulls/34"},"html":{"href":"https://github.com/matrix-org/matrix-react-sdk/pull/34"},"issue":{"href":"https://api.github.com/repos/matrix-org/matrix-react-sdk/issues/34"},"comments":{"href":"https://api.github.com/repos/matrix-org/matrix-react-sdk/issues/34/comments"},"review_comments":{"href":"https://api.github.com/repos/matrix-org/matrix-react-sdk/pulls/34/comments"},"review_comment":{"href":"https://api.github.com/repos/matrix-org/matrix-react-sdk/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/matrix-org/matrix-react-sdk/pulls/34/commits"},"statuses":{"href":"https://api.github.com/repos/matrix-org/matrix-react-sdk/statuses/23467de016463aa0e94c69862f71c75985fca62b"}}}}