Support Topics Documentation Slack YouTube Blog

Both email and name cloumns, identity column at same time ?


(Hüseyin Karakullukçu) #1

I’m new to service. I’m working around user service. I want make a app that users can login their username or email. But in the console we can only mark one column as identity. Is possible to mark multiple columns as identity column ? If not, could be implemented ?

Best Regards.


(Mark Piller) #2

Hi Hüseyin,

Would username and email be unique for every user? If so, it would be possible with custom business logic in JS (you need to add a “beforeLogin” handler).In the handler you would need to determine the user based on the provided information and use the right identity. For example, suppose user logs in with username, but the email column is marked as identity. In the business logic, you need to find the user using Backendless API, get their email and set the email value to “req.login”.

Regards,
Mark


(Hüseyin Karakullukçu) #3

Thanks for replying Mark,

I tried your instructions. But didn’t worked. Am I doing something wrong?


@Override
  public void beforeLogin( RunnerContext context, String login, String password ) throws Exception {
          String whereClause = "name = '"+login+"'";
          BackendlessDataQuery dataQuery = new BackendlessDataQuery();
          dataQuery.setWhereClause(whereClause);



          BackendlessCollection<BackendlessUser> result = Backendless.Persistence.of(BackendlessUser.class).find(dataQuery);
          if (!result.getCurrentPage().isEmpty()) {
              login = result.getCurrentPage().get(0).getEmail();
          }





  }

(Mark Piller) #4

With Java, it will not work. The “login” argument is passed by value and the change you make by assigning value to “login” will not be visible outside of the “beforeLogin” invocation. That is why I said it should be done in a JS handler.


(Hüseyin Karakullukçu) #5

Whoa! Thanks for really fast answering.

Now i get it. Instead of passing string arguments, putting all values in a hashmap might be work on java.
Maybe you add in future. Keep up with good work.

Regards.