Is this the correct way for using before login and after login

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

@Async
@Override
public void beforeLogin( RunnerContext context, String login, String password ) throws Exception
{
// add your code here
dataQuery =new BackendlessDataQuery();
whereClause = “email = '” +login+"’";
BackendlessCollection<BackendlessUser> result = Backendless.Persistence.of(BackendlessUser.class).find(dataQuery);
Iterator<BackendlessUser> iterator = result.getCurrentPage().iterator();
while (iterator.hasNext()){
BackendlessUser user = iterator.next();
verfied = user.getProperty(“verified”).toString();
}
if (verfied==“true”){

}
}
@Async
@Override
public void afterLogin( RunnerContext context, String login, String password, ExecutionResult<HashMap> result ) throws Exception
{
// add your code here
}

}
Now after that how to send an erroe if verified is false

Hi Reuben,

please take a look at this comment:
http://support.backendless.com/t/doubts-in-before-login-and-after-login#comment-19893

Regards,
Stanislaw

so you mean to say that i just write

throw notverfiedexception

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

@Async
@Override
public void beforeLogin( RunnerContext context, String login, String password )throws Exception
{
// add your code here
dataQuery =new BackendlessDataQuery();
whereClause = “email = '” +login+"’";
BackendlessCollection<BackendlessUser> result = Backendless.Persistence.of(BackendlessUser.class).find(dataQuery);
Iterator<BackendlessUser> iterator = result.getCurrentPage().iterator();
while (iterator.hasNext()){
BackendlessUser user = iterator.next();
verfied = user.getProperty(“verified”).toString();
}
if (verfied==“false”){

  System.out.print("error");
  throw new Exception("UserNotVerfied");
}

}

@Async
@Override
public void afterLogin( RunnerContext context, String login, String password, ExecutionResult<HashMap> result ) throws Exception
{
// add your code here
}

}

Now i should just run coderunner.bat and it will deploy this code on server right ?

  1. Don’t use == operator to compare strings

  2. Remove the @Async annotation from beforeLogin handler. Otherwise Backendless server will log-in the user without waiting for your Server Code resolution

  3. In your specific case findFirst would fit better than find (Basic Data Search doc)

  4. Remove redundant and empty afterLogin event handler

  5. Read the Backendless documentation. This section explains how to deploy the code on server

  6. Please, use this forum only for Backendless specific questions and problems. Not like how to throw an exception. Such a questions should be asked somewhere else on Java specific forums

  7. Please, keep in mind that according to Backendless Support Policy, the free support plan doesn’t cover user’s code validation, fixing and writing. As well as answering general how-to questions

Thanks

Thank you so much i never needed help with java though i was just asking whether i should do it in that manner or not :slight_smile: