diff options
| author | Guillaume Horel <guillaume.horel@gmail.com> | 2011-05-04 01:07:58 -0400 |
|---|---|---|
| committer | Guillaume Horel <guillaume.horel@gmail.com> | 2011-05-04 01:07:58 -0400 |
| commit | e85fffabbb61ca964f35561e00c382a180166f64 (patch) | |
| tree | ef6ced333ad2bac6c78567d9247fc07c249dfb03 /server/xep_0077.py | |
| parent | 312583b52777046637c942f840ae77e9bd4175ad (diff) | |
| download | alias-e85fffabbb61ca964f35561e00c382a180166f64.tar.gz | |
Registration should be fully functional now.
this fixes #7
Diffstat (limited to 'server/xep_0077.py')
| -rw-r--r-- | server/xep_0077.py | 38 |
1 files changed, 19 insertions, 19 deletions
diff --git a/server/xep_0077.py b/server/xep_0077.py index 6018c55..fa5ddfe 100644 --- a/server/xep_0077.py +++ b/server/xep_0077.py @@ -18,7 +18,7 @@ class Registration(ElementBase): namespace = 'jabber:iq:register' name = 'query' plugin_attrib = 'register' - interfaces = set(('registered', 'remove', 'instructions')) + interfaces = set(('registered', 'remove', 'instructions', 'form')) sub_interfaces = interfaces subitem = (Form,) @@ -46,14 +46,18 @@ class Registration(ElementBase): itemXML = ET.Element('{%s}%s' % (self.namespace, name)) self.xml.append(itemXML) - def add_form(self, values=None): - aliasform = Form(None,self) + def add_form(self): + aliasform = Form(None, self) aliasform.addField(ftype="hidden",var="FORM_TYPE",value=self.namespace) aliasform.addField(var="pubkey",ftype="text-single", label="Public Key", required=True) aliasform.addField(var="privkey",ftype="text-single", label="Private Key", required=True) aliasform.addField(var="salt",ftype="text-single", label="Salt", required=True) - if values: - aliasform.setValues(values) + + def get_form(self): + return Form(self.xml.find('{jabber:x:data}x')) + + def set_form(self, values): + self.get_form().setValues(values) class xep_0077(base_plugin): """ @@ -90,19 +94,17 @@ class xep_0077(base_plugin): iq.reply().send() return - aliasforms = iq['register']['substanzas'] - for aliasform in aliasforms: - aliasdict = aliasform.getValues() + registration_form = iq['register']['form'] + registration_info = registration_form.getValues() for field in self.form_fields: - if not aliasdict[field]: + if not registration_info[field]: # Incomplete Registration self._send_error(iq, '406', 'modify', 'not-acceptable', "Please fill in all fields.") return try: - print aliasdict - registrant.register(aliasdict) + registrant.register(registration_info) # Successful registration #self.xmpp.event('registered_user', iq) iq.reply().setPayload(iq['register'].xml) @@ -122,14 +124,13 @@ class xep_0077(base_plugin): def send_registration_form(self, iq, registrant): reg = iq['register'] + reg.add_form() if self.form_instructions: reg['instructions'] = self.form_instructions if registrant.registered(): - print "yoyoyo" - print registrant.get_registration() reg['registered'] = True - reg.add_form(registrant.get_registration()) + reg['form'] = registrant.get_registration() else: reg.add_form() @@ -148,8 +149,7 @@ class xep_0077(base_plugin): if __name__=='__main__': test = Registration() test.add_form() - test['registered']=True - print test - #why doesn't this work? - form = test.xml.findall('{jabber:x:data}x') - print form + print '{}\n'.format(test['form']) + values = {'privkey': 'pomme', 'pubkey': 'poire', 'salt': 'abricot'} + test['form']=values + print test
\ No newline at end of file |
