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