Doubts in Before Login and After Login

Hi guys i am actually using OTP from msg91 and when i am receiving the OTP i have a button called verify which when pressed will make the verified field in my USERS database to true if it fails it remains Unverified.
Now if it is unverfied i dont want the user to be able to login and throw an exception. so for this i am using Before and After Login so now how can i access the user table in afterLogin to check whether the user is verfied or not.
do i use the same logic which i have been using for the custom table which i have made
Like using Backendless.persistece.of(Class name.class)
Or is there and other method for this
Been stuck in this since almost a week hope you guys can help me out

Hi Reuben,

You are quite right. You can make it in this way but instead of use custom class, you should use BackendlessUser.class.
Please, note that access to custom properties of instance user is carried by method getProperty()
Regards, Ilya

Thank you so much can I ask one more question so now if i want to send an error i should throw that error as an exception

like
try{

the code over here to check whether he is verified

if not then

throw NotVerfiedException
}catch(NotVerfiedExcetpio){
what should i write here so that my app catches this exception name and i can handle it in my logic
}

Yes, you should throw an exception and on your client side you should catch this with try-catch

public class GenericUserEventHandler extends com.backendless.servercode.extension.UserExtender
{
BackendlessDataQuery dataQuery;
String whereClause;

@Async
@Override
public void beforeLogin( RunnerContext context, String login, String password ) throws Exception
{
// add your code here
dataQuery =new BackendlessDataQuery();
whereClause = “email = '” +login+"’";
Backendless.Persistence.of(BackendlessUser.class).find(dataQuery, new AsyncCallback<BackendlessCollection<BackendlessUser>>() {
@Override
public void handleResponse(BackendlessCollection<BackendlessUser> backendlessUserBackendlessCollection) {
for (BackendlessUser user: backendlessUserBackendlessCollection.getData()){
String verfied = user.getProperty(“verfied”).toString();
if(verfied == “false”){

      }
    }
  }

  @Override
  public void handleFault(BackendlessFault backendlessFault) {

  }
});

}

this is what i have written now what do i do in the if loop throw an exception ?

Hi,
First at all event handler should be sync and query to data service should be sync too.
In your ‘if’ you can throw an error and on client side this error will come to fault handle.
Regards Ilya