#include <registration.h>
Inherits IqHandler.
Inheritance diagram for Registration:
Public Types | |
enum | fieldEnum |
Public Member Functions | |
Registration (ClientBase *parent, const JID &to) | |
Registration (ClientBase *parent) | |
virtual | ~Registration () |
void | fetchRegistrationFields () |
void | createAccount (int fields, const fieldStruct &values) |
void | createAccount (const DataForm &form) |
void | removeAccount () |
void | changePassword (const std::string &username, const std::string &password) |
void | registerRegistrationHandler (RegistrationHandler *rh) |
void | removeRegistrationHandler () |
virtual bool | handleIq (Stanza *stanza) |
virtual bool | handleIqID (Stanza *stanza, int context) |
Classes | |
struct | fieldStruct |
Derive your object from RegistrationHandler and implement the virtual functions offered by that interface. Then use it like this:
void MyClass::myFunc() { m_client = new Client( "example.org" ); m_client->disableRoster(); // a roster is not necessary for registration m_client->disableDisco(); // the disco client is not necessary for registration m_client->registerConnectionListener( this ); m_reg = new Registration( c ); m_reg->registerRegistrationHandler( this ); m_client->connect(); } void MyClass::onConnect() { m_reg->fetchRegistrationFields(); }
In RegistrationHandler::handleRegistrationFields() you should check which information the server requires to open a new account. You might not always get away with just username and password. Then call createAccount() with a filled-in fieldStruct and an int
representing the bit-wise ORed fields you want to have included in the registration attempt. For your convenience you can use the 'fields' argument of handleRegistrationFields(). ;) It's your responsibility to make sure at least those fields the server requested are filled in.
Check tests/register_test.cpp
for an example.
Definition at line 68 of file registration.h.
enum fieldEnum |
The possible fields of a JEP-0077 account registration.
Definition at line 99 of file registration.h.
Registration | ( | ClientBase * | parent, | |
const JID & | to | |||
) |
Constructor.
parent | The ClientBase which is used for establishing a connection. | |
to | The server or service to register with. If empty the currently connected server will be used. |
Definition at line 23 of file registration.cpp.
Registration | ( | ClientBase * | parent | ) |
Constructor. Registration will be attempted with the ClientBase's connected host.
parent | The ClientBase which is used for establishing a connection. |
Definition at line 30 of file registration.cpp.
~Registration | ( | ) | [virtual] |
Virtual destructor.
Definition at line 37 of file registration.cpp.
void fetchRegistrationFields | ( | ) |
Use this function to request the registration fields the server requires. The required fields are returned asynchronously to the object registered as RegistrationHandler by calling RegistrationHandler::handleRegistrationFields().
Definition at line 43 of file registration.cpp.
void createAccount | ( | int | fields, | |
const fieldStruct & | values | |||
) |
Attempts to register an account with the given credentials. Only the fields OR'ed in fields
will be sent. This can only be called with an unauthenticated parent (Client).
fields | The fields to use to generate the registration request. OR'ed fieldEnum values. | |
values | The struct contains the values which shall be used for the registration. |
Definition at line 62 of file registration.cpp.
void createAccount | ( | const DataForm & | form | ) |
Attempts to register an account with the given credentials. This can only be called with an unauthenticated parent (Client).
form | The DataForm containing the registration credentials. |
Definition at line 114 of file registration.cpp.
void removeAccount | ( | ) |
Tells the server to remove the currently authenticated account from the server.
Definition at line 134 of file registration.cpp.
void changePassword | ( | const std::string & | username, | |
const std::string & | password | |||
) |
Tells the server to change the password for the current account.
password | The new password. | |
username | The username to change the password for. You might want to use Client::username() to get the current prepped username. |
Definition at line 155 of file registration.cpp.
void registerRegistrationHandler | ( | RegistrationHandler * | rh | ) |
Registers the given rh
as RegistrationHandler. Only one handler is possible at a time.
rh | The RegistrationHandler to register. |
Definition at line 176 of file registration.cpp.
void removeRegistrationHandler | ( | ) |
Un-registers the current RegistrationHandler.
Definition at line 181 of file registration.cpp.
bool handleIq | ( | Stanza * | stanza | ) | [virtual] |
Reimplement this function if you want to be notified about incoming IQs.
stanza | The complete Stanza. |
Implements IqHandler.
Definition at line 186 of file registration.cpp.
bool handleIqID | ( | Stanza * | stanza, | |
int | context | |||
) | [virtual] |
Reimplement this function if you want to be notified about incoming IQs with a specific value of the id
attribute. You have to enable tracking of those IDs using Client::trackID()
. This is usually useful for IDs that generate a positive reply, i.e. <iq type='result' id='reg'/> where a namespace filter wouldn't work.
stanza | The complete Stanza. | |
context | A value to restore context, stored with ClientBase::trackID(). |
Implements IqHandler.
Definition at line 226 of file registration.cpp.