Changeset e837493


Ignore:
Timestamp:
04/27/2009 01:01:20 PM (16 years ago)
Author:
Damien Churchill <damoc@gmail.com>
Branches:
2.0.x, develop, extjs4-port, master
Children:
204f055
Parents:
c4cdd7
Message:

add basic session support

Location:
deluge/ui/web
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • deluge/ui/web/js/Deluge.Login.js

    rc4cdd7 re837493  
    2424(function(){
    2525        Ext.deluge.LoginWindow = Ext.extend(Ext.Window, {
     26               
     27                firstShow: true,
     28               
    2629                constructor: function(config) {
    2730                        config = Ext.apply({
     
    4649                        Deluge.Events.on('logout', this.onLogout, this);
    4750                        this.on('show', this.onShow, this);
     51                        this.on('beforeshow', this.onBeforeShow, this);
    4852                       
    4953                        this.addButton({
     
    8387                        Deluge.Client.web.login(passwordField.getValue(), {
    8488                                success: function(result) {
    85                                         if (result == true) {
     89                                        if (result) {
    8690                                                Deluge.Events.fire('login');
    8791                                                this.hide();
    8892                                                passwordField.setRawValue('');
     93                                                Deluge.UI.cookies.set("session", result);
    8994                                        } else {
    9095                                                Ext.MessageBox.show({
     
    106111               
    107112                onLogout: function() {
    108                         this.show();
     113                        var session = Deluge.UI.cookies.get("session", false);
     114                        if (session) {
     115                                Deluge.Client.web.delete_session(session, {
     116                                        success: function(result) {
     117                                                Deluge.UI.cookies.set("session", false);
     118                                                this.show();
     119                                        },
     120                                        scope: this
     121                                });
     122                        }
     123                },
     124               
     125                onBeforeShow: function() {
     126                        var session = Deluge.UI.cookies.get("session", false);
     127                        if (session) {
     128                                Deluge.Client.web.check_session(session, {
     129                                        success: function(result) {
     130                                                if (result) {
     131                                                        Deluge.Events.fire('login');
     132                                                        this.loginForm.items.get('password').setRawValue('');
     133                                                        this.hide();
     134                                                } else {
     135                                                        Deluge.UI.cookies.set("session", false);
     136                                                        this.show();
     137                                                }
     138                                        },
     139                                        failure: function(result) {
     140                                                Deluge.UI.cookies.set("session", false);
     141                                                this.show();
     142                                        },
     143                                        scope: this
     144                                });
     145                                return false;
     146                        }
    109147                },
    110148               
  • deluge/ui/web/js/Deluge.UI.js

    rc4cdd7 re837493  
    5050                });
    5151               
    52                 Deluge.Login.show();
    53                
    5452                Deluge.Events.on("connect", this.onConnect, this);
    5553                Deluge.Events.on("disconnect", this.onDisconnect, this);
    56                 Deluge.Client = new Ext.ux.util.RpcClient({url: '/json'});
     54                Deluge.Client = new Ext.ux.util.RpcClient({
     55                        url: '/json'
     56                });
     57                Deluge.Client.on('connected', function(e) {
     58                        Deluge.Login.show();
     59                });
    5760                this.update = this.update.bind(this);
    5861        },
  • deluge/ui/web/json_api.py

    rc4cdd7 re837493  
    2626import time
    2727import base64
     28import random
    2829import urllib
    2930import hashlib
     
    428429        return d
    429430   
     431    def _create_session(self, login='admin'):
     432        m = hashlib.md5()
     433        m.update(login)
     434        m.update(str(time.time()))
     435        m.update(str(random.getrandbits(999)))
     436        m.update(m.hexdigest())
     437        session_id = m.hexdigest()
     438       
     439        config = component.get("DelugeWeb").config
     440        config["sessions"][session_id] = {
     441            "login": login
     442        }
     443        return session_id
     444   
     445    @export
     446    def check_session(self, session_id):
     447        d = Deferred()
     448        config = component.get("DelugeWeb").config
     449        d.callback(session_id in config["sessions"])
     450        return d
     451   
     452    @export
     453    def delete_session(self, session_id):
     454        d = Deferred()
     455        config = component.get("DelugeWeb").config
     456        del config["sessions"][session_id]
     457        d.callback(True)
     458        return d
     459   
    430460    @export
    431461    def login(self, password):
     
    437467        m.update(password)
    438468        d = Deferred()
    439         d.callback(m.hexdigest() == config['pwd_md5'])
     469        if m.hexdigest() == config['pwd_md5']:
     470            # Change this to return a session id
     471            d.callback(self._create_session())
     472        else:
     473            d.callback(False)
    440474        return d
    441475   
  • deluge/ui/web/server.py

    rc4cdd7 re837493  
    2727import locale
    2828import shutil
     29import signal
    2930import urllib
    3031import gettext
     
    7273    "pwd_md5": "2c9baa929ca38fb5c9eb5b054474d1ce",
    7374    "base": "",
    74     "sessions": [],
     75    "sessions": {},
    7576    "sidebar_show_zero": False,
    7677    "sidebar_show_trackers": False,
Note: See TracChangeset for help on using the changeset viewer.