@@ -300,7 +292,7 @@
placeholder="http://exemple.blogger.com/">
+
@@ -309,13 +301,12 @@
diff --git a/js/file-manager.js b/js/file-manager.js
index 86f940af..1cfeacbb 100644
--- a/js/file-manager.js
+++ b/js/file-manager.js
@@ -434,7 +434,7 @@ define(["jquery", "google-helper", "dropbox-helper", "github-helper", "synchroni
newPublishProvider = provider;
// Show/hide controls depending on provider
- $('div[class*=" control-publish-"]').hide().filter(".control-publish-" + provider).show();
+ $('div[class*=" modal-publish-"]').hide().filter(".modal-publish-" + provider).show();
// Reset fields
core.resetModalInputs();
@@ -457,7 +457,6 @@ define(["jquery", "google-helper", "dropbox-helper", "github-helper", "synchroni
// Create a new publication on GitHub
function newPublishGithub(event) {
var publishObject = {};
- publishObject.username = core.getInputValue($("#input-publish-github-username"), event);
publishObject.repository = core.getInputValue($("#input-publish-github-reponame"), event);
publishObject.branch = core.getInputValue($("#input-publish-github-branch"), event);
publishObject.path = core.getInputValue($("#input-publish-github-path"), event);
@@ -470,7 +469,7 @@ define(["jquery", "google-helper", "dropbox-helper", "github-helper", "synchroni
var title = localStorage[fileIndex + ".title"];
var content = publisher.getPublishContent(publishObject);
var commitMsg = core.settings.commitMsg;
- githubHelper.upload(publishObject.username, publishObject.repository,
+ githubHelper.upload(publishObject.repository,
publishObject.branch, publishObject.path, content, commitMsg,
function(error) {
if(error === undefined) {
diff --git a/js/github-helper.js b/js/github-helper.js
index 82375651..50ee796e 100644
--- a/js/github-helper.js
+++ b/js/github-helper.js
@@ -55,6 +55,7 @@ define(["jquery", "async-runner"], function($, asyncTaskRunner) {
var intervalId = undefined;
var authWindow = undefined;
var token = localStorage["githubToken"];
+ var errorMsg = "Access to GitHub is not authorized.";
var asyncTask = {};
asyncTask.run = function() {
if (github !== undefined) {
@@ -71,7 +72,7 @@ define(["jquery", "async-runner"], function($, asyncTaskRunner) {
return;
}
if(immediate === true) {
- core.showError("Unable to perform GitHub authenticate.");
+ core.showError();
asyncTask.error();
return;
}
@@ -85,15 +86,18 @@ define(["jquery", "async-runner"], function($, asyncTaskRunner) {
authWindow.focus();
intervalId = setInterval(function() {
var code = localStorage["githubCode"];
- if(code !== undefined) {
+ if(authWindow.closed === true || code !== undefined) {
localStorage.removeItem("githubCode");
+ if(code === undefined) {
+ asyncTask.error();
+ return;
+ }
$.getJSON(GATEKEEPER_URL + "authenticate/" + code, function(data) {
if(data.token !== undefined) {
localStorage["githubToken"] = data.token;
asyncTask.success();
}
else {
- core.showError("Error retrieving GitHub Oauth token.");
asyncTask.error();
}
});
@@ -117,50 +121,59 @@ define(["jquery", "async-runner"], function($, asyncTaskRunner) {
if(authWindow !== undefined) {
authWindow.close();
}
+ core.showError(errorMsg);
callback();
};
asyncTaskRunner.addTask(asyncTask);
});
}
- githubHelper.upload = function(username, reponame, branch, path, content, commitMsg, callback) {
+ githubHelper.upload = function(reponame, branch, path, content, commitMsg, callback) {
callback = callback || core.doNothing;
authenticate(function() {
if (github === undefined) {
- callback();
+ callback("error");
return;
}
var error = undefined;
var asyncTask = {};
asyncTask.run = function() {
- var repo = github.getRepo(username, reponame);
- repo.write(branch, path, content, commitMsg, function(err) {
- if(!err) {
- asyncTask.success();
+ var user = github.getUser();
+ user.show(undefined, function(err, result) {
+ if(err) {
+ error = err.error;
+ asyncTask.error();
return;
}
- error = err.error;
- asyncTask.error();
+ var repo = github.getRepo(result.login, reponame);
+ repo.write(branch, path, content, commitMsg, function(err) {
+ if(err) {
+ error = err.error;
+ asyncTask.error();
+ return;
+ }
+ asyncTask.success();
+ });
});
};
asyncTask.onSuccess = function() {
callback(error);
};
asyncTask.onError = function() {
- if(error === 401) {
+ var errorMsg = "Could not publish on GitHub";
+ if(error === 401 || error === 403) {
github = undefined;
// Token must be renewed
localStorage.removeItem("githubToken");
- githubHelper.upload(username, reponame, branch, path, content, commitMsg, callback);
- return;
+ errorMsg = "Access to GitHub is not authorized.";
}
- if(error === 0) {
+ else if(error === 0) {
connected = false;
github = undefined;
core.setOffline();
}
- core.showError("Could not publish on GitHub");
+ core.showError(errorMsg);
callback(error);
};
asyncTaskRunner.addTask(asyncTask);
diff --git a/js/publisher.js b/js/publisher.js
index cdba6d62..865bcac9 100644
--- a/js/publisher.js
+++ b/js/publisher.js
@@ -66,8 +66,7 @@ define(["jquery", "google-helper", "github-helper"], function($, googleHelper, g
// Try to find the provider
if(publishObject.provider == PUBLISH_PROVIDER_GITHUB) {
- githubHelper.upload(publishObject.username, publishObject.repository,
- publishObject.branch, publishObject.path, content, commitMsg,
+ githubHelper.upload(publishObject.repository, publishObject.branch, publishObject.path, content, commitMsg,
function(error) {
publishLocation(callback, error);
});