Skip to content

Commit

Permalink
fixes #431
Browse files Browse the repository at this point in the history
  • Loading branch information
increpare committed May 18, 2018
1 parent 04877a3 commit e419d14
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 27 deletions.
7 changes: 6 additions & 1 deletion access_token.py
Expand Up @@ -25,13 +25,18 @@
import requests
import sys

OAUTH_CLIENT = "xxxxxxxxxxxxxxxxxxxx"
OAUTH_CLIENT = "211570277eb588cddf44"
OAUTH_SECRET = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
ORIGIN_LIST = [
"www.puzzlescript.net",
"www.increpare.com",
"ded.increpare.com",
"increpare.github.io",
"sfiera.github.io",
"www.flickgame.org",
"www.tinychoice.net",
"www.plingpling.org",
"www.flickgame.org",
]

LOGIN_URL = "https://github.com/login/oauth/access_token"
Expand Down
2 changes: 1 addition & 1 deletion auth.html
Expand Up @@ -24,7 +24,7 @@
// {"access_token": "a440b61aa137bb25bb739b697ef5c96a76881107"}
//
// The server has CORS set up so that puzzlescript.net can access it.
OAUTH_HELPER_URL = "https://twotaled.com/puzzleauth/access_token";
OAUTH_HELPER_URL = "https://ded.increpare.com/cgi-bin/access_token.py";

var pre = document.getElementById("pre");

Expand Down
2 changes: 1 addition & 1 deletion editor.html
Expand Up @@ -156,7 +156,7 @@
<div class="lowerarea" id="lowerarea">
<div id = "consoletextarea" >
=================================<br>
&nbsp;&nbsp;&nbsp;PuzzleScript Log V1.4.6<br>
&nbsp;&nbsp;&nbsp;PuzzleScript Log V1.5.0<br>
=================================<br>
</div>
</div>
Expand Down
71 changes: 48 additions & 23 deletions js/toolbar.js
@@ -1,7 +1,7 @@
// The client ID of a GitHub OAuth app registered at https://github.com/settings/developers.
// The “callback URL” of that app points to https://www.puzzlescript.net/auth.html.
// If you’re running from another host name, sharing might not work.
OAUTH_CLIENT_ID = "52a4e0d89c82c5c29417";
OAUTH_CLIENT_ID = "211570277eb588cddf44";


function runClick() {
Expand Down Expand Up @@ -151,29 +151,33 @@ function levelEditorClick_Fn() {
lastDownTarget=canvas;
}

function printUnauthorized(){
var randomState = window.btoa(Array.prototype.map.call(
window.crypto.getRandomValues(new Uint8Array(24)),
function(x) { return String.fromCharCode(x); }).join(""));

var authUrl = "https://github.com/login/oauth/authorize"
+ "?client_id=" + OAUTH_CLIENT_ID
+ "&scope=gist"
+ "&state=" + randomState
+ "&allow_signup=true";
consolePrint(
"<br>" +
"PuzzleScript needs permission to share games through GitHub:<br>" +
"<ul>" +
"<li><a target=\"_blank\" href=\"" + authUrl + "\">Give PuzzleScript permission</a></li>" +
"</ul>",true);
}

function shareClick() {
var oauthAccessToken = window.localStorage.getItem("oauth_access_token");
if (typeof oauthAccessToken !== "string") {
// Generates 32 letters of random data, like "liVsr/e+luK9tC02fUob75zEKaL4VpQn".
var randomState = window.btoa(Array.prototype.map.call(
window.crypto.getRandomValues(new Uint8Array(24)),
function(x) { return String.fromCharCode(x); }).join(""));

var authUrl = "https://github.com/login/oauth/authorize"
+ "?client_id=" + OAUTH_CLIENT_ID
+ "&scope=gist"
+ "&state=" + randomState
+ "&allow_signup=true";
consolePrint(
"PuzzleScript needs permission to share games through GitHub:<br>" +
"<ul>" +
"<li><a target=\"_blank\" href=\"https://github.com/join\">Create a GitHub account</a></li>" +
"<li><a target=\"_blank\" href=\"" + authUrl + "\">Give PuzzleScript permission</a></li>" +
"</ul>");
printUnauthorized();
return;
}

consolePrint("Sending code to github...",true)
consolePrint("<br>Sending code to github...",true)
var title = "Untitled PuzzleScript Script";
if (state.metadata.title!==undefined) {
title=state.metadata.title + " PuzzleScript Script";
Expand Down Expand Up @@ -207,27 +211,36 @@ function shareClick() {
if (githubHTTPClient.status===403) {
consoleError(result.message);
} else if (githubHTTPClient.status!==200&&githubHTTPClient.status!==201) {
consoleError("HTTP Error "+ githubHTTPClient.status + ' - ' + githubHTTPClient.statusText);
if (githubHTTPClient.statusText==="Unauthorized"){
consoleError("Authorization check failed. You have to log back into GitHub (or give it permission again or something).");
window.localStorage.removeItem("oauth_access_token");
} else {
consoleError("HTTP Error "+ githubHTTPClient.status + ' - ' + githubHTTPClient.statusText);
consoleError("Try giving puzzlescript permission again, that might fix things...");
}

printUnauthorized();
} else {
var id = result.id;
var url = "play.html?p="+id;
url=qualifyURL(url);

var editurl = "editor.html?hack="+id;
editurl=qualifyURL(editurl);
var sourceCodeLink = "link to source code:<br><a target=\"_blank\" href=\""+editurl+"\">"+editurl+"</a>";
var sourceCodeLink = "Link to source code:<br><a target=\"_blank\" href=\""+editurl+"\">"+editurl+"</a>";


consolePrint("GitHub submission successful - " + sourceCodeLink,true);
consolePrint('GitHub (<a onclick="githubLogOut();" href="javascript:void(0);">log out</a>) submission successful.<br>',true);

consolePrint('<br>'+sourceCodeLink,true);


if (errorCount>0) {
consolePrint("Cannot link directly to playable game, because there are compiler errors.",true);
consolePrint("<br>Cannot link directly to playable game, because there are compiler errors.",true);
} else {
consolePrint("The game can now be played at this url:<br><a target=\"_blank\" href=\""+url+"\">"+url+"</a>",true);
consolePrint("<br>The game can now be played at this url:<br><a target=\"_blank\" href=\""+url+"\">"+url+"</a>",true);
}


}
}
githubHTTPClient.setRequestHeader("Content-type","application/x-www-form-urlencoded");
Expand All @@ -236,6 +249,18 @@ function shareClick() {
lastDownTarget=canvas;
}

function githubLogOut(){
window.localStorage.removeItem("oauth_access_token");
consolePrint(
"<br>Logged out of Github.<br>" +
"<ul>" +
"<li><a target=\"_blank\" href=\"" + authUrl + "\">Give PuzzleScript permission</a></li>" +

This comment has been minimized.

Copy link
@sfiera

sfiera May 18, 2018

Contributor

authUrl not set?

This comment has been minimized.

Copy link
@increpare

increpare May 18, 2018

Author Owner

oops! one sec! :)

This comment has been minimized.

Copy link
@increpare

increpare May 18, 2018

Author Owner

should be fixed now

"</ul>"
,true);
shareClick();

}

function rebuildClick() {
clearConsole();
compile(["rebuild"]);
Expand Down
2 changes: 1 addition & 1 deletion standalone_inlined.txt

Large diffs are not rendered by default.

0 comments on commit e419d14

Please sign in to comment.