login.py :  » Network » rwhois.py » releaseforge-0.5 » modules » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Network » rwhois.py 
rwhois.py » releaseforge 0.5 » modules » login.py
#!/usr/bin/env python

from qt import *
from loginBA import LoginBA
from workerThread import WorkerThread
import logging
from constants import EVENT_LOGIN
from messageQueue import mainMessageQueue
from loginSettings import LoginSettings
import os
from help import Help
try:
    from base64 import b32encode,b32decode
except ImportError:
    from python24.base64 import b32encode,b32decode


debug = logging.getLogger("login").debug
error = logging.getLogger("login").error

class Login(LoginBA):
    def __init__(self, parent, data_path, sf, *args):
        apply(LoginBA.__init__,(self,) + args)
        self.parent = parent
        self.data_path = data_path
        
        self.settings = LoginSettings(data_path)
        username = self.settings['sf_username']
        password = self.settings['sf_password']
        try:
            if password: password = b32decode(password)
        except:
            QMessageBox.warning(self, "Password Reset",
                                "Could not decode your saved password."
                                "You will need to re-enter it.")
            password = ""
        
        
        self.usernameLineEdit.setText(username)
        self.passwordLineEdit.setText(password)
        rememberMe = self.settings['sf_remember_password']
        if rememberMe.lower() in ('1', 'true'):
            self.rememberCheckBox.setChecked(True)
        self.sf = sf
        self.thread = None
        self.show()
        
        if username and password: self.buttonOk.setFocus()
        elif username: self.passwordLineEdit.setFocus()



    def customEvent(self, event):
        if event.type() != EVENT_LOGIN: return
        
        projects = event.data()
        debug("customEvent: %s", projects)
        self.setCursor(Qt.arrowCursor)
        self.parent.statusBar().clear()
        self.setEnabled(True)
        #self.parent.setCursor(Qt.arrowCursor)
        if not projects:
            QMessageBox.critical(self, "Login Failed",
                                 "Unable to login to SourceForge.\n"
                                 "Please verify your username and password.")
            self.enableElements()
            return

        settings = self.settings
        settings['sf_username'] = self.username
        settings['sf_remember_password'] = self.remember
        if self.remember:
            settings['sf_password'] = b32encode(self.password)
        else:
            settings['sf_password'] = ""

        settings.saveSettings()
            
        self.parent.emit(PYSIGNAL('projects_fetched()'), (projects,) )
        LoginBA.accept(self)


    def __del__(self):
        if self.thread:
            t = self.thread
            running = t.running()
            t.stop()
            if not t.finished():
                t.wait()

    def help(self):
        self._help = Help(self, "login.html")
        

    def disableElements(self):
        self.enableElements(0)


    def enableElements(self, enable=1):
        self.usernameLineEdit.setEnabled(enable)
        self.passwordLineEdit.setEnabled(enable)
        self.rememberCheckBox.setEnabled(enable)
        self.buttonOk.setEnabled(enable)

        
    def reject(self):
        if self.thread: self.thread.stop()
        mainMessageQueue.put("Sourceforge login cancelled")
        LoginBA.reject(self)
        
        
    def accept(self):
        self.username = str(self.usernameLineEdit.text())
        self.password = str(self.passwordLineEdit.text())
        self.remember = str(self.rememberCheckBox.isChecked()) # True/False

        if not self.username or not self.password:
            QMessageBox.critical(self, "Login Failed",
                                 "You must supply a valid username and password.\n")
            return
        self.setCursor(Qt.waitCursor)
        mainMessageQueue.put("Authenticating user")

        self.disableElements()
        
        self.thread = WorkerThread(self,
                                   EVENT_LOGIN,
                                   self.sf.initialize,
                                   self.username,
                                   self.password)
        self.thread.start()

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.