38
38
39
39
< div class ="row ">
40
40
< 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 >
50
55
< 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
+
55
58
</ div >
56
59
</ div >
57
60
@@ -186,6 +189,44 @@ <h4>Send your donation to the following address:</h4>
186
189
</ div >
187
190
</ div >
188
191
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 "> ×</ 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
+
189
230
</ body >
190
231
191
232
< script type ="text/javascript ">
@@ -212,6 +253,7 @@ <h4>Send your donation to the following address:</h4>
212
253
213
254
var geoLat = 34.0432108 ;
214
255
var geoLon = - 118.2675059 ;
256
+ var userAccounts = [ ] ;
215
257
216
258
$ ( document ) . ready ( function ( ) {
217
259
// Show version
@@ -231,7 +273,7 @@ <h4>Send your donation to the following address:</h4>
231
273
232
274
// Get checkbox state
233
275
[
234
- 'remember' , ' is_public'
276
+ 'is_public'
235
277
] . forEach ( function ( elem ) {
236
278
if ( localStorage . getItem ( elem ) ) {
237
279
document . getElementById ( elem ) . checked = (
@@ -242,18 +284,17 @@ <h4>Send your donation to the following address:</h4>
242
284
} ) ;
243
285
} ) ;
244
286
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'));
252
287
setupValueAndSetter ( 'radius' , $ ( '#radius' ) ) ;
253
288
254
- setupValue ( 'last_lat' , $ ( '#lat' ) ) ;
255
- setupValue ( 'last_lon' , $ ( '#lon' ) ) ;
289
+ setupValueAndSetter ( 'last_lat' , $ ( '#lat' ) ) ;
290
+ setupValueAndSetter ( 'last_lon' , $ ( '#lon' ) ) ;
256
291
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 ( ) ;
257
298
} ) ;
258
299
259
300
function setupValue ( key , elem ) {
@@ -274,12 +315,23 @@ <h4>Send your donation to the following address:</h4>
274
315
}
275
316
276
317
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 ( ) ;
283
335
}
284
336
285
337
navigator . geolocation . getCurrentPosition ( function success ( position ) {
@@ -289,7 +341,6 @@ <h4>Send your donation to the following address:</h4>
289
341
$ ( '#lon' ) . prop ( 'placeholder' , geoLon ) ;
290
342
console . log ( "Got location: " + geoLat + ", " + geoLon ) ;
291
343
} , function error ( err ) {
292
- console . log ( "Error getting location, trying second provider" , err ) ;
293
344
$ . getJSON ( "http://ipinfo.io" , function ( ipinfo ) {
294
345
console . log ( "Found location [" + ipinfo . loc + "] by ipinfo.io" ) ;
295
346
var latLong = ipinfo . loc . split ( "," ) ;
@@ -317,6 +368,28 @@ <h4>Send your donation to the following address:</h4>
317
368
ipcRenderer . send ( 'installUpdate' ) ;
318
369
}
319
370
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
+
320
393
function doLogin ( ssoUrl , callback ) {
321
394
var authWindow = new BrowserWindow (
322
395
{ width : 800 , height : 600 , show : false ,
@@ -360,17 +433,18 @@ <h4>Send your donation to the following address:</h4>
360
433
return false ;
361
434
}
362
435
}
436
+ if ( userAccounts . length <= 0 ) {
437
+ alert ( 'You must add at least 1 account.' ) ;
438
+ return false ;
439
+ }
363
440
return true ;
364
441
}
365
442
366
443
function doPTCLogin ( ) {
367
- if ( ! checkParams ( ) ) {
368
- return ;
369
- }
370
444
toggleLogin ( true ) ;
371
445
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 ( ) ;
374
448
375
449
// Reset cookie jar
376
450
ptcJar = request . jar ( ) ;
@@ -428,10 +502,15 @@ <h4>Send your donation to the following address:</h4>
428
502
}
429
503
430
504
function handlePokemonCallback ( newUrl ) {
505
+ toggleLogin ( false ) ;
506
+ addAccount ( ) ;
507
+ }
431
508
432
- // Login by passing in password to prevent timeouts
433
- completeLogin ( 'ptc' , '' ) ;
434
-
509
+ function startServer ( ) {
510
+ if ( ! checkParams ( ) ) {
511
+ return ;
512
+ }
513
+ completeLogin ( '' , '' ) ;
435
514
}
436
515
437
516
function completeLogin ( auth , code ) {
@@ -447,9 +526,8 @@ <h4>Send your donation to the following address:</h4>
447
526
is_public : checked ( 'is_public' ) ,
448
527
//fast_scan: checked('fast_scan'),
449
528
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
453
531
} ) ;
454
532
}
455
533
@@ -479,6 +557,7 @@ <h4>Send your donation to the following address:</h4>
479
557
$ ( "#lat" ) . val ( loc . geometry . location . lat ) ;
480
558
$ ( "#lon" ) . val ( loc . geometry . location . lng ) ;
481
559
}
560
+
482
561
function toggleGeolocate ( disabled ) {
483
562
if ( disabled == null ) {
484
563
disabled = $ ( "#address" ) . val ( ) . trim ( ) . length == 0 ;
0 commit comments