Is there a way to add session values before redirecting to a controller?
I explain better, I have the following code:
if(user.getRole().equals("STUDENT")) {
return redirect(routes.HomeController.index()).
addingToSession(request, "role", user.getRole()).
addingToSession(request, "email", user.getEmail()).
addingToSession(request, "id", user.getId()).
addingToSession(request, "fullname", user.getLastname() + " " + user.getFirstname()).
addingToSession(request, "cycle", user.getCycle()).
addingToSession(request,"tutor", user.getTutorFullname());
}
else {
return redirect(routes.HomeController.index()).
addingToSession(request, "role", user.getRole()).
addingToSession(request, "email", user.getEmail()).
addingToSession(request, "id", user.getId()).
addingToSession(request, "fullname", user.getLastname() + " " + user.getFirstname());
}
I have a lot of duplicated code. Is there a way to avoid that?