From 413bcddb1ed4a419f26b63955351e80ee7cbe140 Mon Sep 17 00:00:00 2001
From: Garret Alfert
Date: Fri, 26 Jul 2019 03:38:18 +0200
Subject: [PATCH] Wire up signup via Github
---
app/controllers/signup/eth-account.js | 33 ++++++++++++++++++--
app/controllers/signup/index.js | 14 +++++++++
app/router.js | 1 +
app/routes/signup/eth-account.js | 13 ++++++++
app/routes/signup/github.js | 18 +++++++++++
app/services/kredits.js | 1 +
app/templates/signup/index.hbs | 4 +--
config/environment.js | 6 ++++
package-lock.json | 45 ++++++++-------------------
9 files changed, 99 insertions(+), 36 deletions(-)
create mode 100644 app/controllers/signup/index.js
create mode 100644 app/routes/signup/github.js
diff --git a/app/controllers/signup/eth-account.js b/app/controllers/signup/eth-account.js
index 199323d..d1a8bcf 100644
--- a/app/controllers/signup/eth-account.js
+++ b/app/controllers/signup/eth-account.js
@@ -1,11 +1,16 @@
import Controller from '@ember/controller';
import { computed } from '@ember/object';
-import { not } from '@ember/object/computed';
+import { alias, not } from '@ember/object/computed';
import { isAddress } from 'web3-utils';
+import { inject as service } from '@ember/service';
+import config from 'kredits-web/config/environment';
export default Controller.extend({
+ kredits: service(),
+
ethAddress: null,
+ githubAccessToken: alias('kredits.githubAccessToken'),
isValidEthAccount: computed('ethAddress', function() {
return isAddress(this.ethAddress);
@@ -15,7 +20,31 @@ export default Controller.extend({
actions: {
- completeSignup() {
+ completeSignup () {
+ const payload = {
+ accessToken: this.githubAccessToken,
+ account: this.ethAddress
+ }
+
+ fetch(config.githubSignupUrl, {
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/json'
+ },
+ body: JSON.stringify(payload)
+ }).then(response => {
+ return response.json();
+ })
+ .then(data => {
+ console.log('Created contributor:', data);
+
+ this.setProperties({
+ githubAccessToken: null,
+ ethAddress: null
+ });
+
+ // TODO show success message or transition to success page
+ });
}
}
diff --git a/app/controllers/signup/index.js b/app/controllers/signup/index.js
new file mode 100644
index 0000000..d90035c
--- /dev/null
+++ b/app/controllers/signup/index.js
@@ -0,0 +1,14 @@
+import Controller from '@ember/controller';
+import config from 'kredits-web/config/environment';
+
+export default Controller.extend({
+
+ actions: {
+
+ connectGithub () {
+ window.location = config.githubConnectUrl;
+ }
+
+ }
+
+});
diff --git a/app/router.js b/app/router.js
index 839c8c1..61cc122 100644
--- a/app/router.js
+++ b/app/router.js
@@ -27,6 +27,7 @@ Router.map(function() {
this.route('edit', { path: ':id/edit' });
});
this.route('signup', function() {
+ this.route('github');
this.route('eth-account');
});
});
diff --git a/app/routes/signup/eth-account.js b/app/routes/signup/eth-account.js
index 6c74252..078a109 100644
--- a/app/routes/signup/eth-account.js
+++ b/app/routes/signup/eth-account.js
@@ -1,4 +1,17 @@
import Route from '@ember/routing/route';
+import { inject as service } from '@ember/service';
+import { isEmpty } from '@ember/utils';
export default Route.extend({
+
+ kredits: service(),
+
+ redirect () {
+ this._super(...arguments);
+
+ if (isEmpty(this.kredits.githubAccessToken)) {
+ this.transitionTo('signup.index');
+ }
+ }
+
});
diff --git a/app/routes/signup/github.js b/app/routes/signup/github.js
new file mode 100644
index 0000000..969dc55
--- /dev/null
+++ b/app/routes/signup/github.js
@@ -0,0 +1,18 @@
+import Route from '@ember/routing/route';
+import { inject as service } from '@ember/service';
+
+export default Route.extend({
+
+ kredits: service(),
+
+ redirect () {
+ this._super(...arguments);
+
+ const accessToken = window.location.hash.match(/access_token=(.+)/)[1];
+ this.kredits.set('githubAccessToken', accessToken);
+
+ this.transitionTo('signup.eth-account');
+ }
+
+});
+
diff --git a/app/services/kredits.js b/app/services/kredits.js
index e31e714..a1b9ec2 100644
--- a/app/services/kredits.js
+++ b/app/services/kredits.js
@@ -24,6 +24,7 @@ export default Service.extend({
contributors: null,
contributions: null,
proposals: null,
+ githubAccessToken: null,
currentUserIsContributor: notEmpty('currentUser'),
currentUserIsCore: alias('currentUser.isCore'),
diff --git a/app/templates/signup/index.hbs b/app/templates/signup/index.hbs
index f57768b..a8ad30f 100644
--- a/app/templates/signup/index.hbs
+++ b/app/templates/signup/index.hbs
@@ -8,8 +8,8 @@
connecting one of the following accounts:
- {{#link-to "signup.eth-account" class="button icon"}}
+
diff --git a/config/environment.js b/config/environment.js
index 1004b33..d1ae6e7 100644
--- a/config/environment.js
+++ b/config/environment.js
@@ -37,6 +37,9 @@ module.exports = function(environment) {
web3ProviderUrl: 'https://rinkeby.infura.io/v3/d4f788b7a6584f7db2fc3c268d4d09e9',
+ githubConnectUrl: 'https://hal8000.chat.kosmos.org:8082/kredits/signup/connect/github',
+ githubSignupUrl: 'https://hal8000.chat.kosmos.org:8082/kredits/signup/github',
+
ipfs: {
host: 'ipfs.kosmos.org',
port: '5444',
@@ -53,6 +56,9 @@ module.exports = function(environment) {
// ENV.APP.LOG_VIEW_LOOKUPS = true;
ENV.web3ProviderUrl = 'https://rinkeby.infura.io/v3/d4f788b7a6584f7db2fc3c268d4d09e9';
+ ENV.githubConnectUrl = 'http://localhost:8888/kredits/signup/connect/github';
+ ENV.githubSignupUrl = 'http://localhost:8888/kredits/signup/github';
+
ENV.ipfs = {
host: 'localhost',
port: '5001',
diff --git a/package-lock.json b/package-lock.json
index 849e839..81bacd8 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -9429,8 +9429,7 @@
"ansi-regex": {
"version": "2.1.1",
"bundled": true,
- "dev": true,
- "optional": true
+ "dev": true
},
"aproba": {
"version": "1.2.0",
@@ -9451,14 +9450,12 @@
"balanced-match": {
"version": "1.0.0",
"bundled": true,
- "dev": true,
- "optional": true
+ "dev": true
},
"brace-expansion": {
"version": "1.1.11",
"bundled": true,
"dev": true,
- "optional": true,
"requires": {
"balanced-match": "^1.0.0",
"concat-map": "0.0.1"
@@ -9473,20 +9470,17 @@
"code-point-at": {
"version": "1.1.0",
"bundled": true,
- "dev": true,
- "optional": true
+ "dev": true
},
"concat-map": {
"version": "0.0.1",
"bundled": true,
- "dev": true,
- "optional": true
+ "dev": true
},
"console-control-strings": {
"version": "1.1.0",
"bundled": true,
- "dev": true,
- "optional": true
+ "dev": true
},
"core-util-is": {
"version": "1.0.2",
@@ -9603,8 +9597,7 @@
"inherits": {
"version": "2.0.3",
"bundled": true,
- "dev": true,
- "optional": true
+ "dev": true
},
"ini": {
"version": "1.3.5",
@@ -9616,7 +9609,6 @@
"version": "1.0.0",
"bundled": true,
"dev": true,
- "optional": true,
"requires": {
"number-is-nan": "^1.0.0"
}
@@ -9631,7 +9623,6 @@
"version": "3.0.4",
"bundled": true,
"dev": true,
- "optional": true,
"requires": {
"brace-expansion": "^1.1.7"
}
@@ -9639,14 +9630,12 @@
"minimist": {
"version": "0.0.8",
"bundled": true,
- "dev": true,
- "optional": true
+ "dev": true
},
"minipass": {
"version": "2.3.5",
"bundled": true,
"dev": true,
- "optional": true,
"requires": {
"safe-buffer": "^5.1.2",
"yallist": "^3.0.0"
@@ -9665,7 +9654,6 @@
"version": "0.5.1",
"bundled": true,
"dev": true,
- "optional": true,
"requires": {
"minimist": "0.0.8"
}
@@ -9746,8 +9734,7 @@
"number-is-nan": {
"version": "1.0.1",
"bundled": true,
- "dev": true,
- "optional": true
+ "dev": true
},
"object-assign": {
"version": "4.1.1",
@@ -9759,7 +9746,6 @@
"version": "1.4.0",
"bundled": true,
"dev": true,
- "optional": true,
"requires": {
"wrappy": "1"
}
@@ -9845,8 +9831,7 @@
"safe-buffer": {
"version": "5.1.2",
"bundled": true,
- "dev": true,
- "optional": true
+ "dev": true
},
"safer-buffer": {
"version": "2.1.2",
@@ -9882,7 +9867,6 @@
"version": "1.0.2",
"bundled": true,
"dev": true,
- "optional": true,
"requires": {
"code-point-at": "^1.0.0",
"is-fullwidth-code-point": "^1.0.0",
@@ -9902,7 +9886,6 @@
"version": "3.0.1",
"bundled": true,
"dev": true,
- "optional": true,
"requires": {
"ansi-regex": "^2.0.0"
}
@@ -9946,14 +9929,12 @@
"wrappy": {
"version": "1.0.2",
"bundled": true,
- "dev": true,
- "optional": true
+ "dev": true
},
"yallist": {
"version": "3.0.3",
"bundled": true,
- "dev": true,
- "optional": true
+ "dev": true
}
}
},
@@ -10883,7 +10864,7 @@
"bs58": "^4.0.1",
"buffer": "^5.2.1",
"cids": "~0.5.5",
- "concat-stream": "github:hugomrdias/concat-stream#feat/smaller",
+ "concat-stream": "github:hugomrdias/concat-stream#057bc7b5d6d8df26c8cf00a3f151b6721a0a8034",
"debug": "^4.1.0",
"detect-node": "^2.0.4",
"end-of-stream": "^1.4.1",
@@ -10905,7 +10886,7 @@
"multibase": "~0.6.0",
"multicodec": "~0.5.0",
"multihashes": "~0.4.14",
- "ndjson": "github:hugomrdias/ndjson#feat/readable-stream3",
+ "ndjson": "github:hugomrdias/ndjson#4db16da6b42e5b39bf300c3a7cde62abb3fa3a11",
"once": "^1.4.0",
"peer-id": "~0.12.2",
"peer-info": "~0.15.1",