Database Reference
In-Depth Information
@Query("MATCH (user { username:{u}})-[:FOLLOWS]->(users) " +
" RETURN users " +
" ORDER BY users.username")
LinkedList<User>
following
(@Param("u") String username);
}
Sign-Up
The HTML required for the user sign-up form is shown in Listing 11-18 and can be found in the
{PROJECTROOT}/WebContent/mustache/html/home/index.html
file. The important item to note in the HTML form is
that the
bean name
then
property
are used to specify what is passed to controller and, subsequently, to the service
layer for saving to the database.
Listing 11-18.
Sign-Up HTML Form
<form class="navbar-form navbar-left" action="
/signup/add
" role="form" id="createaccountform"
method="post">
<div class="form-group">
<input type="text" placeholder="Username" name="
user.username
" class="form-control">
</div>
<button type="submit" class="btn btn-success">Create Account</button>
</form>
■
The sample application creates a user without a password, but I am certainly not suggesting or advocating
this approach for a production application. excluding the password property was done in order to create a simple sign-up
and login that helps keep the focus on the more salient aspects of SDn.
Note
Sign-Up Controller
In the
SignupController
class, located in the
com.practicalneo4j.graphstory.controller
, you will use a method
called
adduser
to control the flow of the sign-up process, shown in Listing 11-19. The controller instantiates a
ModelAndView
object, which returns properties to the view layer. Next, the
GraphStoryInterface
accesses the
save
method of the
UserInterface
and returns a
GraphStory
object.
If no errors are returned during the save attempt, the request is redirected to a message view to thank the user for
signing up. Otherwise, the
ModelAndView
specifies the HTML page to return and the error messages that need to be
displayed.
Listing 11-19.
Sign-Up Controller
@RequestMapping(value = "/signup/add", method = RequestMethod.POST)
public ModelAndView
addUser
(@ModelAttribute("graphStory") GraphStory graphStory) {
ModelAndView modelAndView;
try {
graphStory =
graphStoryInterface.getUserInterface().save
(graphStory);