From 6649c61c40fbb45ea92890941f846901b4f5f6e4 Mon Sep 17 00:00:00 2001 From: Andy Haden Date: Fri, 30 Jun 2017 21:27:04 -0700 Subject: [PATCH] cabana: login with github on modals --- server.py | 9 +++------ src/CanExplorer.js | 10 +++++++++- src/components/LoadDbcModal.js | 5 +++-- src/components/SaveDbcModal.js | 8 ++++++-- src/components/meta.js | 5 +++-- src/config.js | 2 +- 6 files changed, 25 insertions(+), 14 deletions(-) diff --git a/server.py b/server.py index f5b790b..22166d8 100644 --- a/server.py +++ b/server.py @@ -2,8 +2,8 @@ from flask import Flask, request, redirect import requests import json -CLIENT_ID = '4b43250e7499a97d62a5' -CLIENT_SECRET = '65dbd43f3e298e024a7aff85b2a9ed261ffc9fcf' +CLIENT_ID = 'f1e42d14f45491f9ca34' +CLIENT_SECRET = 'f50f7a6dd6b0364b0761f35367f0be7027e7caa1' OAUTH_STATES = [] app = Flask(__name__) @@ -16,9 +16,6 @@ def auth_state(): @app.route('/callback') def callback(): - CLIENT_ID = '4b43250e7499a97d62a5' - CLIENT_SECRET = '65dbd43f3e298e024a7aff85b2a9ed261ffc9fcf' - code = request.args.get('code') state = request.args.get('state') @@ -34,7 +31,7 @@ def callback(): route = json.loads(state)['route'] - return redirect('https://community.comma.ai/cabana/?route={}&gh_access_token={}'.format(route, oauth_resp['access_token'])) + return redirect('http://127.0.0.1:3000/?route={}&gh_access_token={}'.format(route, oauth_resp['access_token'])) if __name__ == '__main__': app.run(port=1235) diff --git a/src/CanExplorer.js b/src/CanExplorer.js index 200453b..046e546 100644 --- a/src/CanExplorer.js +++ b/src/CanExplorer.js @@ -322,6 +322,10 @@ export default class CanExplorer extends Component { this.setState({selectedMessage: null}); } + loginWithGithub() { + return Log in with Github + } + render() { return (
{this.state.isLoading ? @@ -347,6 +351,7 @@ export default class CanExplorer extends Component { seekTime={this.state.seekTime} maxByteStateChangeCount={this.state.maxByteStateChangeCount} githubAuthToken={this.props.githubAuthToken} + loginWithGithub={this.loginWithGithub()} />
{this.state.route.url ? @@ -372,13 +377,16 @@ export default class CanExplorer extends Component { onDbcSelected={this.onDbcSelected} onCancel={this.hideLoadDbc} openDbcClient={this.openDbcClient} + loginWithGithub={this.loginWithGithub()} /> : null} {this.state.showSaveDbc ? : null} + openDbcClient={this.openDbcClient} + hasGithubAuth={this.props.githubAuthToken !== null} + loginWithGithub={this.loginWithGithub()} /> : null} {this.state.showEditMessageModal ? ); } else if(tab === 'GitHub') { if(!this.props.openDbcClient.hasAuth()) { - return (
Need to auth
); + return (
{this.props.loginWithGithub}
); } else if(this.state.userOpenDbcRepo === null) { return (
Fork it
); } else { diff --git a/src/components/SaveDbcModal.js b/src/components/SaveDbcModal.js index b48ae5d..ae4bd80 100644 --- a/src/components/SaveDbcModal.js +++ b/src/components/SaveDbcModal.js @@ -14,7 +14,9 @@ export default class SaveDbcModal extends Component { sourceDbcFilename: PropTypes.string.isRequired, onCancel: PropTypes.func.isRequired, onDbcSaved: PropTypes.func.isRequired, - openDbcClient: PropTypes.instanceOf(OpenDbc).isRequired + openDbcClient: PropTypes.instanceOf(OpenDbc).isRequired, + hasGithubAuth: PropTypes.bool.isRequired, + loginWithGithub: PropTypes.element.isRequired }; constructor(props) { @@ -84,9 +86,11 @@ export default class SaveDbcModal extends Component { let content; if(openDbcFork !== null) { content =

Done! {openDbcFork}

; - } else { + } else if(this.props.hasGithubAuth) { content =

Fork OpenDBC

; + } else { + content = this.props.loginWithGithub; } return (
{openDbcFork !== null ?

Fork OpenDBC

: null} diff --git a/src/components/meta.js b/src/components/meta.js index 552bad2..df3c9fe 100644 --- a/src/components/meta.js +++ b/src/components/meta.js @@ -26,7 +26,8 @@ export default class Meta extends Component { route: PropTypes.object, partsLoaded: PropTypes.number, currentParts: PropTypes.array, - seekTime: PropTypes.number + seekTime: PropTypes.number, + loginWithGithub: PropTypes.element, }; constructor(props) { @@ -296,7 +297,7 @@ export default class Meta extends Component { {this.props.githubAuthToken ?

GitHub Authenticated

: - Log in with Github + this.props.loginWithGithub }
diff --git a/src/config.js b/src/config.js index 8f7899f..862a777 100644 --- a/src/config.js +++ b/src/config.js @@ -2,7 +2,7 @@ import {getUrlParameter} from './utils/url'; const ENV = process.env.NODE_ENV === 'production' ? 'prod' : 'debug'; -const ENV_GITHUB_CLIENT_ID = {debug: '4b43250e7499a97d62a5', +const ENV_GITHUB_CLIENT_ID = {debug: 'f1e42d14f45491f9ca34', prod: '4b43250e7499a97d62a5'} export const GITHUB_CLIENT_ID = ENV_GITHUB_CLIENT_ID[ENV];