CSC309 Programming on the Web
Assignment 2 - Javascript, AJAX, JSON, JQuery, PHP Rest API, Postgresql

Due: March 5, 2017, 11:50 PM
Late penalty: 20% penalty for 48 hours late, not excepted after that.
Hand in: Electronic submit here
Preliminary Marking Scheme: here
Groups: Work in teams of size 2
Environment:We will run your code under Firefox and cs.utm.utoronto.ca.

Warehouse Wars

Your job will be to implement the WareHouse Wars game as outlined in the CSC148 Assignment 1. This video is of a partial implementation.
Your web application should live at http://cs.utm.utoronto.ca/~UTORID/ww/ You can start with this starter code

Installation Script

Please include install.php or install.bash to help us install your application in our webspace, using our database.

User Managment

Implement a user managment system with a RESTful api. Your PHP scripts should support Account creation, update, delete and read via the http verbs POST, GET, PUT, DELETE.

index.html

There is a single index.html which includes Javascript, JQuery, CSS etc. It has many different views. To keep your code clean, you should probably separate the Javascript for this page into separate files. index.html has a few different parts, Homepage/Login, Account Creation/Modification, Game. All of these appear as a result of the single page load. The particular part of the page that the user sees depends in showing or hiding the appropriate div in Javascript/JQuery. PHP is not allowed to serve html for this assignment, it only served the REST api. The front end uses JQuery to make ajax requests to the backend. You will have to figure out what a AJAX JSON request looks like as well as what an AJAX JSON response looks like.

Homepage/Login

The home page contains a login form as well as a list of the top 10 high scores and a button/link etc. to the registration page. When the user selects registration, they are switched to that view of the same index.html. That is, no further request for html happens. Appropriate html inputs for login should be present. Validation should happen both on the front end and on the backend.

It should be noted that a RESTful api uses authentication slightly differently. That is, the simple case has the client store the credentials and repeatedly send them on each request. In this way, the server does not maintain session information. As an extra feature, you can implement rest api login pattern instead of simply sending the credentials on each request.

Account Creation/Modification

Accounts are validated both in the front end and the backend (in your PHP code). For backend validation, on invalid data, modify the css for form fields to let the user know where the issues are. A username can only appear in the database at most one time. Once a user is registered, they are placed on the game play page.

Game

Users can not see the game page without authentication. Yes, I know, in reality, since they have the javascript, they can hack it, but they still can't modify the backend information. Some more details are below...

htaccess and htpasswd

The ww directory I have given you contains two files, .htaccess and htpasswd. In general, you would not put the htpasswd file in such a 'convenient' place. In any case, I have set this up so that self can access the directory with password changeThis. Your job is to fix .htaccess so that it points to your htpasswd and also change the password using the htpasswd command. Otherwise, curious students can simply browse into your directory, download your game and play with it, and then look at your code. See Authentication and Authorization. By the way, this is not great security, at least cs uses https though, so the whole conversation is encrypted.

References

Questions and Answers

Question:
I cant seem to find the program htaccess in the lab?
Answer:
It is installed on cs.utm.utoronto.ca
Question:
cs.utm.utoronto.ca is using an old version of php, so I can't find http_response_code.
Answer:
See this and this