1
0
mirror of https://github.com/sehugg/8bitworkshop.git synced 2024-11-29 14:51:17 +00:00

github: message after signing in, let login errors propogate, added Log Out

This commit is contained in:
Steven Hugg 2019-05-22 14:45:03 -04:00
parent 980c8beb89
commit b190cb7cfd
3 changed files with 28 additions and 5 deletions

View File

@ -69,6 +69,8 @@ if (window.location.host.endsWith('8bitworkshop.com')) {
<a tabindex="-1" href="#">Sync</a> <a tabindex="-1" href="#">Sync</a>
<ul class="dropdown-menu"> <ul class="dropdown-menu">
<li><a class="dropdown-item" href="#" id="item_github_login">Sign in to Github...</a></li> <li><a class="dropdown-item" href="#" id="item_github_login">Sign in to Github...</a></li>
<li><a class="dropdown-item" href="#" id="item_github_logout">Log out</a></li>
<hr>
<li><a class="dropdown-item" href="#" id="item_github_import">Import Project from GitHub...</a></li> <li><a class="dropdown-item" href="#" id="item_github_import">Import Project from GitHub...</a></li>
<li><a class="dropdown-item" href="#" id="item_github_publish">Publish Project on GitHub...</a></li> <li><a class="dropdown-item" href="#" id="item_github_publish">Publish Project on GitHub...</a></li>
<li><a class="dropdown-item" href="#" id="item_repo_delete">Delete Local Repository...</a></li> <li><a class="dropdown-item" href="#" id="item_repo_delete">Delete Local Repository...</a></li>

View File

@ -79,9 +79,21 @@ export class GithubService {
this.recreateGithub(); this.recreateGithub();
document.cookie = "__github_key=" + this.githubToken + ";path=/;max-age=31536000"; document.cookie = "__github_key=" + this.githubToken + ";path=/;max-age=31536000";
console.log("Stored GitHub OAUTH key"); console.log("Stored GitHub OAUTH key");
}).catch( (error) => { });
console.log(error); }
bootbox.alert("Could not login to GitHub: " + error);
logout() : Promise<void> {
// already logged out? return immediately
if (!(this.githubToken && this.githubToken.length)) {
return new Promise<void>( (yes,no) => {
yes();
});
}
// logout
return firebase.auth().signOut().then(() => {
document.cookie = "__github_key=;path=/;max-age=0";
this.githubToken = null;
this.recreateGithub();
}); });
} }

View File

@ -455,7 +455,15 @@ function importProjectFromGithub(githuburl:string) {
} }
function _loginToGithub(e) { function _loginToGithub(e) {
getGithubService().login(); getGithubService().login().then(() => {
alertInfo("You are signed in to Github.");
});
}
function _logoutOfGithub(e) {
getGithubService().logout().then(() => {
alertInfo("You are logged out of Github.");
});
} }
function _importProjectFromGithub(e) { function _importProjectFromGithub(e) {
@ -524,7 +532,7 @@ function _pushProjectToGithub(e) {
function _pullProjectFromGithub(e) { function _pullProjectFromGithub(e) {
var ghurl = getBoundGithubURL(); var ghurl = getBoundGithubURL();
if (!ghurl) return; if (!ghurl) return;
bootbox.confirm("Pull from repository and replace all local files?", (ok) => { bootbox.confirm("Pull from repository and replace all local files? Any changes you've made will be overwritten.", (ok) => {
if (ok) { if (ok) {
setWaitDialog(true); setWaitDialog(true);
getGithubService().pull(ghurl).then( (sess:GHSession) => { getGithubService().pull(ghurl).then( (sess:GHSession) => {
@ -1430,6 +1438,7 @@ function setupDebugControls() {
$("#item_new_file").click(_createNewFile); $("#item_new_file").click(_createNewFile);
$("#item_upload_file").click(_uploadNewFile); $("#item_upload_file").click(_uploadNewFile);
$("#item_github_login").click(_loginToGithub); $("#item_github_login").click(_loginToGithub);
$("#item_github_logout").click(_logoutOfGithub);
$("#item_github_import").click(_importProjectFromGithub); $("#item_github_import").click(_importProjectFromGithub);
$("#item_github_publish").click(_publishProjectToGithub); $("#item_github_publish").click(_publishProjectToGithub);
$("#item_github_push").click(_pushProjectToGithub); $("#item_github_push").click(_pushProjectToGithub);