Author: damoxc
Revision: 5181
Log:
add basic session support
Diff:
Modified: trunk/deluge/ui/web/js/Deluge.Login.js
===================================================================
--- trunk/deluge/ui/web/js/Deluge.Login.js 2009-04-27 12:55:42 UTC (rev
5180)
+++ trunk/deluge/ui/web/js/Deluge.Login.js 2009-04-27 13:01:20 UTC (rev
5181)
@@ -23,6 +23,9 @@
(function(){
Ext.deluge.LoginWindow = Ext.extend(Ext.Window, {
+
+ firstShow: true,
+
constructor: function(config) {
config = Ext.apply({
layout: 'fit',
@@ -45,6 +48,7 @@
Ext.deluge.LoginWindow.superclass.initComponent.call(this);
Deluge.Events.on('logout', this.onLogout, this);
this.on('show', this.onShow, this);
+ this.on('beforeshow', this.onBeforeShow, this);
this.addButton({
text: _('Login'),
@@ -82,10 +86,11 @@
var passwordField =
this.loginForm.items.get('password');
Deluge.Client.web.login(passwordField.getValue(), {
success: function(result) {
- if (result == true) {
+ if (result) {
Deluge.Events.fire('login');
this.hide();
passwordField.setRawValue('');
+
Deluge.UI.cookies.set("session", result);
} else {
Ext.MessageBox.show({
title: _('Login
Failed'),
@@ -105,9 +110,42 @@
},
onLogout: function() {
- this.show();
+ var session = Deluge.UI.cookies.get("session", false);
+ if (session) {
+ Deluge.Client.web.delete_session(session, {
+ success: function(result) {
+
Deluge.UI.cookies.set("session", false);
+ this.show();
+ },
+ scope: this
+ });
+ }
},
+ onBeforeShow: function() {
+ var session = Deluge.UI.cookies.get("session", false);
+ if (session) {
+ Deluge.Client.web.check_session(session, {
+ success: function(result) {
+ if (result) {
+
Deluge.Events.fire('login');
+
this.loginForm.items.get('password').setRawValue('');
+ this.hide();
+ } else {
+
Deluge.UI.cookies.set("session", false);
+ this.show();
+ }
+ },
+ failure: function(result) {
+
Deluge.UI.cookies.set("session", false);
+ this.show();
+ },
+ scope: this
+ });
+ return false;
+ }
+ },
+
onShow: function() {
var passwordField =
this.loginForm.items.get('password');
passwordField.focus(false, 150);
Modified: trunk/deluge/ui/web/js/Deluge.UI.js
===================================================================
--- trunk/deluge/ui/web/js/Deluge.UI.js 2009-04-27 12:55:42 UTC (rev 5180)
+++ trunk/deluge/ui/web/js/Deluge.UI.js 2009-04-27 13:01:20 UTC (rev 5181)
@@ -49,11 +49,14 @@
items: [this.MainPanel]
});
- Deluge.Login.show();
-
Deluge.Events.on("connect", this.onConnect, this);
Deluge.Events.on("disconnect", this.onDisconnect, this);
- Deluge.Client = new Ext.ux.util.RpcClient({url: '/json'});
+ Deluge.Client = new Ext.ux.util.RpcClient({
+ url: '/json'
+ });
+ Deluge.Client.on('connected', function(e) {
+ Deluge.Login.show();
+ });
this.update = this.update.bind(this);
},
Modified: trunk/deluge/ui/web/json_api.py
===================================================================
--- trunk/deluge/ui/web/json_api.py 2009-04-27 12:55:42 UTC (rev 5180)
+++ trunk/deluge/ui/web/json_api.py 2009-04-27 13:01:20 UTC (rev 5181)
@@ -25,6 +25,7 @@
import os
import time
import base64
+import random
import urllib
import hashlib
import logging
@@ -427,7 +428,36 @@
d.callback(True)
return d
+ def _create_session(self, login='admin'):
+ m = hashlib.md5()
+ m.update(login)
+ m.update(str(time.time()))
+ m.update(str(random.getrandbits(999)))
+ m.update(m.hexdigest())
+ session_id = m.hexdigest()
+
+ config = component.get("DelugeWeb").config
+ config["sessions"][session_id] = {
+ "login": login
+ }
+ return session_id
+
@export
+ def check_session(self, session_id):
+ d = Deferred()
+ config = component.get("DelugeWeb").config
+ d.callback(session_id in config["sessions"])
+ return d
+
+ @export
+ def delete_session(self, session_id):
+ d = Deferred()
+ config = component.get("DelugeWeb").config
+ del config["sessions"][session_id]
+ d.callback(True)
+ return d
+
+ @export
def login(self, password):
"""Method to allow the webui to authenticate
"""
@@ -436,7 +466,11 @@
m.update(config['pwd_salt'])
m.update(password)
d = Deferred()
- d.callback(m.hexdigest() == config['pwd_md5'])
+ if m.hexdigest() == config['pwd_md5']:
+ # Change this to return a session id
+ d.callback(self._create_session())
+ else:
+ d.callback(False)
return d
@export
Modified: trunk/deluge/ui/web/server.py
===================================================================
--- trunk/deluge/ui/web/server.py 2009-04-27 12:55:42 UTC (rev 5180)
+++ trunk/deluge/ui/web/server.py 2009-04-27 13:01:20 UTC (rev 5181)
@@ -26,6 +26,7 @@
import time
import locale
import shutil
+import signal
import urllib
import gettext
import hashlib
@@ -71,7 +72,7 @@
"pwd_salt": "16f65d5c79b7e93278a28b60fed2431e",
"pwd_md5": "2c9baa929ca38fb5c9eb5b054474d1ce",
"base": "",
- "sessions": [],
+ "sessions": {},
"sidebar_show_zero": False,
"sidebar_show_trackers": False,
"show_keyword_search": False,
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"deluge-commit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/deluge-commit?hl=en
-~----------~----~----~----~------~----~------~--~---