Optional login/password in account
Remove login/password related attribut in Account class but still support live password if account_class in component has correct attributs. darcs-hash:20061025182516-86b55-4743189d47ba481692f16ff52f8b50903df49689.gz
This commit is contained in:
@@ -479,7 +479,9 @@ class JCLComponent(Component):
|
||||
accounts = self.account_class.select(\
|
||||
self.account_class.q.user_jid == base_from_jid \
|
||||
and self.account_class.q.name == name)
|
||||
if re.compile("\[PASSWORD\]").search(message.get_subject()) \
|
||||
if hasattr(self.account_class, 'password') \
|
||||
and hasattr(self.account_class, 'waiting_password_reply') \
|
||||
and re.compile("\[PASSWORD\]").search(message.get_subject()) \
|
||||
is not None \
|
||||
and accounts.count() == 1:
|
||||
account = list(accounts)[0]
|
||||
@@ -512,7 +514,9 @@ class JCLComponent(Component):
|
||||
show = show, \
|
||||
stanza_type = "available")
|
||||
self.stream.send(p)
|
||||
if _account.store_password == False \
|
||||
if hasattr(self.account_class, 'store_password') \
|
||||
and hasattr(self.account_class, 'password') \
|
||||
and _account.store_password == False \
|
||||
and old_status == account.OFFLINE \
|
||||
and _account.password == None :
|
||||
self._ask_password(_account, lang_class)
|
||||
@@ -520,7 +524,8 @@ class JCLComponent(Component):
|
||||
def _ask_password(self, _account, lang_class):
|
||||
"""Send a Jabber message to ask for account password
|
||||
"""
|
||||
if not _account.waiting_password_reply \
|
||||
if hasattr(self.account_class, 'waiting_password_reply') \
|
||||
and not _account.waiting_password_reply \
|
||||
and _account.status != account.OFFLINE:
|
||||
_account.waiting_password_reply = True
|
||||
msg = Message(from_jid = _account.jid, \
|
||||
|
||||
@@ -32,8 +32,8 @@ from sqlobject.dbconnection import ConnectionHub
|
||||
|
||||
from jcl.lang import Lang
|
||||
|
||||
OFFLINE = 0
|
||||
ONLINE = 1
|
||||
OFFLINE = "offline"
|
||||
ONLINE = "online"
|
||||
|
||||
# create a hub to attach a per thread connection
|
||||
hub = ConnectionHub()
|
||||
@@ -45,14 +45,16 @@ class Account(SQLObject):
|
||||
user_jid = StringCol()
|
||||
name = StringCol()
|
||||
jid = StringCol()
|
||||
login = StringCol(default = "")
|
||||
password = StringCol(default = None)
|
||||
store_password = BoolCol(default = True)
|
||||
## Not yet used first_check = BoolCol(default = True)
|
||||
__status = StringCol(default = OFFLINE, dbName = "status")
|
||||
|
||||
## Use these attributs to support volatile password
|
||||
## login = StringCol(default = "")
|
||||
## password = StringCol(default = None)
|
||||
## store_password = BoolCol(default = True)
|
||||
## waiting_password_reply = BoolCol(default = False)
|
||||
|
||||
default_lang_class = Lang.en
|
||||
first_check = True
|
||||
__status = OFFLINE
|
||||
waiting_password_reply = False
|
||||
|
||||
def get_long_name(self):
|
||||
"""Return Human readable account name"""
|
||||
@@ -73,10 +75,15 @@ class Account(SQLObject):
|
||||
def set_status(self, status):
|
||||
"""Set current Jabber status"""
|
||||
if status == OFFLINE:
|
||||
if hasattr(self.__class__, 'waiting_password_reply') \
|
||||
and hasattr(self.__class__, 'store_password') \
|
||||
and hasattr(self.__class__, 'password'):
|
||||
self.waiting_password_reply = False
|
||||
if not self.store_password:
|
||||
self.password = None
|
||||
else:
|
||||
# TODO seems a bug : first_check = True only if previous status
|
||||
# was OFFLINE
|
||||
self.first_check = True
|
||||
self.__status = status
|
||||
|
||||
|
||||
@@ -422,27 +422,57 @@ class JCLComponent_TestCase(unittest.TestCase):
|
||||
from_jid = "user1@test.com",\
|
||||
to_jid = "account11@jcl.test.com"))
|
||||
messages_sent = self.comp.stream.sent
|
||||
self.assertEqual(len(messages_sent), 2)
|
||||
password_message = None
|
||||
presence = None
|
||||
for message in messages_sent:
|
||||
if isinstance(message, Message):
|
||||
password_message = message
|
||||
elif isinstance(message, Presence):
|
||||
presence = message
|
||||
self.assertTrue(password_message is not None)
|
||||
self.assertEqual(len(messages_sent), 1)
|
||||
presence = messages_sent[0]
|
||||
self.assertTrue(presence is not None)
|
||||
self.assertEqual(presence.get_show(), "online")
|
||||
self.assertEqual(presence.get_from_jid(), "account11@jcl.test.com")
|
||||
self.assertEqual(presence.get_to_jid(), "user1@test.com")
|
||||
|
||||
self.assertEqual(unicode(password_message.get_from_jid()), \
|
||||
"account11@jcl.test.com")
|
||||
self.assertEqual(unicode(password_message.get_to_jid()), \
|
||||
"user1@test.com")
|
||||
self.assertEqual(password_message.get_subject(), \
|
||||
"[PASSWORD] Password request")
|
||||
self.assertEqual(password_message.get_body(), None)
|
||||
# Use it in real live password implementation
|
||||
# def test_handle_presence_available_to_account_live_password(self):
|
||||
# self.comp.stream = MockStream()
|
||||
# self.comp.stream_class = MockStream
|
||||
# account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)
|
||||
# account11 = Account(user_jid = "user1@test.com", \
|
||||
# name = "account11", \
|
||||
# jid = "account11@jcl.test.com")
|
||||
# account11.store_password = False
|
||||
# account12 = Account(user_jid = "user1@test.com", \
|
||||
# name = "account12", \
|
||||
# jid = "account12@jcl.test.com")
|
||||
# account2 = Account(user_jid = "user2@test.com", \
|
||||
# name = "account2", \
|
||||
# jid = "account2@jcl.test.com")
|
||||
# del account.hub.threadConnection
|
||||
# ## TODO: "online" exist ?
|
||||
# self.comp.handle_presence_available(Presence(\
|
||||
# stanza_type = "available", \
|
||||
# show = "online", \
|
||||
# from_jid = "user1@test.com",\
|
||||
# to_jid = "account11@jcl.test.com"))
|
||||
# messages_sent = self.comp.stream.sent
|
||||
# self.assertEqual(len(messages_sent), 2)
|
||||
# password_message = None
|
||||
# presence = None
|
||||
# for message in messages_sent:
|
||||
# if isinstance(message, Message):
|
||||
# password_message = message
|
||||
# elif isinstance(message, Presence):
|
||||
# presence = message
|
||||
# self.assertTrue(password_message is not None)
|
||||
# self.assertTrue(presence is not None)
|
||||
# self.assertEqual(presence.get_show(), "online")
|
||||
# self.assertEqual(presence.get_from_jid(), "account11@jcl.test.com")
|
||||
# self.assertEqual(presence.get_to_jid(), "user1@test.com")
|
||||
|
||||
# self.assertEqual(unicode(password_message.get_from_jid()), \
|
||||
# "account11@jcl.test.com")
|
||||
# self.assertEqual(unicode(password_message.get_to_jid()), \
|
||||
# "user1@test.com")
|
||||
# self.assertEqual(password_message.get_subject(), \
|
||||
# "[PASSWORD] Password request")
|
||||
# self.assertEqual(password_message.get_body(), None)
|
||||
|
||||
def test_handle_presence_unavailable_to_component(self):
|
||||
self.comp.stream = MockStream()
|
||||
@@ -615,7 +645,6 @@ class JCLComponent_TestCase(unittest.TestCase):
|
||||
presence_sent[0].xpath_eval("@type")[0].get_content(), \
|
||||
"unavailable")
|
||||
|
||||
|
||||
def test_handle_message_password(self):
|
||||
self.comp.stream = MockStream()
|
||||
self.comp.stream_class = MockStream
|
||||
@@ -637,15 +666,39 @@ class JCLComponent_TestCase(unittest.TestCase):
|
||||
subject = "[PASSWORD]", \
|
||||
body = "secret"))
|
||||
messages_sent = self.comp.stream.sent
|
||||
self.assertEqual(len(messages_sent), 1)
|
||||
self.assertEqual(messages_sent[0].get_to(), "user1@test.com")
|
||||
self.assertEqual(messages_sent[0].get_from(), "account11@jcl.test.com")
|
||||
self.assertEqual(account11.password, "secret")
|
||||
self.assertEqual(account11.waiting_password_reply, False)
|
||||
self.assertEqual(messages_sent[0].get_subject(), \
|
||||
"Password will be kept during your Jabber session")
|
||||
self.assertEqual(messages_sent[0].get_body(), \
|
||||
"Password will be kept during your Jabber session")
|
||||
self.assertEqual(len(messages_sent), 0)
|
||||
|
||||
# TODO Use it with real implementation live password
|
||||
# def test_handle_message_password(self):
|
||||
# self.comp.stream = MockStream()
|
||||
# self.comp.stream_class = MockStream
|
||||
# account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)
|
||||
# account11 = Account(user_jid = "user1@test.com", \
|
||||
# name = "account11", \
|
||||
# jid = "account11@jcl.test.com")
|
||||
# account11.waiting_password_reply = True
|
||||
# account12 = Account(user_jid = "user1@test.com", \
|
||||
# name = "account12", \
|
||||
# jid = "account12@jcl.test.com")
|
||||
# account2 = Account(user_jid = "user2@test.com", \
|
||||
# name = "account2", \
|
||||
# jid = "account2@jcl.test.com")
|
||||
# del account.hub.threadConnection
|
||||
# self.comp.handle_message(Message(\
|
||||
# from_jid = "user1@test.com", \
|
||||
# to_jid = "account11@jcl.test.com", \
|
||||
# subject = "[PASSWORD]", \
|
||||
# body = "secret"))
|
||||
# messages_sent = self.comp.stream.sent
|
||||
# self.assertEqual(len(messages_sent), 1)
|
||||
# self.assertEqual(messages_sent[0].get_to(), "user1@test.com")
|
||||
# self.assertEqual(messages_sent[0].get_from(), "account11@jcl.test.com")
|
||||
# self.assertEqual(account11.password, "secret")
|
||||
# self.assertEqual(account11.waiting_password_reply, False)
|
||||
# self.assertEqual(messages_sent[0].get_subject(), \
|
||||
# "Password will be kept during your Jabber session")
|
||||
# self.assertEqual(messages_sent[0].get_body(), \
|
||||
# "Password will be kept during your Jabber session")
|
||||
|
||||
def test_handle_tick(self):
|
||||
self.assertRaises(NotImplementedError, self.comp.handle_tick)
|
||||
|
||||
Reference in New Issue
Block a user