Skip to content
This repository was archived by the owner on Apr 26, 2022. It is now read-only.

Commit dbef692

Browse files
committed
Multiaccount support
1 parent 5a13522 commit dbef692

File tree

3 files changed

+127
-53
lines changed

3 files changed

+127
-53
lines changed

app/login.html

Lines changed: 120 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -38,20 +38,23 @@ <h4>
3838

3939
<div class="row">
4040
<div class="col-xs-8 col-xs-offset-2">
41-
<form id="ptc_form" onsubmit="doPTCLogin()">
42-
<input id="ptc_username" class="form-control" type="text" placeholder="PTC Username" required>
43-
<input id="ptc_password" class="form-control" type="password" placeholder="PTC Password" required>
44-
<button class="btn btn-lg btn-block btn-primary login" onclick="doPTCLogin()">Login with PTC</button>
45-
<div class="checkbox">
46-
<label>
47-
<input type="checkbox" id="remember" checked="1"> Remember login info</label>
48-
</div>
49-
</form>
41+
42+
<table class="table">
43+
<thead>
44+
<th>Service</th>
45+
<th>Username</th>
46+
<th></th>
47+
</thead>
48+
<tbody align="left" id="actDisplay">
49+
</tbody>
50+
</table>
51+
52+
<button class="btn btn-lg btn-block btn-primary"
53+
data-toggle="modal" data-target="#add-acct">Add New Account</button>
54+
<br>
5055
<br>
51-
<span id="ptc_errors" style="color: #f00"></span>
52-
<span style="color: #f00">
53-
<a href="https://sso.pokemon.com/sso/login" class="new-window">Create a PTC Account</a>
54-
</span>
56+
<button class="btn btn-lg btn-block btn-success" onclick="startServer()">Start Server</button>
57+
5558
</div>
5659
</div>
5760

@@ -186,6 +189,44 @@ <h4>Send your donation to the following address:</h4>
186189
</div>
187190
</div>
188191

192+
<div class="modal fade" id="add-acct" tabindex="-1"
193+
role="dialog" aria-labelledby="actModalLbl">
194+
<div class="modal-dialog" role="document">
195+
<div class="modal-content">
196+
<div class="modal-header">
197+
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
198+
<h4 class="modal-title" id="actModalLbl">Add Account</h4>
199+
</div>
200+
<div class="modal-body">
201+
<div class="text-center">
202+
<div>
203+
204+
<form id="act_form" onsubmit="verifyAndAddAccount()">
205+
<input id="username" class="form-control" type="text" placeholder="Username" required>
206+
<input id="password" class="form-control" type="password" placeholder="Password" required>
207+
<div class="radio">
208+
<label class="radio-inline"><input type="radio" name="acttype" value="ptc" checked>PTC</label>
209+
<label class="radio-inline"><input type="radio" name="acttype" value="google">Google</label>
210+
</div>
211+
<button class="btn btn-lg btn-block btn-primary login" onclick="verifyAndAddAccount()">Add Account</button>
212+
</form>
213+
214+
<br><br>
215+
216+
<span id="ptc_errors" style="color: #f00"></span>
217+
<br>
218+
<span style="color: #f00">
219+
<a href="https://sso.pokemon.com/sso/login"
220+
class="new-window">Create a PTC Account</a>
221+
</span>
222+
223+
</div>
224+
</div>
225+
</div>
226+
</div>
227+
</div>
228+
</div>
229+
189230
</body>
190231

191232
<script type="text/javascript">
@@ -212,6 +253,7 @@ <h4>Send your donation to the following address:</h4>
212253

213254
var geoLat = 34.0432108;
214255
var geoLon = -118.2675059;
256+
var userAccounts = [];
215257

216258
$( document ).ready(function(){
217259
// Show version
@@ -231,7 +273,7 @@ <h4>Send your donation to the following address:</h4>
231273

232274
// Get checkbox state
233275
[
234-
'remember', 'is_public'
276+
'is_public'
235277
].forEach(function(elem){
236278
if (localStorage.getItem(elem)) {
237279
document.getElementById(elem).checked = (
@@ -242,18 +284,17 @@ <h4>Send your donation to the following address:</h4>
242284
});
243285
});
244286

245-
if (checked('remember')) {
246-
setupValue('ptc_username', $('#ptc_username'));
247-
setupValue('ptc_password', $('#ptc_password'));
248-
}
249-
250-
// setupValueAndSetter('filter_type', $('#filter_type'));
251-
// setupValueAndSetter('pokeids', $('#pokeids'));
252287
setupValueAndSetter('radius', $('#radius'));
253288

254-
setupValue('last_lat', $('#lat'));
255-
setupValue('last_lon', $('#lon'));
289+
setupValueAndSetter('last_lat', $('#lat'));
290+
setupValueAndSetter('last_lon', $('#lon'));
256291
setupValueAndSetter('maps_api_key', $('#maps_api_key'));
292+
293+
if (localStorage.getItem('user_acct')) {
294+
userAccounts = JSON.parse(localStorage.getItem('user_acct'));
295+
}
296+
297+
populateUserAccounts();
257298
});
258299

259300
function setupValue(key, elem) {
@@ -274,12 +315,23 @@ <h4>Send your donation to the following address:</h4>
274315
}
275316

