Page 1 of 1

Sign up

Posted: 29 Jan 2020, 17:54
by Kor
Hi, Can you help me with signup code? I have postgress database with the table users and one column nickname which is primary key. I made extension code and activate the database. Wrote the client code with the zone BasicExamples. But in Log of smartfox there was an signup error when i wanna import some user in database. For example when i write in the script kermit.I just login as a guest and can't import the nickname kermit to the database.The nickname is empty in database
Here is the server code:

Code: Select all

import com.smartfoxserver.v2.components.login.LoginAssistantComponent;
import com.smartfoxserver.v2.components.signup.SignUpAssistantComponent;
import com.smartfoxserver.v2.components.signup.SignUpConfiguration;

import com.smartfoxserver.v2.entities.data.ISFSObject;
import com.smartfoxserver.v2.extensions.SFSExtension;
public class SignUpTestExtension extends SFSExtension
{
	private SignUpAssistantComponent suac;
	private LoginAssistantComponent lac; 
	
	@Override
	public void init()
	{
		initSignUpAssistant();
		initLoginAssistant();
	}
	
	@Override
	public void destroy()
	{
	    super.destroy();
	    lac.destroy();
	}
	
	private void initSignUpAssistant()
	{
		suac = new SignUpAssistantComponent();
		suac.getConfig().signUpTable = "users";		
		addRequestHandler(SignUpAssistantComponent.COMMAND_PREFIX, suac);
	}
	
	private void initLoginAssistant()
	{
		lac = new LoginAssistantComponent(this);		
		lac.getConfig().loginTable = "users";		
		};
	}
}
 
And the client code:

Code: Select all

using UnityEngine;
using System.Collections;
using Sfs2X;
using Sfs2X.Core;
using Sfs2X.Requests;
using Sfs2X.Entities.Data;

public class SignUp : MonoBehaviour {
       
        public string ServerIP = "127.0.0.1";
        public int ServerPort = 9933;
        public string ZoneName = "BasicExamples";
        public string UserName = "";
        SmartFox sfs;
        string CMD_Signup = "$SignUp.Submit";
       
        void Start()
        {
                sfs = new SmartFox();
                sfs.ThreadSafeMode = true;
               
                sfs.AddEventListener(SFSEvent.CONNECTION, OnConnection);
                sfs.AddEventListener(SFSEvent.LOGIN, OnLogin);
                sfs.AddEventListener(SFSEvent.LOGIN_ERROR, OnLoginError);
                sfs.AddEventListener(SFSEvent.EXTENSION_RESPONSE, OnExtensionResponse);
               
                sfs.Connect(ServerIP, ServerPort);
        }
       
        void OnConnection(BaseEvent e)
        {
                if ((bool)e.Params["success"])
                {
                        Debug.Log("Successfully Connected!");
                        sfs.Send(new LoginRequest("", "", ZoneName));
                } else {
                        Debug.Log("Connection Failed!");
                }
        }
       
        void OnLogin(BaseEvent e)
        {
                Debug.Log("Logged In: " + e.Params["user"]);
               
                ISFSObject objOut = new SFSObject();
                objOut.PutUtfString("nickname", UserName);
                
                sfs.Send(new ExtensionRequest(CMD_Signup, objOut));
        }
       
        void OnLoginError(BaseEvent e)
        {
                Debug.Log("Login error: (" + e.Params["errorCode"] + "): " + e.Params["errorMessage"]);
        }
       
        void OnExtensionResponse(BaseEvent e)
        {
                string cmd = (string)e.Params["cmd"];
                ISFSObject objIn = (SFSObject)e.Params["params"];
               
                if (cmd == CMD_Signup)
                {
                        if (objIn.ContainsKey("errorMessage"))
                        {
                                Debug.Log("Signup Error: " + objIn.GetUtfString("errorMessage"));
                        }
                        else if (objIn.ContainsKey("success"))
                        {
                                Debug.Log("Signup Successful");
                        }
                }
        }
       
        void FixedUpdate()
        {
                sfs.ProcessEvents();
        }
       
        void OnApplicationQuit()
        {
                if (sfs.IsConnected)
                        sfs.Disconnect();
        }
}

Re: Sign up

Posted: 10 Feb 2020, 16:14
by Lapo
Sorry for the delay in responding, this was posted under the SFS1.x forum so I didn't notice it for a while. I've now moved it under SFS2X.

What is exactly the error you're getting from server side?

Thanks