From: Stefan Lage Date: Fri, 24 May 2013 01:02:08 +0000 (-0400) Subject: nitdoc: Fix bug when signing in X-Git-Tag: v0.6~46^2~10 X-Git-Url: http://nitlanguage.org nitdoc: Fix bug when signing in Before creating the session, we check if the repository and the branch informed are existing, whose causing some bugs when one of these do not exist. If the repository does not exist then we stop the process. If the branch does not exist we ask to the customer if he wants to create it. Signed-off-by: Stefan Lage --- diff --git a/share/nitdoc/scripts/js-facilities.js b/share/nitdoc/scripts/js-facilities.js index 315f7d6..180aab2 100644 --- a/share/nitdoc/scripts/js-facilities.js +++ b/share/nitdoc/scripts/js-facilities.js @@ -19,6 +19,7 @@ var shaMaster; var repoExist = false; var branchExist = false; var githubRepo; +var loginProcess = false; // Spinner vars var opts = { @@ -76,7 +77,6 @@ $(document).ready(function() { $('a[id=cancelBtn]').hide(); // Hide Authenfication form $(".popover").hide(); - githubRepo = $('#repoName').attr('name'); // Update display updateDisplaying(); /* @@ -427,13 +427,22 @@ $(document).ready(function() { { userName = $('#loginGit').val(); password = $('#passwordGit').val(); - repoName = $('#repositoryGit').val(); + githubRepo = $('#repositoryGit').val(); branchName = $('#branchGit').val(); userB64 = "Basic " + base64.encode(userName+':'+password); - setCookie("logginNitdoc", base64.encode(userName+':'+password+':'+repoName+':'+branchName), 1); - $('#loginGit').val(""); - $('#passwordGit').val(""); - reloadComment(); + // Check if repo exist + isRepoExisting(); + if(repoExist){ + $.when(isBranchExisting()).done(function(){ + loginProcess = true; + if(branchExist){ + setCookie("logginNitdoc", base64.encode(userName+':'+password+':'+githubRepo+':'+branchName), 1); + $('#loginGit').val(""); + $('#passwordGit').val(""); + reloadComment(); + } + }); + } } } else @@ -530,9 +539,8 @@ $(document).ready(function() { displayMessage("You need to be loggued before commit something", 100, 40); $('.popover').show(); return; - } + } else{ userB64 = "Basic " + getUserPass("logginNitdoc"); } - githubRepo = repoName; // Check if repo exist isRepoExisting(); if(repoExist){ @@ -579,9 +587,18 @@ $(document).ready(function() { createBranch(); commitMessage = $('#commitMessage').val(); if(commitMessage == ""){ commitMessage = "New commit"; } - if(userB64 != ""){ - if ($.trim(updateComment) == ''){ this.value = (this.defaultValue ? this.defaultValue : ''); } - else{ startCommitProcess(); } + if(userB64 != ""){ + if(loginProcess){ + setCookie("logginNitdoc", base64.encode(userName+':'+password+':'+githubRepo+':'+branchName), 1); + $('#loginGit').val(""); + $('#passwordGit').val(""); + loginProcess = false; + displayLogginModal(); + } + else{ + if ($.trim(updateComment) == ''){ this.value = (this.defaultValue ? this.defaultValue : ''); } + else{ startCommitProcess(); } + } } } else @@ -614,7 +631,7 @@ $(document).ready(function() { branchName = $(this).text(); } }); - $.when(updateCookie(userName, password, repoName, branchName)).done(function(){ + $.when(updateCookie(userName, password, githubRepo, branchName)).done(function(){ closeAllCommentInEdtiting(); reloadComment(); }); @@ -799,7 +816,7 @@ function checkCookie() cookie = base64.decode(cookie); userName = cookie.split(':')[0]; password = cookie.split(':')[1]; - repoName = cookie.split(':')[2]; + githubRepo = cookie.split(':')[2]; branchName = cookie.split(':')[3]; return true; } @@ -1108,18 +1125,18 @@ function getCommentLastCommit(path){ var urlRaw; getLastCommit(); if(shaLastCommit != ""){ - if (checkCookie()) { urlRaw="https://rawgithub.com/"+ userName +"/"+ repoName +"/" + shaLastCommit + "/" + path; } - else{ urlRaw="https://rawgithub.com/StefanLage/"+ $('#repoName').attr('name') +"/" + shaLastCommit + "/" + path; } - - $.ajax({ - type: "GET", - url: urlRaw, - async: false, - success: function(success) - { - currentfileContent = success; - } - }); + if (checkCookie()) { + urlRaw="https://rawgithub.com/"+ userName +"/"+ githubRepo +"/" + shaLastCommit + "/" + path; + $.ajax({ + type: "GET", + url: urlRaw, + async: false, + success: function(success) + { + currentfileContent = success; + } + }); + } } }