Backendless Support
 
Answered

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

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.

Leave a Comment

Comments (4)

photo
1

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

photo
1

Thanks for replying Mark,

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

  1. @Override
  2. public void beforeLogin( RunnerContext context, String login, String password ) throws Exception {
  3. String whereClause = "name = '"+login+"'";
  4. BackendlessDataQuery dataQuery = new BackendlessDataQuery();
  5. dataQuery.setWhereClause(whereClause);
  6. BackendlessCollection<BackendlessUser> result = Backendless.Persistence.of(BackendlessUser.class).find(dataQuery);
  7. if (!result.getCurrentPage().isEmpty()) {
  8. login = result.getCurrentPage().get(0).getEmail();
  9. }
  10. }

photo
1

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.

photo
1

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.

photo