The login process will be stopped and user will trigger LOGIN_ERROR event if I use the following code, right?
SFSErrorData errData = new SFSErrorData(SFSErrorCode.LOGIN_BAD_USERNAME);
throw new SFSLoginException("User login error", errData);
Stop the login process
Re: Stop the login process
Yes,
on the server side, if you throw a LoginException it will cause a LOGIN_ERROR on the client.
cheers
on the server side, if you throw a LoginException it will cause a LOGIN_ERROR on the client.
cheers
Re: Stop the login process
thanks man, you rock!
Re: Stop the login process
HI Lapo, below is my code, regardless of what user name or password I've used, I could login, client does not receive LOGIN_ERROE, but there was a error message on server console. What did I miss?
Code: Select all
public class OnLogin extends BaseServerEventHandler {
@Override
public void handleServerEvent(ISFSEvent event) throws SFSException {
ISFSObject userdata = new SFSObject();
String uName = (String) event.getParameter(SFSEventParam.LOGIN_NAME);
String uPasswd = (String) event.getParameter(SFSEventParam.LOGIN_PASSWORD);
ISession session = (ISession) event.getParameter(SFSEventParam.SESSION);
if(!Objects.equals(uName, "Mazing"))
{
SFSErrorData errData = new SFSErrorData(SFSErrorCode.LOGIN_BAD_USERNAME);
errData.addParameter(uName);
throw new SFSLoginException("Bad user name", errData);
}
if(!getApi().checkSecurePassword(session, "123876", uPasswd))
{
SFSErrorData errData = new SFSErrorData(SFSErrorCode.LOGIN_BAD_PASSWORD);
errData.addParameter(uPasswd);
throw new SFSLoginException("Bad password", errData);
}
userdata.putUtfString("name", uName);
userdata.putUtfString("id", "100001");
userdata.putInt("cards", 9);
session.setProperty("userdata", userdata);
}
}
Re: Stop the login process
Make sure you have turned on the "Custom login" flag in your zone config.
This tells the server to send all login requests to your Extension.
Cheers
p.s. = if you had an error post the stack trace here.
This tells the server to send all login requests to your Extension.
Cheers
p.s. = if you had an error post the stack trace here.
Re: Stop the login process
Bit of an old thread but I am seeing the same behaviour
To test I have set the login handler to always throw a simple login exception with no additional code
I can see the error in the server console followed by a user login
The client always fires the onLogin and never the onLoginError.
I don't think I am missing anything but the behaviour does not seem to be correct
To test I have set the login handler to always throw a simple login exception with no additional code
Code: Select all
SFSErrorData errData = new SFSErrorData(SFSErrorCode.LOGIN_BAD_PASSWORD);
try {
throw new SFSLoginException("authentication failed", errData);
} catch (SFSLoginException e) {
ext.trace(e);
}
I can see the error in the server console followed by a user login
05:32:21,453 INFO [SFSWorker:Ext:1] Extensions - {CasinoFloorStage}: com.smartfoxserver.v2.exceptions.SFSLoginException: authentication failed
05:32:21,464 INFO [SFSWorker:Ext:1] api.SFSApi - User login: { Zone: CasinoFloorStage }, ( User Name: appUser, Id: 0, Priv: 0, Sess: 90.255.234.203:65277 ) , Type: IOS version: 12.2
The client always fires the onLogin and never the onLoginError.
I don't think I am missing anything but the behaviour does not seem to be correct
Re: Stop the login process
Hi,
the problem with your code is that you're catching the Exception. By doing so you're not allowing the Exception to travel up the call chain and stop the login process.
Simply remove the try/catch block.
Cheers
the problem with your code is that you're catching the Exception. By doing so you're not allowing the Exception to travel up the call chain and stop the login process.
Simply remove the try/catch block.
Cheers
Who is online
Users browsing this forum: Stevenor and 119 guests