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

  1. Update the service object as follows:
    • Add a postUser method which sends an AJAX request to register the user passed as a parameter.
    • Add a user as a parameter to the other methods and pass it (instead of the test user) to the sendRequest method.
  2. Update the store object as follows:
    • Add an addUser method which calls the postUser service method and saves the registered user and an empty todo list in the store if successful.
    • Add a user as a parameter to the getTodos method, pass it to the getTodos service method and save the received todos and the user in the store if successful.
    • Add a clear method which deletes all data from the store.
  3. Implement the Login component:
    • The template contains a form that allows users to enter their name and password.
    • The login event handler fetches the todos of the user using the getTodos method of the store.
    • The register event handler registers the user using addUser method of the store.
    If successful, both event handlers navigate to the todo list; if an error occurs (invalid credentails, user already exists), they display appropriate error messages.
  4. In the main module, register the Login with the router and use it as the initial component.
  5. (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.