Login
This section provides you with the required information regarding the user authentication mechanism.
The below mentioned methods need to be used to login the user. Please follow the steps below to login the user into CometChat.
Method Signature:
login(String userName, String password, Callbacks callback);
The parameters needed for the login method are as follows:
userName – Username of the user.
password – Password for the user.
callback – This is an instance of the Callback interface which contains the success and failure methods.This helps you to know if the login attempt was successful. Usage:
cometChat.login("user1,"password123",new Callbacks() {
@Override
public void successCallback(JSONObject response) {}
@Override
public void failCallback(JSONObject response) {}
});
login(String userId, Callbacks callback);
Parameters
userId – User ID of the user.
callback – This is an instance of the Callback interface which contains the success and failure methods.This helps you to know if the login attempt was successful. Usage:
cometChat.login("10", new Callbacks() {
@Override
public void successCallback(JSONObject response) {}
@Override
public void failCallback(JSONObject response) {}
});
Logout
Calling this function will end the current session and clears user data. Method Signature:
logout(Callbacks callback)
Callback Interface: The callback interface contains the methods successCallback and failCallback. The method successCallback triggers with successful logout and contains “logout successful” message in JSON object. The method failCallback triggers with unsuccessful logout and contains error information in JSON object. Usage:
cometchat.logout(new Callbacks() {
@Override
public void successCallback(JSONObject response) {}
@Override
public void failCallback(JSONObject response) {}
});