Database Reference
In-Depth Information
Listing 10-17. The Sign-Up Controller Route
# sign up
post '/signup/add' do
# search db for user
user = get_user_by_user_name(neo,params[:username])
# found a match. need to use another username
if !!user.nil && !user.empty?
@title = "Home"
@error ="The username " +params[:username]+ " already exists. Please use a different username"
mustache :"home/index"
#save the user
else
save_user(neo,params[:username])
redirect to("/msg?u="+params[:username])
end
end
Adding a User
In each part of the five graph areas covered in the chapter, the domain object will have a corresponding service to
manage the persistence operations within the database. In this case, the User class covers the management of the
application's user nodes using a mix of Neography convenience methods and executing Cypher queries.
To save a node and label it as a User, the save_user method, shown in Listing 10-18, makes use of the create_node
method by passing in the username param and value. Once the node is created, then the add_label method applies
the User label.
Listing 10-18. The save_user Method in the User Class
def save_user(neo, username)
node = neo.create_node("username" => username)
neo.add_label(node, "User")
end
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.
 
Search WWH ::




Custom Search