I\'m trying to create a simple login based on the Zentask sample --zentask - playframework, however when I click the login button which calls the Application.authenticate ac
I have to assume a lot but if this is what your stacktrace looked like:
play.api.Application$$anon$1: Execution exception[[RuntimeException: java.lang.reflect.InvocationTargetException]]
at play.api.Application$class.handleError(Application.scala:293) ~[play_2.10.jar:2.2.3]
at play.api.DefaultApplication.handleError(Application.scala:399) [play_2.10.jar:2.2.3]
at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$3$$anonfun$applyOrElse$3.apply(PlayDefaultUpstreamHandler.scala:264) [play_2.10.jar:2.2.3]
at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$3$$anonfun$applyOrElse$3.apply(PlayDefaultUpstreamHandler.scala:264) [play_2.10.jar:2.2.3]
at scala.Option.map(Option.scala:145) [scala-library.jar:na]
at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$3.applyOrElse(PlayDefaultUpstreamHandler.scala:264) [play_2.10.jar:2.2.3]
...
Caused by: java.lang.NullPointerException: null
at models.User.authenticate(User.java:26) ~[na:na]
at controllers.Application$Login.validate(Application.java:50) ~[na:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_05]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_05]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_05]
at java.lang.reflect.Method.invoke(Method.java:483) ~[na:1.8.0_05]
then the cause of the problem is actually hinted at by the NPE in your User class. If you enter bogus credentials, your finder will not find anything and return null in AccountDetails.authenticate().
So in the method below you do not check for null and try and get the userId, which causes the NPE:
public static User authenticate(String email, String password) {
String tempId = AccountDetails.authenticate(email, password).userId;
return find.ref(tempId);
}
If you just check for null properly you will get the desired functionality:
public static User authenticate(String email, String password) {
User user = null;
AccountDetails accountDetails = AccountDetails.authenticate(email, password);
if (accountDetails != null) {
user = find.ref(accountDetails.userId);
}
return user;
}