Skip to content

Commit

Permalink
Update without exposing secret
Browse files Browse the repository at this point in the history
  • Loading branch information
ocruzv committed Jul 31, 2018
1 parent fa43b6a commit 4dac5b0
Show file tree
Hide file tree
Showing 5 changed files with 312 additions and 219 deletions.
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,14 @@
},
"dependencies": {
"axios": "^0.18.0",
"body-parser": "^1.18.3",
"bplist-parser": "^0.1.1",
"electron-oauth2": "^3.0.0",
"electron-osx-prompt": "^1.3.10",
"electron-routes": "^1.3.0",
"express": "^4.16.3",
"motion-core": "https://github.com/motioncrypto/motion-core",
"opn": "^5.3.0",
"vue": "^2.5.13",
"vue-electron": "^1.0.6",
"vue-js-modal": "^1.3.15",
Expand Down Expand Up @@ -93,8 +97,8 @@
"css-loader": "^0.28.4",
"del": "^3.0.0",
"devtron": "^1.4.0",
"electron": "^1.7.5",
"electron-builder": "^19.19.1",
"electron": "^2.0.5",
"electron-builder": "^20.26.0",
"electron-debug": "^1.4.0",
"electron-devtools-installer": "^2.2.0",
"eslint": "^4.4.1",
Expand Down
Empty file added src/main/express.js
Empty file.
40 changes: 15 additions & 25 deletions src/main/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import { app, BrowserWindow, ipcMain, Menu } from 'electron' // eslint-disable-line
const electronOauth2 = require('electron-oauth2');
const oauthConfig = require('./config').oauth;
import { app, BrowserWindow, Menu } from 'electron' // eslint-disable-line
const express = require('express');
const bodyParser = require('body-parser');
const expressApp = express();
const Client = require('motion-core');
const client = new Client({
username: 'motion',
password: '47VMxa7GvxKaV3J',
port: 3385,
});

expressApp.use(bodyParser.urlencoded({ extended: true }));
expressApp.use(bodyParser.json());

/**
* Set `__static` path to static files in production
* https://simulatedgreg.gitbooks.io/electron-vue/content/en/using-static-assets.html
Expand All @@ -16,22 +20,20 @@ if (process.env.NODE_ENV !== 'development') {
global.__static = require('path').join(__dirname, '/static').replace(/\\/g, '\\\\') // eslint-disable-line
}

const windowParams = {
alwaysOnTop: true,
autoHideMenuBar: true,
webPreferences: {
nodeIntegration: false,
},
};

const digitalOceanOAuth = electronOauth2(oauthConfig, windowParams);

let mainWindow;
const winURL = process.env.NODE_ENV === 'development'
? 'http://localhost:9080'
: `file://${__dirname}/index.html`;

expressApp.get('/do-auth/:accessToken', (req, res) => {
mainWindow.webContents.send('do-oauth-reply', req.params.accessToken);
res.send('Done, now you can close this tab and return to the installer.');
});

function createWindow() {
expressApp.listen(3456, () => {
console.log('oAuth Server listening on port 3456!');
});
/**
* Initial window options
*/
Expand Down Expand Up @@ -80,18 +82,6 @@ function createWindow() {
Menu.setApplicationMenu(Menu.buildFromTemplate(template));
}

ipcMain.on('do-oauth', (event) => {
digitalOceanOAuth.getAccessToken({
scope: 'read write',
})
.then((token) => {
console.log(token);
event.sender.send('do-oauth-reply', token);
}, (err) => {
console.log('Error while getting token', err);
});
});

app.on('ready', createWindow);

app.on('quit', () => {
Expand Down
12 changes: 7 additions & 5 deletions src/renderer/components/LandingPage/FirstStep.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
<div id="first-step">
<p>Currently you have: <span class="amount">{{Math.floor(balance)}}</span>XMN</p>
<p class="mt20" v-if="balance >= 1000">We can continue.</p>
<p class="mt20" v-if="balance < 1000">We can't continue. You need at least 1000 XMN unlocked on your account.</p>
<p class="mt20" v-if="balance < 1000">We can't continue. You need at least 1000.1 XMN unlocked on your account.</p>
<div class="separator"></div>
<div v-if="balance >= 1000">
<div v-if="balance >= 1000.1">
<p>First, we need a good VPS:</p>
<img src="~@/assets/digitalocean.png" class="do-logo" alt="DigitalOcean" />
<ul class="buttons">
Expand All @@ -16,7 +16,7 @@
</li>
</ul>
</div>
<div v-if="balance < 1000">
<div v-if="balance < 1000.1">
<p>You can get more XMN from our <a href="https://motionproject.org/#exchanges" @click="openLink($event, 'https://motionproject.org/#exchanges')" target="_blank">supported exchanges</a>.</p>
</div>
<modal name="passphrase"
Expand All @@ -42,6 +42,7 @@ import { shell, ipcRenderer } from 'electron';
import fs from 'fs';
// import path from 'path';
import VueCircle from 'vue2-circle-progress';
import opn from 'opn';
import { setTimeout } from 'timers';
const { dialog } = require('electron').remote;
const Client = require('motion-core');
Expand Down Expand Up @@ -267,7 +268,8 @@ export default {
});
},
loginWithDigitalOcean() {
ipcRenderer.send('do-oauth', 'getToken');
// ipcRenderer.send('do-oauth', 'getToken');
opn('https://cloud.digitalocean.com/v1/oauth/authorize?client_id=643548bb6989b2d7440fc1918f386541b8a43b3baeebcd008b331ee04d4f8d76&redirect_uri=https://us-central1-motion-masternode-installer.cloudfunctions.net/oauthCallback&response_type=code&scope=read write');
},
},
mounted() {
Expand All @@ -280,7 +282,7 @@ export default {
ipcRenderer.on('do-oauth-reply', (event, accessToken) => {
this.$store.commit('SET_ACCESS_TOKEN', {
accessToken: accessToken.access_token,
accessToken,
});
this.getCurrentMasternodes();
});
Expand Down
Loading

0 comments on commit 4dac5b0

Please sign in to comment.