From 0b3a04dc6c7c8e10335f5858b4e500306639b8e2 Mon Sep 17 00:00:00 2001 From: Damien Churchill Date: Wed, 11 Feb 2009 23:55:59 +0000 Subject: [PATCH] add a basic login system --- deluge/ui/web/index.html | 1 + deluge/ui/web/js/deluge-bars.js | 4 +-- deluge/ui/web/js/deluge-login.js | 44 ++++++++++++++++++++++++++++++++ deluge/ui/web/js/deluge-ui.js | 20 +++++++-------- deluge/ui/web/server.py | 7 +++-- 5 files changed, 62 insertions(+), 14 deletions(-) create mode 100644 deluge/ui/web/js/deluge-login.js diff --git a/deluge/ui/web/index.html b/deluge/ui/web/index.html index e5d0f2913..b0bab314c 100644 --- a/deluge/ui/web/index.html +++ b/deluge/ui/web/index.html @@ -15,6 +15,7 @@ + diff --git a/deluge/ui/web/js/deluge-bars.js b/deluge/ui/web/js/deluge-bars.js index 751052638..4e635e950 100644 --- a/deluge/ui/web/js/deluge-bars.js +++ b/deluge/ui/web/js/deluge-bars.js @@ -118,7 +118,7 @@ Deluge.SideBar = { Deluge.StatusBar = new Ext.StatusBar({ statusAlign: 'left', - items: [{ + /*items: [{ id: 'statusbar-connections', text: '200 (200)', cls: 'x-btn-text-icon', @@ -146,5 +146,5 @@ Deluge.StatusBar = new Ext.StatusBar({ text: '161', cls: 'x-btn-text-icon', icon: '/icons/16/dht.png' - }] + }]*/ }); \ No newline at end of file diff --git a/deluge/ui/web/js/deluge-login.js b/deluge/ui/web/js/deluge-login.js new file mode 100644 index 000000000..97991dd9d --- /dev/null +++ b/deluge/ui/web/js/deluge-login.js @@ -0,0 +1,44 @@ +Deluge.Login = { + Form: new Ext.form.FormPanel({ + defaultType: 'textfield', + id: 'loginForm', + baseCls: 'x-plain', + labelWidth: 55, + items: [{ + fieldLabel: 'Password', + id: 'password', + name: 'password', + inputType: 'password', + anchor: '100%' + }] + }), + + onLogin: function() { + var passwordField = Deluge.Login.Form.items.get('password'); + Deluge.Client.web.login(passwordField.getValue(), { + onSuccess: function(result) { + if (result == true) { + Deluge.Login.Window.hide(); + } + } + }); + } +} + +Deluge.Login.Window = new Ext.Window({ + layout: 'fit', + width: 300, + height: 150, + bodyStyle: 'padding: 10px 5px;', + buttonAlign: 'center', + closeAction: 'hide', + closable: false, + modal: true, + plain: true, + title: 'Login', + items: Deluge.Login.Form, + buttons: [{ + text: 'Login', + handler: Deluge.Login.onLogin + }] +}); \ No newline at end of file diff --git a/deluge/ui/web/js/deluge-ui.js b/deluge/ui/web/js/deluge-ui.js index 7228519bf..3233c80fa 100644 --- a/deluge/ui/web/js/deluge-ui.js +++ b/deluge/ui/web/js/deluge-ui.js @@ -1,9 +1,7 @@ Deluge.Ui = { initialize: function() { - Deluge.Client = new JSON.RPC('/json'); this.errorCount = 0; Ext.state.Manager.setProvider(new Ext.state.CookieProvider()); - this.MainPanel = new Ext.Panel({ id: 'mainPanel', title: 'Deluge', @@ -12,20 +10,23 @@ Deluge.Ui = { items: [Deluge.SideBar, Deluge.Details, Deluge.Torrents], bbar: Deluge.StatusBar }); - - Deluge.SideBar = this.MainPanel.items.get('sidebar'); - Deluge.SideBar.on('collapse', function(bar) { - - //alert(JSON.encode($('sidebar').getSize())); - }); - + this.Viewport = new Ext.Viewport({ layout: 'fit', items: [this.MainPanel] }); + + Deluge.Login.Window.show(); + Deluge.Client = new JSON.RPC('/json'); + Deluge.Details.Status.items.get("status-details").load({ url: "/render/tab_statistics.html" }); + + Deluge.SideBar = this.MainPanel.items.get('sidebar'); + Deluge.SideBar.on('collapse', function(bar) { + + }); }, update: function() { @@ -178,5 +179,4 @@ Deluge.Ui = { document.addEvent('domready', function(e) { Deluge.Ui.initialize(); - Deluge.Ui.run(); }); \ No newline at end of file diff --git a/deluge/ui/web/server.py b/deluge/ui/web/server.py index 0413813ee..80fd5c6e9 100644 --- a/deluge/ui/web/server.py +++ b/deluge/ui/web/server.py @@ -124,7 +124,8 @@ class JSON(resource.Resource): "web.update_ui": self.update_ui, "web.download_torrent_from_url": self.download_torrent_from_url, "web.get_torrent_info": self.get_torrent_info, - "web.add_torrents": self.add_torrents + "web.add_torrents": self.add_torrents, + "web.login": self.login } for entry in open(common.get_default_config_dir("auth")): parts = entry.split(":") @@ -355,7 +356,9 @@ class JSON(resource.Resource): m = hashlib.md5() m.update(config['pwd_salt']) m.update(password) - return (m.digest() == config['pwd_md5']) + d = Deferred() + d.callback(m.digest() == config['pwd_md5']) + return d class GetText(resource.Resource):