Skip to content

Commit 349983b

Browse files
Add ability to save token in Preferences
1 parent b4eab79 commit 349983b

File tree

4 files changed

+25
-20
lines changed

4 files changed

+25
-20
lines changed

GitHubManager.js

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,13 @@ define(function (require, exports, module) {
2828
var Dialogs = brackets.getModule("widgets/Dialogs"),
2929
FileSystem = brackets.getModule("filesystem/FileSystem"),
3030
PreferencesManager = brackets.getModule("preferences/PreferencesManager"),
31-
PromiseQueue = brackets.getModule("utils/Async").PromiseQueue,
32-
ProjectManager = brackets.getModule("project/ProjectManager"),
33-
Strings = brackets.getModule("strings"),
34-
StringUtils = brackets.getModule("utils/StringUtils"),
3531
_ = brackets.getModule("thirdparty/lodash"),
3632
Octokit = require("octokit"),
3733
cloneDialog = require("text!templates/clone-dialog.html"),
3834
loginDialog = require("text!templates/login-dialog.html"),
3935
cloneDialogData = require("text!json/clone-dialog.json"),
40-
loginDialogData = require("text!json/login-dialog.json");
36+
loginDialogData = require("text!json/login-dialog.json"),
37+
prefs = PreferencesManager.getExtensionPrefs("bsirlinger.GitHubAccess");
4138

4239
function GitHubManager() {
4340
}
@@ -190,12 +187,26 @@ define(function (require, exports, module) {
190187
};
191188

192189
GitHubManager.prototype.init = function () {
190+
prefs.definePreference("token", "string", "");
191+
193192
var gh,
194193
self = new GitHubManager(),
195194
repo,
196195
templateVars,
197196
dlg,
198-
$dlg;
197+
$dlg,
198+
temp;
199+
200+
temp = prefs.get("token");
201+
202+
if (temp.length === 40) {
203+
gh = new Octokit({
204+
token: temp
205+
});
206+
207+
self.openCloneDialog(gh, self);
208+
return;
209+
}
199210

200211
templateVars = JSON.parse(loginDialogData);
201212

@@ -210,10 +221,16 @@ define(function (require, exports, module) {
210221
var valid = self.checkLoginData($dlg);
211222

212223
if (valid) {
224+
var token = $dlg.find("input.oauth-token").val();
225+
213226
gh = new Octokit({
214-
token: $dlg.find("input.oauth-token").val()
227+
token: token
215228
});
216229

230+
if ($dlg.find("input:checked").size() === 1) {
231+
prefs.set("token", token);
232+
prefs.save();
233+
}
217234

218235
Dialogs.cancelModalDialogIfOpen("github-access-login", "login");
219236
self.openCloneDialog(gh, self);
File renamed without changes.

templates/login-dialog.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ <h1 class="dialog-title">{{title}}</h1>
55
<div class="modal-body">
66
<div class="dialog-message">
77
<p>
8-
Please fill in eiter you Username and Password or use an Oauth Token (for info how to generate these please visit <a href="#">this wiki site</a>)
8+
Please fill in an Oauth Token (for info how to generate these please visit <a href="https://github.com/WebsiteDeveloper/GitHubAccess/wiki/Generating-API-token">this wiki site</a>)
99
</p>
1010
<div class="oauth-auth form-horizontal">
1111
<label for="repo">Oauth Token:</label>

templates/panel.html

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)