Merge lp:~stefanor/ibid/accounts-382464 into lp:~ibid-core/ibid/old-trunk-pack-0.92

Proposed by Stefano Rivera
Status: Merged
Approved by: Stefano Rivera
Approved revision: 671
Merged at revision: 683
Proposed branch: lp:~stefanor/ibid/accounts-382464
Merge into: lp:~ibid-core/ibid/old-trunk-pack-0.92
Diff against target: None lines
To merge this branch: bzr merge lp:~stefanor/ibid/accounts-382464
Reviewer Review Type Date Requested Status
Michael Gorven Approve
Jonathan Hitchcock Approve
Review via email: mp+7718@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Jonathan Hitchcock (vhata) :
review: Approve
Revision history for this message
Michael Gorven (mgorven) wrote :

 review approve

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'ibid/plugins/auth.py'
--- ibid/plugins/auth.py 2009-05-31 07:51:10 +0000
+++ ibid/plugins/auth.py 2009-06-20 15:26:47 +0000
@@ -28,7 +28,7 @@
28 if not ibid.auth.authenticate(event):28 if not ibid.auth.authenticate(event):
29 event.complain = 'notauthed'29 event.complain = 'notauthed'
30 return30 return
31 account = event.session.query(Account).filter_by(id=event.account).first()31 account = event.session.query(Account).get(event.account)
3232
33 else:33 else:
34 if not auth_responses(event, 'admin'):34 if not auth_responses(event, 'admin'):
@@ -122,7 +122,7 @@
122 if not event.account:122 if not event.account:
123 event.addresponse(u"I don't know who you are")123 event.addresponse(u"I don't know who you are")
124 return124 return
125 account = event.session.query(Account).filter_by(id=event.account).first()125 account = event.session.query(Account).get(event.account)
126 else:126 else:
127 if not auth_responses(event, u'accounts'):127 if not auth_responses(event, u'accounts'):
128 return128 return
129129
=== modified file 'ibid/plugins/identity.py'
--- ibid/plugins/identity.py 2009-05-05 07:58:29 +0000
+++ ibid/plugins/identity.py 2009-06-20 17:12:43 +0000
@@ -31,7 +31,7 @@
31 if ibid.auth.authenticate(event) and ibid.auth.authorise(event, 'accounts'):31 if ibid.auth.authenticate(event) and ibid.auth.authorise(event, 'accounts'):
32 admin = True32 admin = True
33 else:33 else:
34 account = event.session.query(Account).filter_by(id=event.account).first()34 account = event.session.query(Account).get(event.account)
35 event.addresponse(u'You already have an account called "%s"', account.username)35 event.addresponse(u'You already have an account called "%s"', account.username)
36 return36 return
3737
@@ -61,7 +61,7 @@
61 log.info(u"Attached identity %s (%s on %s) to account %s (%s)",61 log.info(u"Attached identity %s (%s on %s) to account %s (%s)",
62 identity.id, identity.identity, identity.source, account.id, account.username)62 identity.id, identity.identity, identity.source, account.id, account.username)
63 else:63 else:
64 identity = event.session.query(Identity).filter_by(id=event.identity).first()64 identity = event.session.query(Identity).get(event.identity)
65 identity.account_id = account.id65 identity.account_id = account.id
66 event.session.save_or_update(identity)66 event.session.save_or_update(identity)
67 event.session.commit()67 event.session.commit()
@@ -77,7 +77,7 @@
7777
78 if own:78 if own:
79 if event.account:79 if event.account:
80 account = event.session.query(Account).filter_by(id=event.account).first()80 account = event.session.query(Account).get(event.account)
81 else:81 else:
82 event.addresponse(u"You don't have an account")82 event.addresponse(u"You don't have an account")
83 return83 return
@@ -106,7 +106,7 @@
106106
107 if own:107 if own:
108 if event.account:108 if event.account:
109 account = event.session.query(Account).filter_by(id=event.account).first()109 account = event.session.query(Account).get(event.account)
110 else:110 else:
111 event.addresponse(u"You don't have an account")111 event.addresponse(u"You don't have an account")
112 return112 return
@@ -148,36 +148,45 @@
148 def identity(self, event, username, identity, source):148 def identity(self, event, username, identity, source):
149 admin = False149 admin = False
150 identity = identity.replace(' ', '')150 identity = identity.replace(' ', '')
151 reverse_attach = False
151152
152 if username.upper() == 'I':153 if username.upper() == 'I':
153 if event.account:154 if event.account:
154 account = event.session.query(Account).filter_by(id=event.account).first()155 account = event.session.query(Account).get(event.account)
155 else:156 else:
156 username = event.sender['id']157 account = event.session.query(Account) \
157158 .join(Identity.account) \
158 account = event.session.query(Account).filter_by(username=username).first()159 .filter(func.lower(Identity.identity) == identity.lower()) \
159160 .filter(func.lower(Identity.source) == source.lower()).first()
161
160 if account:162 if account:
161 event.addresponse(u'I tried to create the account %s for you, but it already exists. '163 reverse_attach = True
162 u"Please use 'create account <name>'", username)164 else:
163 return165 username = event.sender['id']
164166
165 account = Account(username)167 account = event.session.query(Account).filter_by(username=username).first()
166 event.session.save_or_update(account)168
167169 if account:
168 currentidentity = event.session.query(Identity).filter_by(id=event.identity).first()170 event.addresponse(u'I tried to create the account %s for you, but it already exists. '
169 currentidentity.account_id = account.id171 u"Please use 'create account <name>'", username)
170 event.session.save_or_update(currentidentity)172 return
171173
172 identify_cache.clear()174 account = Account(username)
173175 event.session.save_or_update(account)
174 event.addresponse(u"I've created the account %s for you", username)176
175177 currentidentity = event.session.query(Identity).get(event.identity)
176 event.session.commit()178 currentidentity.account_id = account.id
177 log.info(u"Created account %s (%s) by %s/%s (%s)",179 event.session.save_or_update(currentidentity)
178 account.id, account.username, event.account, event.identity, event.sender['connection'])180
179 log.info(u"Attached identity %s (%s on %s) to account %s (%s)",181 identify_cache.clear()
180 currentidentity.id, currentidentity.identity, currentidentity.source, account.id, account.username)182
183 event.addresponse(u"I've created the account %s for you", username)
184
185 event.session.commit()
186 log.info(u"Created account %s (%s) by %s/%s (%s)",
187 account.id, account.username, event.account, event.identity, event.sender['connection'])
188 log.info(u"Attached identity %s (%s on %s) to account %s (%s)",
189 currentidentity.id, currentidentity.identity, currentidentity.source, account.id, account.username)
181190
182 else:191 else:
183 if not auth_responses(event, 'accounts'):192 if not auth_responses(event, 'accounts'):
@@ -188,9 +197,12 @@
188 event.addresponse(u"I don't know who %s is", username)197 event.addresponse(u"I don't know who %s is", username)
189 return198 return
190199
191 ident = event.session.query(Identity) \200 if reverse_attach:
192 .filter(func.lower(Identity.identity) == identity.lower()) \201 ident = event.session.query(Identity).get(event.identity)
193 .filter(func.lower(Identity.source) == source.lower()).first()202 else:
203 ident = event.session.query(Identity) \
204 .filter(func.lower(Identity.identity) == identity.lower()) \
205 .filter(func.lower(Identity.source) == source.lower()).first()
194 if ident and ident.account:206 if ident and ident.account:
195 event.addresponse(u'This identity is already attached to account %s',207 event.addresponse(u'This identity is already attached to account %s',
196 ident.account.username)208 ident.account.username)
@@ -204,10 +216,20 @@
204216
205 if not admin:217 if not admin:
206 token = ''.join([choice(chars) for i in xrange(16)])218 token = ''.join([choice(chars) for i in xrange(16)])
207 self.tokens[token] = (account.id, identity, source)219 if reverse_attach:
208 response = {'reply': u'Please send me this message from %s on %s: %s' % (identity, source, token)}220 self.tokens[token] = (account.id, ident.identity, ident.source)
209 if event.public:221 response = {
210 response['target'] = event.sender['id']222 'reply': u'Please send me this message from %s on %s: %s' % (ident.identity, ident.source, token),
223 'target': identity,
224 'source': source,
225 }
226 event.addresponse(True)
227 else:
228 self.tokens[token] = (account.id, identity, source)
229 response = {'reply': u'Please send me this message from %s on %s: %s' % (identity, source, token)}
230 if event.public:
231 response['target'] = event.sender['id']
232 event.addresponse(True)
211 event.addresponse(response)233 event.addresponse(response)
212 log.info(u"Sent token %s to %s/%s (%s)",234 log.info(u"Sent token %s to %s/%s (%s)",
213 token, event.account, event.identity, event.sender['connection'])235 token, event.account, event.identity, event.sender['connection'])
@@ -296,7 +318,7 @@
296 if not event.account:318 if not event.account:
297 event.addresponse(u"I don't know who you are")319 event.addresponse(u"I don't know who you are")
298 return320 return
299 account = event.session.query(Account).filter_by(id=event.account).first()321 account = event.session.query(Account).get(event.account)
300 if not account:322 if not account:
301 event.addresponse(u"%s doesn't exist. Please use 'add account' first", username)323 event.addresponse(u"%s doesn't exist. Please use 'add account' first", username)
302 return324 return
303325
=== modified file 'ibid/source/telnet.py'
--- ibid/source/telnet.py 2009-02-23 20:29:44 +0000
+++ ibid/source/telnet.py 2009-06-20 15:57:43 +0000
@@ -6,6 +6,7 @@
66
7import ibid7import ibid
8from ibid.source import IbidSourceFactory8from ibid.source import IbidSourceFactory
9from ibid.config import IntOption
9from ibid.event import Event10from ibid.event import Event
1011
11class TelnetProtocol(telnet.StatefulTelnetProtocol):12class TelnetProtocol(telnet.StatefulTelnetProtocol):
@@ -45,7 +46,7 @@
45class SourceFactory(protocol.ServerFactory, IbidSourceFactory):46class SourceFactory(protocol.ServerFactory, IbidSourceFactory):
46 protocol = TelnetProtocol47 protocol = TelnetProtocol
4748
48 port = 300049 port = IntOption('port', 'Port to listen on', 3000)
4950
50 def __init__(self, name, *args, **kwargs):51 def __init__(self, name, *args, **kwargs):
51 #protocol.ServerFactory.__init__(self, *args, **kwargs)52 #protocol.ServerFactory.__init__(self, *args, **kwargs)

Subscribers

People subscribed via source and target branches