Signup Assistant tells me "Username already in use" ... but it isnt ?

Post here your questions about SFS2X. Here we discuss all server-side matters. For client API questions see the dedicated forums.

Moderators: Lapo, Bax

genar
Posts: 137
Joined: 13 Jul 2017, 11:49

Signup Assistant tells me "Username already in use" ... but it isnt ?

Postby genar » 16 Oct 2018, 18:01

Good evening !

Sooo ... i have no clue what exactly i changed... i implemented the Signup Assistant a few weeks ago, because its thousand times better than what i coded myself... atleast i thought...

Heres my implementation :

Code: Select all

suac = new SignUpAssistantComponent();
        
       suac.getConfig().signUpTable = "players";
       suac.getConfig().usernameField = "Username";
       suac.getConfig().passwordField = "Password";
       suac.getConfig().emailField = "Email";
      
       suac.getConfig().minUserNameLength = 4;
       suac.getConfig().maxUserNameLength = 15;
       suac.getConfig().minPasswordLength = 5;
       suac.getConfig().maxPasswordLength = 30;
          
       suac.getConfig().checkForDuplicateEmails = true;
       suac.getConfig().extraFields = Arrays.asList("Position","Male", "Female", "BuildingColor");
      
       suac.getConfig().errorMessages.put(SignUpErrorCodes.USERNAME_ALREADY_IN_USE, "BadUsername");
       suac.getConfig().errorMessages.put(SignUpErrorCodes.USERNAME_TOO_LONG, "UsernameTooLong");
       suac.getConfig().errorMessages.put(SignUpErrorCodes.USERNAME_TOO_SHORT, "UsernameTooShort");
       suac.getConfig().errorMessages.put(SignUpErrorCodes.PASSWORD_TOO_LONG, "PasswordTooLong");
       suac.getConfig().errorMessages.put(SignUpErrorCodes.PASSWORD_TOO_SHORT, "PasswordToShort");
       suac.getConfig().errorMessages.put(SignUpErrorCodes.EMAIL_ALREADY_IN_USE, "BadEmail");
       suac.getConfig().errorMessages.put(SignUpErrorCodes.INVALID_EMAIL, "InvalidEmail");
      
       suac.getConfig().preProcessPlugin = new ISignUpAssistantPlugin(){
          
         @Override
         public void execute(User user, ISFSObject params, SignUpConfiguration suc) throws SignUpValidationException {
            
            initParams = params;
            
            String location = params.getUtfString("Location");
            String gender = params.getUtfString("Gender");
            String buildingColor = params.getUtfString("BuildingsColor");
   
            double posX = Double.parseDouble(location.split(";")[0]);
            double posY = Double.parseDouble(location.split(";")[1]);
            
            int male = gender == "Male" ? 1 : 0;
            int female = male == 1 ? 0 : 1;
            
            if(posX == 0 && posY == 0){
               
               posX = getRandomInRange(0, 180);
               posY = getRandomInRange(0, 180);
               
            }
            
            location = posX+";"+posY;
            
            params.putUtfString("Position", location);
            params.putInt("Male", male);
            params.putInt("Female", female);
            
         }
       };

       suac.getConfig().postProcessPlugin = new ISignUpAssistantPlugin() {
         
         @Override
         public void execute(User user, ISFSObject params, SignUpConfiguration suc) throws SignUpValidationException {
            
            Long ID = (Long) user.getSession().getProperty("$SignUp.DBID");
            
            String username = initParams.getUtfString("Username");
            String password = initParams.getUtfString("Password");
            String location = initParams.getUtfString("Position");
         
            
            double posX = Double.parseDouble(location.split(";")[0]);
            double posY = Double.parseDouble(location.split(";")[1]);
            
            // logout guest user & login new user with new name & same session
            getApi().logout(user);
            user = getApi().login(user.getSession(), username, password, GameZone, null);
            
            // Assigning standard variables
            user.setProperty("ID", ID);
            user.getSession().setProperty("ID", ID);
            
            user.getSession().setProperty("new", true);
            user.getSession().setProperty("initX", posX);
            user.getSession().setProperty("initY", posY);
            
         }
      };
      
      
       addRequestHandler(SignUpAssistantComponent.COMMAND_PREFIX, suac);


My problem is that once i try to signup, the logviewer shows me the following log/exception

Code: Select all

BadUsername, from ( User Name: mustafarrry, Id: 2, Priv: 0, Sess: 192.168.0.106:52028 )


As you can see above in my decleration i modified the ErrorCode "UserNameAlreadyInUse" to the following :

