Database Reference
In-Depth Information
Listing 7-15.
HTML Snippet of Sign-Up in Views/Home/Index.cshtml
<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="
graphStory.user.username
" class="form-control">
</div>
<button type="submit" class="btn btn-success">Create Account</button>
</form>
■
While the sample application creates a user without a password, 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 the Neo4jClient library.
Note
Sign-Up Controller
In the
SignupController
class, use a method called
Add
to control the flow of the sign-up process, shown in
Listing 7-16. This particular controller does not extend the
GraphStoryController
class or the
SecurityController
class because it does not need to check the user login status or have access to the accompanying values. It does
include access to the
GraphStoryInterface, which
will access the
save
method of the
UserInterface
and return a
GraphStory
object.
If no errors were returned during the save attempt, the request is redirected via
RedirectToRoute
to a message
view in the
HomeController
to thank the user for signing up. Otherwise, a
ViewBag
is set with an error variable and
output the error message back to the specified view.
Listing 7-16.
The
SignupController
public class SignupController : Controller
{
private GraphStoryInterface graphStoryService;
public SignupController(GraphStoryInterface graphStoryService) {
this.graphStoryService = graphStoryService;
}
public ActionResult Add(GraphStory graphStory)
{
graphStory = graphStoryService.userInterface.save(graphStory);
if (graphStory.haserror==false)
{
return RedirectToRoute(new { controller = "Home", action = "msg",
msg = "Thank you," + graphStory.user.username });
}