How does Spark check user before creating new account?

Looking at Spark client’s source code, I found that the creation of account in AccountCreationWizard is as simple as this:

final AccountManager accountManager = new AccountManager(connection);

accountManager.createAccount(getUsername(), getPassword());

And if the user exist a error code 409 (“User name already exist.”) is thrown, however, in my java app which use smack api with the same way to create account, XMPPException is not thrown and thus, a username is overwriten as a user creates a account,

I wonder why in the Spark client code exception is thrown wheras in my java code exceptions is not thrown. Any ideas?

Thanks.

Sounds like an server issue. I would guess that smack just forwards the response from the server and if the server allows an registration of an already taken username by overwriting the account then smack will not throw an Exception.

Flow

What i do (tho probably not the best way?) is first sign in anonymously and then do a user search. If any of the users returned match…then u know theres already an account for the given name lol.

You just do it the same way Spark does. According to this post on Stackoverflow, this is what the OP found the day after this was posted. I am guessing that it was just a coding error.

Apparently as with my stackoverflow.com post for this, AccountManager class createAccount function does all the job of checking the username if it exist or not, throwing XMPPError code 409 when user exist. The problem with my code is that I was not able to catch this error thus my GUI front-end, so it always shows that account is created everytime, although in reality the account is not overriden.

Yes, its a coding error. Thus I do not have to use UserSearchManager, just use AccountManager class. However lately I am getting a feel that I need to have to use UserSearchManager because during registration process (i.e. createAccount() ) the client needs to check whether a certain user attribute already exist in the system, say email address attribute, so registration should not proceed if such email address has been registered already by a certain user. However I cannot find a comprehensive samples using UserSearchManager.

1 Like