Web Programming
Todo SPA (Sessions)
The objective of this exercise is to extend the
todo single-page application so that users can login to access their individual todos.
Tasks
-
Add the following methods to the
service object:
postUser(user) sends an AJAX request to register the specified user
authUser(user) sends an AJAX request to authenticate the specified user
Add a user parameter to the other methods and pass it (instead of the test user) to the sendRequest method.
-
Add the following methods to the
store object:
registerUser(user) calls the postUser service method and saves the registered user
loginUser(user) calls the authUser service method and saves the logged-in user
In the other methods, add the stored user as additional parameter to the service calls.
-
Implement the
Login component:
- The template contains a form where users can enter their name and password to log in or register.
- Register a handler for the submit event on the form:
- Use the event's
submitter property to determine which button was clicked
- Use the store functions to register or to log in the user
- Navigate to the todo list, or display an appropriate error message if an error occured
-
In the
main module, register the Login class with the router and use it as the initial component.
-
(Optional) Implement the
Logout component that clears the store and displays a confirmation message; insert a link in all views to navigate to the component.