Database Reference
In-Depth Information
Listing 8-18. The saveUser Method in the User Class
public static function saveUser(User $user){
if(!$user->node){
$user->node = new Node(Neo4Client::client());
}
$userlabel = Neo4Client::client()->makeLabel('User');
// set properties
$user->node->setProperty('username', $user->username);
$user->node->setProperty('firstname', $user->firstname);
$user->node->setProperty('lastname', $user->lastname);
// save the node
$user->node->save()->addLabels(array($userlabel));
//set the id on the user object
$user->id = $user->node->getId();
}
Login
This section reviews the login process for the sample application. To execute the login process, we also use the login
route as well as User class. Before reviewing the controller and service layer, take a quick look at the front-end code for
the login.
Login Form
The HTML required for the user login form is shown in Listing 8-19 and can be found in the {PROJECTROOT}/app/
templates/global/homeheader.mustache layout file.
Listing 8-19. The Login Form
<form class="navbar-form navbar-right" action="/login" role="form" method="post">
<div class="form-group">
<input type="text" placeholder="Username" name="username" class="form-control">
</div>
<button type="submit" class="btn btn-success">Sign in</button>
</form>
Login Route
In the {PROJECTROOT}/app/public/index.php file, use the login route to control the flow of the login process, as
shown in Listing 8-20. Inside the login route, we used the getByUsername method to check if the user exists in the
database.
 
Search WWH ::




Custom Search