Code: Select all

 suac.getConfig().errorMessages.put(SignUpErrorCodes.USERNAME_ALREADY_IN_USE, "BadUsername");


So i think this might tell me that the name "mustafarry" is already used in the database, right ?... But it isnt... atleast at the point of the registration, even if this exception gets thrown i still notice that the user is being pushed into the database... Futhermore this exception logs the user out...

So why does this exactly happens ? A few weeks ago it worked seemless... and i didnt changed any code...
User avatar
Lapo
Site Admin
Posts: 23025
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Signup Assistant tells me "Username already in use" ... but it isnt ?

Postby Lapo » 17 Oct 2018, 07:43

Hi,
the Signup Assistant checks the existence of a duplicate for the provided username in the DB. If the name exists it raises an exception as you have found.

I doubt it can be a problem with the component because the query used for the check is painfully simple.
It is something like this:

Code: Select all

sql = String.format("SELECT %s FROM %s WHERE %s=?", config.usernameField, config.signUpTable, config.usernameField);

If a result is found there's evidently a record in your DB with that usernameField in it.
Also keep in mind that selects are not case sensitive.

Maybe a good idea would be to completely empty the database table and start from scratch. You can always back up the current table before running the test, so you don't loose anything.

Cheers
Lapo
--
gotoAndPlay()
...addicted to flash games
genar
Posts: 137
Joined: 13 Jul 2017, 11:49

Re: Signup Assistant tells me "Username already in use" ... but it isnt ?

Postby genar » 17 Oct 2018, 07:58

Lapo wrote:Hi,
the Signup Assistant checks the existence of a duplicate for the provided username in the DB. If the name exists it raises an exception as you have found.

I doubt it can be a problem with the component because the query used for the check is painfully simple.
It is something like this:

Code: Select all

sql = String.format("SELECT %s FROM %s WHERE %s=?", config.usernameField, config.signUpTable, config.usernameField);

If a result is found there's evidently a record in your DB with that usernameField in it.
Also keep in mind that selects are not case sensitive.

Maybe a good idea would be to completely empty the database table and start from scratch. You can always back up the current table before running the test, so you don't loose anything.

Cheers


Thanks for your fast reply !
Well... i didnt knew that it is case sensitive... otherwise i still have no clue why this happens... i just cleared the whole "Users" table and tried it again... theres no entry in there and it still gives me this exception...

Somehow the signup assistant still inserts the user, even if the exception gets thrown....

So the flow looks like this : The user table is completly empty -> I insert credentials ( client side ) & press register -> the extension gets called and so the signup assistant does -> on post process i logout the guest user & login him again with a new name & make him join rooms -> Room extension ( On room join ) gets called, assigning of variables -> Suddenly the SignupAssistant tells me "BasUsername" and dissconnects the current user session

Result : Player suddenly shows up in the database user table...

Am i the only one with this problem ?
genar
Posts: 137
Joined: 13 Jul 2017, 11:49

Re: Signup Assistant tells me "Username already in use" ... but it isnt ?

Postby genar » 17 Oct 2018, 12:13

Lapo wrote:Hi,
the Signup Assistant checks the existence of a duplicate for the provided username in the DB. If the name exists it raises an exception as you have found.

I doubt it can be a problem with the component because the query used for the check is painfully simple.
It is something like this:

Code: Select all

sql = String.format("SELECT %s FROM %s WHERE %s=?", config.usernameField, config.signUpTable, config.usernameField);

If a result is found there's evidently a record in your DB with that usernameField in it.
Also keep in mind that selects are not case sensitive.

Maybe a good idea would be to completely empty the database table and start from scratch. You can always back up the current table before running the test, so you don't loose anything.

Cheers


Little Update regarding this iusse...

Above i showed some sample code... during the post processing of the signup extension i do the following :

Code: Select all

  suac.getConfig().postProcessPlugin = new ISignUpAssistantPlugin() {
         
         @Override
         public void execute(User user, ISFSObject params, SignUpConfiguration suc) throws SignUpValidationException {
            
            Long ID = (Long) user.getSession().getProperty("$SignUp.DBID");
            
            String username = initParams.getUtfString("Username");
            String password = initParams.getUtfString("Password");
            String location = initParams.getUtfString("Position");
         
            
            double posX = Double.parseDouble(location.split(";")[0]);
            double posY = Double.parseDouble(location.split(";")[1]);
            
            /Logging user out & in again for changing name
            getApi().logout(user);
            user = getApi().login(user.getSession(), username, password, GameZone, null);

            user.setProperty("ID", ID);
            user.getSession().setProperty("ID", ID);
            
            user.getSession().setProperty("new", true);
            user.getSession().setProperty("initX", posX);
            user.getSession().setProperty("initY", posY);
            
         }
      };


