问题
So, I have set up a registration form that saves info to a database in Play Framework. Don't get caught up on the nonexistant password security, I haven't gotten to that.
I need a way to check to see if an email is already in the user database. I'm simply not sure how to do that with Ebean.
The form model is stored here: https://github.com/Axsel/PonyCentral/blob/master/app/models/RegisterForm.java | In the validation method seen at the bottom of the class I need to be able to check the user table for any matching emails. The email variable from RegisterForm is direct input from the form.
The user model that is connected to Ebean can be found here: https://github.com/Axsel/PonyCentral/blob/master/app/models/User.java
Lastly, if you need to see it, the form request handler can be found here: Under /app/controllers/User.java (StackOverflow won't let me link for than two things)
If you could provide any help I would be very grateful.
Thank you much.
回答1:
Just... query the database i.e. count the records for given email (written from top of my head):
int count = User.find.where().like("email", "john@doe.com").findRowCount();
if (count>0) return badRequest("This email address already in use");
来源:https://stackoverflow.com/questions/23774217/how-to-query-ebean-play-framework-to-see-if-a-certain-value-is-in-a-certain