276317
function saveState() {
277-
if (checked('remember')) {
278-
localStorage.setItem("ptc_username", $('#ptc_username').val());
279-
localStorage.setItem("ptc_password", $('#ptc_password').val());
280-
}
281-
localStorage.setItem("last_lat", $('#lat').val());
282-
localStorage.setItem("last_lon", $('#lon').val());
318+
localStorage.setItem('user_acct', JSON.stringify(userAccounts));
319+
}
320+
321+
function populateUserAccounts() {
322+
var displayHtml = '';
323+
userAccounts.forEach(function(val, idx) {
324+
displayHtml += '<tr><td>'+val.type+'</td>';
325+
displayHtml += '<td>'+val.user+'</td>';
326+
displayHtml += '<td><a href="#" onclick="deleteUser('+idx+')">[X]</a></td></tr>';
327+
});
328+
$('#actDisplay').html(displayHtml);
329+
saveState();
330+
}
331+
332+
function deleteUser(idx) {
333+
userAccounts.splice(idx, 1);
334+
populateUserAccounts();
283335
}
284336

285337
navigator.geolocation.getCurrentPosition(function success(position) {
@@ -289,7 +341,6 @@ <h4>Send your donation to the following address:</h4>
289341
$('#lon').prop('placeholder', geoLon);
290342
console.log("Got location: " + geoLat + ", " + geoLon);
291343
}, function error(err) {
292-
console.log("Error getting location, trying second provider", err);
293344
$.getJSON("http://ipinfo.io", function(ipinfo){
294345
console.log("Found location ["+ipinfo.loc+"] by ipinfo.io");
295346
var latLong = ipinfo.loc.split(",");
@@ -317,6 +368,28 @@ <h4>Send your donation to the following address:</h4>
317368
ipcRenderer.send('installUpdate');
318369
}
319370

371+
function verifyAndAddAccount() {
372+
var acttype = $('input[name=acttype]:checked', '#act_form').val();
373+
if (acttype == 'ptc') {
374+
doPTCLogin();
375+
} else {
376+
addAccount();
377+
}
378+
}
379+
380+
function addAccount() {
381+
var acctInfo = {
382+
user: $('#username').val(),
383+
pass: $('#password').val(),
384+
type: $('input[name=acttype]:checked', '#act_form').val()
385+
};
386+
$('#username').val('');
387+
$('#password').val('');
388+
$('#add-acct').modal('hide');
389+
userAccounts.push(acctInfo);
390+
populateUserAccounts();
391+
}
392+
320393
function doLogin(ssoUrl, callback) {
321394
var authWindow = new BrowserWindow(
322395
{ width: 800, height: 600, show: false,
@@ -360,17 +433,18 @@ <h4>Send your donation to the following address:</h4>
360433
return false;
361434
}
362435
}
436+
if (userAccounts.length <= 0) {
437+
alert('You must add at least 1 account.');
438+
return false;
439+
}
363440
return true;
364441
}
365442

366443
function doPTCLogin() {
367-
if (!checkParams()){
368-
return;
369-
}
370444
toggleLogin(true);
371445
jQuery('#ptc_errors').html('');
372-
var username = jQuery('#ptc_username').val(),
373-
password = jQuery('#ptc_password').val();
446+
var username = jQuery('#username').val(),
447+
password = jQuery('#password').val();
374448

375449
// Reset cookie jar
376450
ptcJar = request.jar();
@@ -428,10 +502,15 @@ <h4>Send your donation to the following address:</h4>
428502
}
429503

430504
function handlePokemonCallback(newUrl) {
505+
toggleLogin(false);
506+
addAccount();
507+
}
431508

432-
// Login by passing in password to prevent timeouts
433-
completeLogin('ptc', '');
434-
509+
function startServer() {
510+
if (!checkParams()){
511+
return;
512+
}
513+
completeLogin('', '');
435514
}
436515

437516
function completeLogin(auth, code) {
@@ -447,9 +526,8 @@ <h4>Send your donation to the following address:</h4>
447526
is_public: checked('is_public'),
448527
//fast_scan: checked('fast_scan'),
449528
radius: $('#radius').val(),
450-
username: $('#ptc_username').val(),
451-
password: $('#ptc_password').val(),
452-
maps_api_key: $('#maps_api_key').val()
529+
maps_api_key: $('#maps_api_key').val(),
530+
accounts: userAccounts
453531
});
454532
}
455533

@@ -479,6 +557,7 @@ <h4>Send your donation to the following address:</h4>
479557
$("#lat").val(loc.geometry.location.lat);
480558
$("#lon").val(loc.geometry.location.lng);
481559
}
560+
482561
function toggleGeolocate(disabled) {
483562
if(disabled == null) {
484563
disabled = $("#address").val().trim().length == 0;

app/main.js

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,6 @@ function startPython(auth, code, lat, long, opts) {
209209
var cmdLine = [
210210
'./run_map.py',
211211
'--cors',
212-
'--auth-service',
213-
auth,
214212
'--location=' +
215213
parseFloat(lat).toFixed(7) + ',' + parseFloat(long).toFixed(7),
216214
'--port',
@@ -234,17 +232,14 @@ function startPython(auth, code, lat, long, opts) {
234232
cmdLine.push(opts.maps_api_key);
235233
}
236234

237-
if (auth == 'ptc' && opts.username) {
235+
opts.accounts.forEach(function(val) {
236+
cmdLine.push('--auth-service');
237+
cmdLine.push(val.type);
238238
cmdLine.push('--username');
239-
cmdLine.push(opts.username);
239+
cmdLine.push(val.user);
240240
cmdLine.push('--password');
241-
cmdLine.push(opts.password);
242-
}
243-
244-
if (auth == 'google' && code) {
245-
cmdLine.push('--token');
246-
cmdLine.push(code);
247-
}
241+
cmdLine.push(val.pass);
242+
});
248243

249244
// Add options
250245

app/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"author": "Mike Christopher",
55
"repository": "https://github.com/mchristopher/PokemonGo-DesktopMap",
66
"license": "MIT",
7-
"version" : "0.3.3",
7+
"version" : "0.3.4",
88
"main": "main.js",
99
"scripts": {
1010
"start": "electron ."

0 commit comments

Comments
 (0)