Wire up signup via Github

This commit is contained in:
2019-07-26 03:38:18 +02:00
parent c2273d1778
commit 413bcddb1e
9 changed files with 99 additions and 36 deletions
+31 -2
View File
@@ -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
});
}
}
+14
View File
@@ -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;
}
}
});
+1
View File
@@ -27,6 +27,7 @@ Router.map(function() {
this.route('edit', { path: ':id/edit' });
});
this.route('signup', function() {
this.route('github');
this.route('eth-account');
});
});
+13
View File
@@ -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');
}
}
});
+18
View File
@@ -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');
}
});
+1
View File
@@ -24,6 +24,7 @@ export default Service.extend({
contributors: null,
contributions: null,
proposals: null,
githubAccessToken: null,
currentUserIsContributor: notEmpty('currentUser'),
currentUserIsCore: alias('currentUser.isCore'),
+2 -2
View File
@@ -8,8 +8,8 @@
connecting one of the following accounts:
</p>
<p class="actions">
{{#link-to "signup.eth-account" class="button icon"}}
<button {{action "connectGithub"}} class="icon">
{{icon-account-github-com}}
Connect GitHub
{{/link-to}}
</button>
</p>