save password in db
This commit is contained in:
parent
9520b7bc7b
commit
6821b93478
3 changed files with 45 additions and 8 deletions
|
@ -718,11 +718,10 @@ class OxControl(Resource):
|
|||
|
||||
if __name__ == '__main__':
|
||||
db = 'dev.sqlite'
|
||||
db = sys.argv[1]
|
||||
port = 2620
|
||||
username = 'fix'
|
||||
password = 'me'
|
||||
|
||||
db = sys.argv[1]
|
||||
|
||||
port = 2620
|
||||
interface = '127.0.0.1'
|
||||
interface = '10.26.20.10'
|
||||
interface = '0.0.0.0'
|
||||
|
@ -731,6 +730,9 @@ if __name__ == '__main__':
|
|||
|
||||
root = OxControl(db)
|
||||
|
||||
username = root.db.get('username', 'fix')
|
||||
password = root.db.get('password', 'me')
|
||||
|
||||
checker = InMemoryUsernamePasswordDatabaseDontUse()
|
||||
checker.addUser(username, password)
|
||||
|
||||
|
|
|
@ -30,6 +30,8 @@ function OxFF() {
|
|||
var windowMediator = Cc["@mozilla.org/appshell/window-mediator;1"].getService(Ci.nsIWindowMediator);
|
||||
var nsWindow = windowMediator.getMostRecentWindow("navigator:browser");
|
||||
this._window = nsWindow.content;
|
||||
this._window.addEventListener("unload", function() { _this.logout() }, false);
|
||||
|
||||
this.app = Cc["@mozilla.org/fuel/application;1"].getService(Ci.fuelIApplication);
|
||||
|
||||
this._site = this._window.document.location.hostname;
|
||||
|
@ -38,7 +40,12 @@ function OxFF() {
|
|||
}
|
||||
this.access();
|
||||
|
||||
this._window.addEventListener("unload", function() { _this.logout() }, false);
|
||||
if(!ox.get('username')) {
|
||||
ox.set('username', ox.makeRandomString(8));
|
||||
ox.set('password', ox.makeRandomString(8));
|
||||
}
|
||||
this.username = ox.get('username');
|
||||
this.password = ox.get('password');
|
||||
}
|
||||
|
||||
OxFF.prototype = {
|
||||
|
@ -111,8 +118,6 @@ OxFF.prototype = {
|
|||
this.app.console.log(msg);
|
||||
},
|
||||
base: 'http://127.0.0.1:2620/',
|
||||
username: 'fix',
|
||||
password: 'me',
|
||||
_user: null,
|
||||
|
||||
//nsIOxFF
|
||||
|
@ -194,6 +199,7 @@ OxFF.prototype = {
|
|||
formData.append(key, data[key]);
|
||||
}
|
||||
}
|
||||
|
||||
req.open("POST", url, true, this.username, this.password);
|
||||
req.send(formData);
|
||||
return true;
|
||||
|
|
|
@ -17,9 +17,25 @@ let ox = {
|
|||
var file = this.getDBFile();
|
||||
var storageService = Cc["@mozilla.org/storage/service;1"].getService(Ci.mozIStorageService);
|
||||
var conn = storageService.openDatabase(file);
|
||||
conn.executeSimpleSQL("CREATE TABLE IF NOT EXISTS site (site varchar(1024) unique, access INT)");
|
||||
conn.executeSimpleSQL("CREATE TABLE IF NOT EXISTS site (site varchar(1024) unique, access INT)");
|
||||
conn.executeSimpleSQL("CREATE TABLE IF NOT EXISTS setting (key varchar(1024) unique, value text)");
|
||||
return conn;
|
||||
},
|
||||
get: function(key, defaultValue) {
|
||||
var conn = this.getDB();
|
||||
var q = conn.createStatement("SELECT value FROM setting WHERE key = :key");
|
||||
q.params.key = key;
|
||||
if (q.executeStep())
|
||||
return q.row.value;
|
||||
return defaultValue;
|
||||
},
|
||||
set: function(key, value) {
|
||||
var conn = this.getDB();
|
||||
var q = conn.createStatement("INSERT OR REPLACE INTO setting values (:key, :value)");
|
||||
q.params.key = key;
|
||||
q.params.value = value;
|
||||
q.executeStep();
|
||||
},
|
||||
setTimeout: function(callback, timeout) {
|
||||
var timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
|
||||
timer.initWithCallback(callback, timeout, Ci.nsITimer.TYPE_ONE_SHOT);
|
||||
|
@ -46,6 +62,19 @@ let ox = {
|
|||
}
|
||||
return array;
|
||||
},
|
||||
makeRandomString: function(len) {
|
||||
var s = "";
|
||||
var table = [
|
||||
'a','b','c','d','e','f','g','h','i','j',
|
||||
'k','l','m','n','o','p','q','r','s','t',
|
||||
'u','v','w','x','y','z','0','1','2','3',
|
||||
'4','5','6','7','8','9'
|
||||
];
|
||||
for(var i=0;i<len;i++) {
|
||||
s += table[parseInt(Math.random() * table.length)];
|
||||
}
|
||||
return s;
|
||||
},
|
||||
subprocess: function(command, options, callback) {
|
||||
if(!this.ipcService) {
|
||||
this.ipcService = Cc["@mozilla.org/process/ipc-service;1"]
|
||||
|
|
Loading…
Reference in a new issue