I am trying to create a relationship between the User model of the play-authenticate module and my model - Books. I am using play 2.0.4 and I have integrated play-authenticate into my project. In my controllers/Application I have the getLocalUser method:
public static User getLocalUser(final Session session) {
final User localUser = User.findByAuthUserIdentity(PlayAuthenticate
.getUser(session));
return localUser;
}
I am trying override Model's method in my Books model to save the user who adds/modify book records.
public void save() {
User logged = Application.getLocalUser(session());
if (logged != null) {
this.createUser = logged;
this.modifyUser = logged;
}
super.save();
}
public void update(Object o) {
User logged = Application.getLocalUser(session());
if (logged != null) {
this.modifyUser = logged;
}
super.update(o);
}
The error I get when I do this, which I do not understand is:
The method session() is undefined for the type Books.
I'm not sure how this can be as I do have access to the controller/application methods because of my import:
import controllers.Application;
Update: *
public static Result createBook() {
Form<Book> filledForm = bookForm.bindFromRequest();
if(filledForm.hasErrors()) {
return badRequest(
views.html.bookCreator.render(Book.all(), filledForm)
);
}
else {
Book.create(filledForm.get());
//Book.save(getLocalUser(session()));
return redirect(routes.Application.createSuccess());
}
}*