As you can see above at one point i log the user out & in again... without those lines the signup assistant works fine... but once i log the user out & in again it somehow throws the BadUserName exception...

Any ideas why this keeps happening ? Futhermore... to trigger the signup assistant i use "$SignUp" or even "$SignUp.Submit... does this command trigger anything else ? An event... or the login process ?

When calling "getApi().login(...)" does this probably throw this command ("$SignUp" or "$SignUp.Submit") that triggers the SignUpAssistant twice which causes the Already In use error ????
And if so... is there a way to change the CMD prefix of SignUpAssistant to solve this iusse ?

I hope for an fast answer !
User avatar
Lapo
Site Admin
Posts: 23025
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Signup Assistant tells me "Username already in use" ... but it isnt ?

Postby Lapo » 17 Oct 2018, 14:19

genar wrote:As you can see above at one point i log the user out & in again... without those lines the signup assistant works fine... but once i log the user out & in again it somehow throws the BadUserName exception...

Sorry but you can't do that.
If the user must be logged in again the request must come from the User itself (i.e. the client).

Still, I am confused as to how a database query can find an entry in an empty table. I think there's something else going in your code that is causing issues here.
Lapo

--

gotoAndPlay()

...addicted to flash games
genar
Posts: 137
Joined: 13 Jul 2017, 11:49

Re: Signup Assistant tells me "Username already in use" ... but it isnt ?

Postby genar » 17 Oct 2018, 14:41

Lapo wrote:
genar wrote:As you can see above at one point i log the user out & in again... without those lines the signup assistant works fine... but once i log the user out & in again it somehow throws the BadUserName exception...

Sorry but you can't do that.
If the user must be logged in again the request must come from the User itself (i.e. the client).

Still, I am confused as to how a database query can find an entry in an empty table. I think there's something else going in your code that is causing issues here.


Well probably "I cant do that" ... but it worked in the past ...
How else should i change the users name ? And no i wont use properties for that... i would need to recode the whole structure... thats no option...

And its only the "logout & login" part which causes this exception... once i remove this part the Signup Assistant works wonderfully... so i dont mess things up in the rest of my code...
User avatar
Lapo
Site Admin
Posts: 23025
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Signup Assistant tells me "Username already in use" ... but it isnt ?

Postby Lapo » 17 Oct 2018, 15:12

genar wrote:How else should i change the users name ? And no i wont use properties for that... i would need to recode the whole structure... thats no option...

I don't follow.
What has the SFSApi.login call to do with changing the name of a User?

I thought you were using this call to move a User from one Zone to another. My previous reply simply pointed out that it's not the proper way to do it. Instead you should logout the client (from client or server) and re-login from client side.

Changing the user name is done as explained in the docs:
https://smartfoxserver.com/blog/how-to- ... n/#more-70
(point #4)

And its only the "logout & login" part which causes this exception... once i remove this part the Signup Assistant works wonderfully... so i dont mess things up in the rest of my code...

Ok, good.
Lapo

--

gotoAndPlay()

...addicted to flash games
genar
Posts: 137
Joined: 13 Jul 2017, 11:49

Re: Signup Assistant tells me "Username already in use" ... but it isnt ?

Postby genar » 17 Oct 2018, 17:00

Lapo wrote:
genar wrote:How else should i change the users name ? And no i wont use properties for that... i would need to recode the whole structure... thats no option...

I don't follow.
What has the SFSApi.login call to do with changing the name of a User?

I thought you were using this call to move a User from one Zone to another. My previous reply simply pointed out that it's not the proper way to do it. Instead you should logout the client (from client or server) and re-login from client side.

Changing the user name is done as explained in the docs:
https://smartfoxserver.com/blog/how-to- ... n/#more-70
(point #4)

And its only the "logout & login" part which causes this exception... once i remove this part the Signup Assistant works wonderfully... so i dont mess things up in the rest of my code...

Ok, good.



The username changing you reffered to is quite usefull... is there a way to use this in the post process of the signup assistant ?
User avatar
Lapo
Site Admin
Posts: 23025
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Signup Assistant tells me "Username already in use" ... but it isnt ?

Postby Lapo » 18 Oct 2018, 07:07

Hi,
no because the SingUp process is something separate from the login process.
SignUpAssistant helps you build a system where people can create an account in your application. After that they will login with their new account, that's where you apply the login logic (and the name change).

Makes sense?
Lapo

--

gotoAndPlay()

...addicted to flash games

Return to “SFS2X Questions”

Who is online

Users browsing this forum: No registered users and 51 guests