<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>http://classes.engineering.wustl.edu/cse330/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Marc</id>
	<title>CSE330 Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="http://classes.engineering.wustl.edu/cse330/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Marc"/>
	<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=Special:Contributions/Marc"/>
	<updated>2026-11-15T18:16:51Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.34.4</generator>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=Module_5&amp;diff=920</id>
		<title>Module 5</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=Module_5&amp;diff=920"/>
		<updated>2012-11-29T21:39:04Z</updated>

		<summary type="html">&lt;p&gt;Marc: /* Grading */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In Module 6, you will learn about python, a programming language, and Django, a web framework.&lt;br /&gt;
&lt;br /&gt;
This article contains your assignments for Module 6.&lt;br /&gt;
&lt;br /&gt;
== Individual Assignments ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Python Tutorial ===&lt;br /&gt;
&lt;br /&gt;
====Install Python Tools====&lt;br /&gt;
*&amp;lt;code&amp;gt;sudo yum install python-setuptools&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
*&amp;lt;code&amp;gt;sudo yum install python-devel&amp;lt;/code&amp;gt;&lt;br /&gt;
====Python Assignment====&lt;br /&gt;
*You will write a python script that reads a set of student grades in from a file and does some basic parsing and processing. [http://docs.python.org/tutorial/inputoutput.html#reading-and-writing-files here] is the section of the python tutorial on reading and writing files.&lt;br /&gt;
*An example grades file is [http://research.engineering.wustl.edu/~todd/cse330/grades.txt here]. For the sake of simplicity you can assume that the file name is always going to be grades.txt.&lt;br /&gt;
*The first line of the file is of the form: NUM_LABS,NUM_EXAMS,LAB_WEIGHT&lt;br /&gt;
*All of the other lines in the file are of the form: FIRSTNAME LASTNAME|GRADE|TYPE&lt;br /&gt;
*The FIRSTNAME and LASTNAME fields are the student's full name (always only a first and last name), the GRADE is one grade for the student, and the TYPE describes what kind of assignment the grade was for, in this case either a 'lab' or an 'exam'.&lt;br /&gt;
*Your script should read in a grades file with the above format and perform the following:&lt;br /&gt;
*# Compute the final grade for every student, given that there were a total of NUM_LABS labs, NUM_EXAMS exams, and that the labs account for a total of LAB_WEIGHT percent of the grade.&lt;br /&gt;
*# Compute the final letter grade based on the final numeric grade (A = 90 or above, B = 80 - 90, C = 70 - 80, D = 60 - 70, F = below 60). &lt;br /&gt;
*# Ignore any blank lines.&lt;br /&gt;
*# Sort the students by last name, and print out final grades in that sorted order.&lt;br /&gt;
*# No names should be hard coded into the script (you will run your script on another file with different student names when we grade your assignment).&lt;br /&gt;
*# Finally, the script should take one optional command line argument, which is a string to match against student names.  Only names that match the string in full or in part, should be printed out with their final grades.&lt;br /&gt;
*#*For example, with the argument 'John' grades for both John Smith and John Locke should be printed (if those are the only two Johns in the grades.txt file)&lt;br /&gt;
&lt;br /&gt;
=== Django Tutorial===&lt;br /&gt;
====Install Djgano====&lt;br /&gt;
&amp;lt;p&amp;gt; This procedure assumes you are using and Amazon AMI Linux on an ec2 instance. An in-depth install guide can be found on the [https://docs.djangoproject.com/en/dev/topics/install/# Django website], but a quick version is below. Run these commands as root. &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Install Distribute (prerequisite for pip):&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;curl http://python-distribute.org/distribute_setup.py | python&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Install pip:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;curl https://raw.github.com/pypa/pip/master/contrib/get-pip.py | python&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Install Django using pip:&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;pip install Django&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt; That's it. &amp;lt;/p&amp;gt;&lt;br /&gt;
====Django Assignment====&lt;br /&gt;
&amp;lt;p&amp;gt;Complete the [https://docs.djangoproject.com/en/1.4/intro/tutorial01/ tutorial] on the django website. You will create a Polls app. There are four parts to this tutorial.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;It is important you do all the steps in the tutorial to get comfortable defining models, views, templates, and using the interactive shell and the admin app. Understanding the concepts will make the project go much quicker.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;h5&amp;gt;[https://docs.djangoproject.com/en/1.4/intro/tutorial01/ Part 1]&amp;lt;/h5&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Create a project&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Start the development server&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Setup an SQLite database&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Create the Polls app and define the models&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Interact with the database using the interactive python shell&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&lt;br /&gt;
&amp;lt;h5&amp;gt;[https://docs.djangoproject.com/en/1.4/intro/tutorial02/ Part 2]&amp;lt;/h5&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Activate the admin site&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Add the poll app to the admin site&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Modify the database using the admin site&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&lt;br /&gt;
&amp;lt;h5&amp;gt;[https://docs.djangoproject.com/en/1.4/intro/tutorial03/ Part 3]&amp;lt;/h5&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Configure URL handling&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Create some views&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&lt;br /&gt;
&amp;lt;h5&amp;gt;[https://docs.djangoproject.com/en/1.4/intro/tutorial04/ Part 4]&amp;lt;/h5&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Write a form that modifies the database&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Refactor to use generic views&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h5&amp;gt;Switch to Apache Webserver&amp;lt;/h5&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;run &amp;lt;code&amp;gt;yum install mod_wsgi&amp;lt;/code&amp;gt; to install the apache and the module necessary for serving your django app.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Add these lines to /etc/httpd/conf/httpd.conf&lt;br /&gt;
&amp;lt;source lang=&amp;quot;apache&amp;quot;&amp;gt;&lt;br /&gt;
Alias /static /var/www/*APPNAME*/static&lt;br /&gt;
&amp;lt;Directory /var/www/*APPNAME*/static&amp;gt;&lt;br /&gt;
  Order deny,allow&lt;br /&gt;
  Allow from all&lt;br /&gt;
&amp;lt;/Directory&amp;gt;&lt;br /&gt;
WSGIScriptAlias / /var/www/*APPNAME*/apache/django.wsgi&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Move your &amp;quot;mysite&amp;quot; project to /var/www and make the directory /var/www/*APPNAME*/apache. In that directory create the file django.wsgi and Inside that file put:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
import os&lt;br /&gt;
import sys&lt;br /&gt;
sys.path.append('/var/www/*APPNAME*')&lt;br /&gt;
os.environ['DJANGO_SETTINGS_MODULE'] = '*APPNAME*.settings'&lt;br /&gt;
import django.core.handlers.wsgi&lt;br /&gt;
application = django.core.handlers.wsgi.WSGIHandler()&lt;br /&gt;
&amp;lt;/source&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Be sure to change any references to old paths in the django &amp;quot;mysite&amp;quot; settings.py file&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Group Project ==&lt;br /&gt;
&lt;br /&gt;
You may work in pairs on this project. Your group will create an image tagging and browsing site using Django as described below.&lt;br /&gt;
&lt;br /&gt;
=== Image Tagging/Browsing Site ===&lt;br /&gt;
&lt;br /&gt;
A site that lets users upload images, apply multiple tags to them, and browse through images of a certain tag.&lt;br /&gt;
When looking at an image, it lists all associated tags so you can switch albums.&lt;br /&gt;
&lt;br /&gt;
==== Requirements ====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Make a database that stores images and tags. An image can have multiple tags, and each tag can have multiple images.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;The home page should allow users to find tags that they want to view. (e.g. lolcat).&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;After clicking a link to a tag, it should take you to a page with the newest image for that tag.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Clicking on the current image should take to to the next image according to date added. When at the last image, link to the first.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Make it clear which tag you are currently browsing. Beside or below the current image, also display the full list of tags that belong to the current image (e.g. lolcat, meme, internet, funny). You should be able to click on any of the tags to begin looking through that collection of images.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Provide a way for users who are logged in to add new images and new tags.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Validate user input&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Provide a way for users to register, login, and change their password.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Have a link that sends an email to a user with a link for resetting their password in case they forget it.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Style the site with statically-served CSS (i.e. link to static .css files and don't write CSS inside the html templates) &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Notes ====&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;You may store images as external web links. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Try to find and figure out as many Django shortcuts as you can. You do not need to write your own url parsing, validation, login/registration/reset forms etc. For these common tasks, there is almost always built-in functionality that will do what you want in very few lines.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;The admin interface and the interactive python shell will be very helpful when getting started with the database.&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Grading ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;font-size:2em; line-height:2em;&amp;quot;&amp;gt;'''Due Date: Wednesday December 5th by 1pm (both individual and group)'''&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
!Python Assignment (Individual)&lt;br /&gt;
!Points&lt;br /&gt;
|-&lt;br /&gt;
|Compute Final Grades&lt;br /&gt;
|0.25&lt;br /&gt;
|-&lt;br /&gt;
|Compute Letter Grade&lt;br /&gt;
|0.25&lt;br /&gt;
|-&lt;br /&gt;
|Sort by Last Name&lt;br /&gt;
|0.25&lt;br /&gt;
|-&lt;br /&gt;
|Accept Command Line Argument&lt;br /&gt;
|0.25&lt;br /&gt;
|-&lt;br /&gt;
!colspan=&amp;quot;2&amp;quot;|Django Assignment (Individual)&lt;br /&gt;
|- &lt;br /&gt;
|Models defined, database set up       &lt;br /&gt;
|0.25&lt;br /&gt;
|-&lt;br /&gt;
|Admin app enabled and working&lt;br /&gt;
|0.25&lt;br /&gt;
|-&lt;br /&gt;
|URLs matched to correct views&lt;br /&gt;
|0.25&lt;br /&gt;
|-&lt;br /&gt;
|Templates for viewing and voting using generic views&lt;br /&gt;
|0.25&lt;br /&gt;
|-&lt;br /&gt;
|Apache serving the site&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
!colspan=&amp;quot;2&amp;quot;|Group Portion:&lt;br /&gt;
|-&lt;br /&gt;
|Models defined and database set up&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|View of single image with current tag and list of all tags&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Navigation between images and tags&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
|Main page displays all tags sorted by number of images&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
|User registration, login/logout and change password&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
|Forgot password sends email with working reset link&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
|Validation of all user input&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
|Add new images and tags, only if logged in&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
|Static CSS applied to some templates&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
|Creative Portion&lt;br /&gt;
|2&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Total Points = 10&lt;br /&gt;
&lt;br /&gt;
Turn in after 1pm on the 5th = 1 point off&lt;br /&gt;
&lt;br /&gt;
Turn in on the 6th = 2 points off&lt;br /&gt;
&lt;br /&gt;
Turn in on the 7th = 3 points off&lt;br /&gt;
&lt;br /&gt;
All projects should be completed by the last day of class, Friday the 7th.  Any modules that have not been demo'd at that time will be given a grade of zero.  You are responsible for making sure you can attend TA hours to demo if you are late (or for contacting a TA to try and arrange a session).  You cannot demo by e-mail.  &lt;br /&gt;
&lt;br /&gt;
[[Category:Module 6]]&lt;br /&gt;
[[Category:Modules]]&lt;/div&gt;</summary>
		<author><name>Marc</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=Module_5&amp;diff=915</id>
		<title>Module 5</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=Module_5&amp;diff=915"/>
		<updated>2012-11-26T17:41:01Z</updated>

		<summary type="html">&lt;p&gt;Marc: /* Grading */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In Module 6, you will learn about python, a programming language, and Django, a web framework.&lt;br /&gt;
&lt;br /&gt;
This article contains your assignments for Module 6.&lt;br /&gt;
&lt;br /&gt;
== Individual Assignments ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Python Tutorial ===&lt;br /&gt;
&lt;br /&gt;
====Install Python Tools====&lt;br /&gt;
*&amp;lt;code&amp;gt;sudo yum install python-setuptools&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
*&amp;lt;code&amp;gt;sudo yum install python-devel&amp;lt;/code&amp;gt;&lt;br /&gt;
====Python Assignment====&lt;br /&gt;
*You will write a python script that reads a set of student grades in from a file and does some basic parsing and processing. [http://docs.python.org/tutorial/inputoutput.html#reading-and-writing-files here] is the section of the python tutorial on reading and writing files.&lt;br /&gt;
*An example grades file is [http://research.engineering.wustl.edu/~todd/cse330/grades.txt here]. For the sake of simplicity you can assume that the file name is always going to be grades.txt.&lt;br /&gt;
*The first line of the file is of the form: NUM_LABS,NUM_EXAMS,LAB_WEIGHT&lt;br /&gt;
*All of the other lines in the file are of the form: FIRSTNAME LASTNAME|GRADE|TYPE&lt;br /&gt;
*The FIRSTNAME and LASTNAME fields are the student's full name (always only a first and last name), the GRADE is one grade for the student, and the TYPE describes what kind of assignment the grade was for, in this case either a 'lab' or an 'exam'.&lt;br /&gt;
*Your script should read in a grades file with the above format and perform the following:&lt;br /&gt;
*# Compute the final grade for every student, given that there were a total of NUM_LABS labs, NUM_EXAMS exams, and that the labs account for a total of LAB_WEIGHT percent of the grade.&lt;br /&gt;
*# Compute the final letter grade based on the final numeric grade (A = 90 or above, B = 80 - 90, C = 70 - 80, D = 60 - 70, F = below 60). &lt;br /&gt;
*# Ignore any blank lines.&lt;br /&gt;
*# Sort the students by last name, and print out final grades in that sorted order.&lt;br /&gt;
*# No names should be hard coded into the script (you will run your script on another file with different student names when we grade your assignment).&lt;br /&gt;
*# Finally, the script should take one optional command line argument, which is a string to match against student names.  Only names that match the string in full or in part, should be printed out with their final grades.&lt;br /&gt;
*#*For example, with the argument 'John' grades for both John Smith and John Locke should be printed (if those are the only two Johns in the grades.txt file)&lt;br /&gt;
&lt;br /&gt;
=== Django Tutorial===&lt;br /&gt;
====Install Djgano====&lt;br /&gt;
&amp;lt;p&amp;gt; This procedure assumes you are using and Amazon AMI Linux on an ec2 instance. An in-depth install guide can be found on the [https://docs.djangoproject.com/en/dev/topics/install/# Django website], but a quick version is below. Run these commands as root. &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Install Distribute (prerequisite for pip):&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;curl http://python-distribute.org/distribute_setup.py | python&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Install pip:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;curl https://raw.github.com/pypa/pip/master/contrib/get-pip.py | python&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Install Django using pip:&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;pip install Django&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt; That's it. &amp;lt;/p&amp;gt;&lt;br /&gt;
====Django Assignment====&lt;br /&gt;
&amp;lt;p&amp;gt;Complete the [https://docs.djangoproject.com/en/1.4/intro/tutorial01/ tutorial] on the django website. You will create a Polls app. There are four parts to this tutorial.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;It is important you do all the steps in the tutorial to get comfortable defining models, views, templates, and using the interactive shell and the admin app. Understanding the concepts will make the project go much quicker.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;h5&amp;gt;[https://docs.djangoproject.com/en/1.4/intro/tutorial01/ Part 1]&amp;lt;/h5&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Create a project&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Start the development server&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Setup an SQLite database&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Create the Polls app and define the models&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Interact with the database using the interactive python shell&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&lt;br /&gt;
&amp;lt;h5&amp;gt;[https://docs.djangoproject.com/en/1.4/intro/tutorial02/ Part 2]&amp;lt;/h5&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Activate the admin site&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Add the poll app to the admin site&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Modify the database using the admin site&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&lt;br /&gt;
&amp;lt;h5&amp;gt;[https://docs.djangoproject.com/en/1.4/intro/tutorial03/ Part 3]&amp;lt;/h5&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Configure URL handling&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Create some views&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&lt;br /&gt;
&amp;lt;h5&amp;gt;[https://docs.djangoproject.com/en/1.4/intro/tutorial04/ Part 4]&amp;lt;/h5&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Write a form that modifies the database&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Refactor to use generic views&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h5&amp;gt;Switch to Apache Webserver&amp;lt;/h5&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;run &amp;lt;code&amp;gt;yum install mod_wsgi&amp;lt;/code&amp;gt; to install the apache and the module necessary for serving your django app.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Add these lines to /etc/httpd/conf/httpd.conf&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;Alias /static /var/www/*APPNAME*/static&lt;br /&gt;
&amp;lt;Directory /var/www/*APPNAME*/static&amp;gt;&lt;br /&gt;
Order deny,allow&lt;br /&gt;
Allow from all&lt;br /&gt;
&amp;lt;/Directory&amp;gt;&lt;br /&gt;
WSGIScriptAlias / /var/www/*APPNAME*/apache/django.wsgi&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Move your app to /var/www and make the directory /var/www/*APPNAME*/apache. In that directory create the file django.wsgi and Inside that file put:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import os&lt;br /&gt;
import sys&lt;br /&gt;
sys.path.append('/var/www/*APPNAME*')&lt;br /&gt;
os.environ['DJANGO_SETTINGS_MODULE'] = '*APPNAME*.settings'&lt;br /&gt;
import django.core.handlers.wsgi&lt;br /&gt;
application = django.core.handlers.wsgi.WSGIHandler()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Be sure to change any references to old paths in the django settings.py file&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Group Project ==&lt;br /&gt;
&lt;br /&gt;
You may work in pairs on this project. Your group will create an image tagging and browsing site using Django as described below.&lt;br /&gt;
&lt;br /&gt;
=== Image Tagging/Browsing Site ===&lt;br /&gt;
&lt;br /&gt;
A site that lets users upload images, apply multiple tags to them, and browse through images of a certain tag.&lt;br /&gt;
When looking at an image, it lists all associated tags so you can switch albums.&lt;br /&gt;
&lt;br /&gt;
==== Requirements ====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Make a database that stores images and tags. An image can have multiple tags, and each tag can have multiple images.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;The home page should allow users to find tags that they want to view. (e.g. lolcat).&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;After clicking a link to a tag, it should take you to a page with the newest image for that tag.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Clicking on the current image should take to to the next image according to date added. When at the last image, link to the first.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Make it clear which tag you are currently browsing. Beside or below the current image, also display the full list of tags that belong to the current image (e.g. lolcat, meme, internet, funny). You should be able to click on any of the tags to begin looking through that collection of images.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Provide a way for users who are logged in to add new images and new tags.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Validate user input&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Provide a way for users to register, login, and change their password.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Have a link that sends an email to a user with a link for resetting their password in case they forget it.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Style the site with statically-served CSS (i.e. link to static .css files and don't write CSS inside the html templates) &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Notes ====&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;You may store images as external web links. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Try to find and figure out as many Django shortcuts as you can. You do not need to write your own url parsing, validation, login/registration/reset forms etc. For these common tasks, there is almost always built-in functionality that will do what you want in very few lines.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;The admin interface and the interactive python shell will be very helpful when getting started with the database.&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Grading ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;font-size:2em; line-height:2em;&amp;quot;&amp;gt;'''Due Date: Wednesday December 5th by 1pm (both individual and group)'''&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
!Python Assignment (Individual)&lt;br /&gt;
!Points&lt;br /&gt;
|-&lt;br /&gt;
|Compute Final Grades&lt;br /&gt;
|0.25&lt;br /&gt;
|-&lt;br /&gt;
|Compute Letter Grade&lt;br /&gt;
|0.25&lt;br /&gt;
|-&lt;br /&gt;
|Sort by Last Name&lt;br /&gt;
|0.25&lt;br /&gt;
|-&lt;br /&gt;
|Accept Command Line Argument&lt;br /&gt;
|0.25&lt;br /&gt;
|-&lt;br /&gt;
!colspan=&amp;quot;2&amp;quot;|Django Assignment (Individual)&lt;br /&gt;
|- &lt;br /&gt;
|Models defined, database set up       &lt;br /&gt;
|0.25&lt;br /&gt;
|-&lt;br /&gt;
|Admin app enabled and working&lt;br /&gt;
|0.25&lt;br /&gt;
|-&lt;br /&gt;
|URLs matched to correct views&lt;br /&gt;
|0.25&lt;br /&gt;
|-&lt;br /&gt;
|Templates for viewing and voting using generic views&lt;br /&gt;
|0.25&lt;br /&gt;
|-&lt;br /&gt;
|Apache serving the site&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
!colspan=&amp;quot;2&amp;quot;|Group Portion:&lt;br /&gt;
|-&lt;br /&gt;
|Models defined and database set up&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|View of single image with current tag and list of all tags&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Navigation between images and tags&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
|Main page displays all tags sorted by number of images&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
|User registration, login/logout and change password&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
|Forgot password sends email with working reset link&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
|Validation of all user input&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
|Add new images and tags, only if logged in&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
|Static CSS applied to some templates&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
|Creative Portion&lt;br /&gt;
|2&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Total Points = 10&lt;br /&gt;
&lt;br /&gt;
Turn in after 1pm on the 5th = 1 point off&lt;br /&gt;
&lt;br /&gt;
Turn in on the 6th = 2 points off&lt;br /&gt;
&lt;br /&gt;
Turn in on the 7th = 3 points off&lt;br /&gt;
&lt;br /&gt;
All projects should be completed by the last day of class, Friday the 7th.  &lt;br /&gt;
&lt;br /&gt;
[[Category:Module 6]]&lt;br /&gt;
[[Category:Modules]]&lt;/div&gt;</summary>
		<author><name>Marc</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=Module_5&amp;diff=914</id>
		<title>Module 5</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=Module_5&amp;diff=914"/>
		<updated>2012-11-26T17:40:28Z</updated>

		<summary type="html">&lt;p&gt;Marc: /* Grading */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In Module 6, you will learn about python, a programming language, and Django, a web framework.&lt;br /&gt;
&lt;br /&gt;
This article contains your assignments for Module 6.&lt;br /&gt;
&lt;br /&gt;
== Individual Assignments ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Python Tutorial ===&lt;br /&gt;
&lt;br /&gt;
====Install Python Tools====&lt;br /&gt;
*&amp;lt;code&amp;gt;sudo yum install python-setuptools&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
*&amp;lt;code&amp;gt;sudo yum install python-devel&amp;lt;/code&amp;gt;&lt;br /&gt;
====Python Assignment====&lt;br /&gt;
*You will write a python script that reads a set of student grades in from a file and does some basic parsing and processing. [http://docs.python.org/tutorial/inputoutput.html#reading-and-writing-files here] is the section of the python tutorial on reading and writing files.&lt;br /&gt;
*An example grades file is [http://research.engineering.wustl.edu/~todd/cse330/grades.txt here]. For the sake of simplicity you can assume that the file name is always going to be grades.txt.&lt;br /&gt;
*The first line of the file is of the form: NUM_LABS,NUM_EXAMS,LAB_WEIGHT&lt;br /&gt;
*All of the other lines in the file are of the form: FIRSTNAME LASTNAME|GRADE|TYPE&lt;br /&gt;
*The FIRSTNAME and LASTNAME fields are the student's full name (always only a first and last name), the GRADE is one grade for the student, and the TYPE describes what kind of assignment the grade was for, in this case either a 'lab' or an 'exam'.&lt;br /&gt;
*Your script should read in a grades file with the above format and perform the following:&lt;br /&gt;
*# Compute the final grade for every student, given that there were a total of NUM_LABS labs, NUM_EXAMS exams, and that the labs account for a total of LAB_WEIGHT percent of the grade.&lt;br /&gt;
*# Compute the final letter grade based on the final numeric grade (A = 90 or above, B = 80 - 90, C = 70 - 80, D = 60 - 70, F = below 60). &lt;br /&gt;
*# Ignore any blank lines.&lt;br /&gt;
*# Sort the students by last name, and print out final grades in that sorted order.&lt;br /&gt;
*# No names should be hard coded into the script (you will run your script on another file with different student names when we grade your assignment).&lt;br /&gt;
*# Finally, the script should take one optional command line argument, which is a string to match against student names.  Only names that match the string in full or in part, should be printed out with their final grades.&lt;br /&gt;
*#*For example, with the argument 'John' grades for both John Smith and John Locke should be printed (if those are the only two Johns in the grades.txt file)&lt;br /&gt;
&lt;br /&gt;
=== Django Tutorial===&lt;br /&gt;
====Install Djgano====&lt;br /&gt;
&amp;lt;p&amp;gt; This procedure assumes you are using and Amazon AMI Linux on an ec2 instance. An in-depth install guide can be found on the [https://docs.djangoproject.com/en/dev/topics/install/# Django website], but a quick version is below. Run these commands as root. &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Install Distribute (prerequisite for pip):&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;curl http://python-distribute.org/distribute_setup.py | python&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Install pip:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;curl https://raw.github.com/pypa/pip/master/contrib/get-pip.py | python&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Install Django using pip:&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;pip install Django&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt; That's it. &amp;lt;/p&amp;gt;&lt;br /&gt;
====Django Assignment====&lt;br /&gt;
&amp;lt;p&amp;gt;Complete the [https://docs.djangoproject.com/en/1.4/intro/tutorial01/ tutorial] on the django website. You will create a Polls app. There are four parts to this tutorial.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;It is important you do all the steps in the tutorial to get comfortable defining models, views, templates, and using the interactive shell and the admin app. Understanding the concepts will make the project go much quicker.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;h5&amp;gt;[https://docs.djangoproject.com/en/1.4/intro/tutorial01/ Part 1]&amp;lt;/h5&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Create a project&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Start the development server&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Setup an SQLite database&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Create the Polls app and define the models&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Interact with the database using the interactive python shell&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&lt;br /&gt;
&amp;lt;h5&amp;gt;[https://docs.djangoproject.com/en/1.4/intro/tutorial02/ Part 2]&amp;lt;/h5&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Activate the admin site&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Add the poll app to the admin site&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Modify the database using the admin site&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&lt;br /&gt;
&amp;lt;h5&amp;gt;[https://docs.djangoproject.com/en/1.4/intro/tutorial03/ Part 3]&amp;lt;/h5&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Configure URL handling&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Create some views&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&lt;br /&gt;
&amp;lt;h5&amp;gt;[https://docs.djangoproject.com/en/1.4/intro/tutorial04/ Part 4]&amp;lt;/h5&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Write a form that modifies the database&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Refactor to use generic views&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h5&amp;gt;Switch to Apache Webserver&amp;lt;/h5&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;run &amp;lt;code&amp;gt;yum install mod_wsgi&amp;lt;/code&amp;gt; to install the apache and the module necessary for serving your django app.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Add these lines to /etc/httpd/conf/httpd.conf&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;Alias /static /var/www/*APPNAME*/static&lt;br /&gt;
&amp;lt;Directory /var/www/*APPNAME*/static&amp;gt;&lt;br /&gt;
Order deny,allow&lt;br /&gt;
Allow from all&lt;br /&gt;
&amp;lt;/Directory&amp;gt;&lt;br /&gt;
WSGIScriptAlias / /var/www/*APPNAME*/apache/django.wsgi&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Move your app to /var/www and make the directory /var/www/*APPNAME*/apache. In that directory create the file django.wsgi and Inside that file put:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import os&lt;br /&gt;
import sys&lt;br /&gt;
sys.path.append('/var/www/*APPNAME*')&lt;br /&gt;
os.environ['DJANGO_SETTINGS_MODULE'] = '*APPNAME*.settings'&lt;br /&gt;
import django.core.handlers.wsgi&lt;br /&gt;
application = django.core.handlers.wsgi.WSGIHandler()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Be sure to change any references to old paths in the django settings.py file&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Group Project ==&lt;br /&gt;
&lt;br /&gt;
You may work in pairs on this project. Your group will create an image tagging and browsing site using Django as described below.&lt;br /&gt;
&lt;br /&gt;
=== Image Tagging/Browsing Site ===&lt;br /&gt;
&lt;br /&gt;
A site that lets users upload images, apply multiple tags to them, and browse through images of a certain tag.&lt;br /&gt;
When looking at an image, it lists all associated tags so you can switch albums.&lt;br /&gt;
&lt;br /&gt;
==== Requirements ====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Make a database that stores images and tags. An image can have multiple tags, and each tag can have multiple images.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;The home page should allow users to find tags that they want to view. (e.g. lolcat).&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;After clicking a link to a tag, it should take you to a page with the newest image for that tag.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Clicking on the current image should take to to the next image according to date added. When at the last image, link to the first.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Make it clear which tag you are currently browsing. Beside or below the current image, also display the full list of tags that belong to the current image (e.g. lolcat, meme, internet, funny). You should be able to click on any of the tags to begin looking through that collection of images.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Provide a way for users who are logged in to add new images and new tags.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Validate user input&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Provide a way for users to register, login, and change their password.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Have a link that sends an email to a user with a link for resetting their password in case they forget it.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Style the site with statically-served CSS (i.e. link to static .css files and don't write CSS inside the html templates) &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Notes ====&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;You may store images as external web links. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Try to find and figure out as many Django shortcuts as you can. You do not need to write your own url parsing, validation, login/registration/reset forms etc. For these common tasks, there is almost always built-in functionality that will do what you want in very few lines.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;The admin interface and the interactive python shell will be very helpful when getting started with the database.&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Grading ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;font-size:2em; line-height:2em;&amp;quot;&amp;gt;'''Due Date: Wednesday December 5th by 1pm (both individual and group)'''&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
!Python Assignment&lt;br /&gt;
!Points&lt;br /&gt;
|-&lt;br /&gt;
|Compute Final Grades&lt;br /&gt;
|0.25&lt;br /&gt;
|-&lt;br /&gt;
|Compute Letter Grade&lt;br /&gt;
|0.25&lt;br /&gt;
|-&lt;br /&gt;
|Sort by Last Name&lt;br /&gt;
|0.25&lt;br /&gt;
|-&lt;br /&gt;
|Accept Command Line Argument&lt;br /&gt;
|0.25&lt;br /&gt;
|-&lt;br /&gt;
!colspan=&amp;quot;2&amp;quot;|Django Assignment:&lt;br /&gt;
|- &lt;br /&gt;
|Models defined, database set up       &lt;br /&gt;
|0.25&lt;br /&gt;
|-&lt;br /&gt;
|Admin app enabled and working&lt;br /&gt;
|0.25&lt;br /&gt;
|-&lt;br /&gt;
|URLs matched to correct views&lt;br /&gt;
|0.25&lt;br /&gt;
|-&lt;br /&gt;
|Templates for viewing and voting using generic views&lt;br /&gt;
|0.25&lt;br /&gt;
|-&lt;br /&gt;
|Apache serving the site&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
!colspan=&amp;quot;2&amp;quot;|Group Portion:&lt;br /&gt;
|-&lt;br /&gt;
|Models defined and database set up&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|View of single image with current tag and list of all tags&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Navigation between images and tags&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
|Main page displays all tags sorted by number of images&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
|User registration, login/logout and change password&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
|Forgot password sends email with working reset link&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
|Validation of all user input&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
|Add new images and tags, only if logged in&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
|Static CSS applied to some templates&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
|Creative Portion&lt;br /&gt;
|2&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Total Points = 10&lt;br /&gt;
&lt;br /&gt;
Turn in after 1pm on the 5th = 1 point off&lt;br /&gt;
&lt;br /&gt;
Turn in on the 6th = 2 points off&lt;br /&gt;
&lt;br /&gt;
Turn in on the 7th = 3 points off&lt;br /&gt;
&lt;br /&gt;
All projects should be completed by the last day of class, Friday the 7th.  &lt;br /&gt;
&lt;br /&gt;
[[Category:Module 6]]&lt;br /&gt;
[[Category:Modules]]&lt;/div&gt;</summary>
		<author><name>Marc</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=Module_5&amp;diff=913</id>
		<title>Module 5</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=Module_5&amp;diff=913"/>
		<updated>2012-11-26T17:39:58Z</updated>

		<summary type="html">&lt;p&gt;Marc: /* Grading */  fixed points, it only summed up to 9 before my earlier change, which changed it to 8, and now its back at 10&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In Module 6, you will learn about python, a programming language, and Django, a web framework.&lt;br /&gt;
&lt;br /&gt;
This article contains your assignments for Module 6.&lt;br /&gt;
&lt;br /&gt;
== Individual Assignments ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Python Tutorial ===&lt;br /&gt;
&lt;br /&gt;
====Install Python Tools====&lt;br /&gt;
*&amp;lt;code&amp;gt;sudo yum install python-setuptools&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
*&amp;lt;code&amp;gt;sudo yum install python-devel&amp;lt;/code&amp;gt;&lt;br /&gt;
====Python Assignment====&lt;br /&gt;
*You will write a python script that reads a set of student grades in from a file and does some basic parsing and processing. [http://docs.python.org/tutorial/inputoutput.html#reading-and-writing-files here] is the section of the python tutorial on reading and writing files.&lt;br /&gt;
*An example grades file is [http://research.engineering.wustl.edu/~todd/cse330/grades.txt here]. For the sake of simplicity you can assume that the file name is always going to be grades.txt.&lt;br /&gt;
*The first line of the file is of the form: NUM_LABS,NUM_EXAMS,LAB_WEIGHT&lt;br /&gt;
*All of the other lines in the file are of the form: FIRSTNAME LASTNAME|GRADE|TYPE&lt;br /&gt;
*The FIRSTNAME and LASTNAME fields are the student's full name (always only a first and last name), the GRADE is one grade for the student, and the TYPE describes what kind of assignment the grade was for, in this case either a 'lab' or an 'exam'.&lt;br /&gt;
*Your script should read in a grades file with the above format and perform the following:&lt;br /&gt;
*# Compute the final grade for every student, given that there were a total of NUM_LABS labs, NUM_EXAMS exams, and that the labs account for a total of LAB_WEIGHT percent of the grade.&lt;br /&gt;
*# Compute the final letter grade based on the final numeric grade (A = 90 or above, B = 80 - 90, C = 70 - 80, D = 60 - 70, F = below 60). &lt;br /&gt;
*# Ignore any blank lines.&lt;br /&gt;
*# Sort the students by last name, and print out final grades in that sorted order.&lt;br /&gt;
*# No names should be hard coded into the script (you will run your script on another file with different student names when we grade your assignment).&lt;br /&gt;
*# Finally, the script should take one optional command line argument, which is a string to match against student names.  Only names that match the string in full or in part, should be printed out with their final grades.&lt;br /&gt;
*#*For example, with the argument 'John' grades for both John Smith and John Locke should be printed (if those are the only two Johns in the grades.txt file)&lt;br /&gt;
&lt;br /&gt;
=== Django Tutorial===&lt;br /&gt;
====Install Djgano====&lt;br /&gt;
&amp;lt;p&amp;gt; This procedure assumes you are using and Amazon AMI Linux on an ec2 instance. An in-depth install guide can be found on the [https://docs.djangoproject.com/en/dev/topics/install/# Django website], but a quick version is below. Run these commands as root. &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Install Distribute (prerequisite for pip):&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;curl http://python-distribute.org/distribute_setup.py | python&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Install pip:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;curl https://raw.github.com/pypa/pip/master/contrib/get-pip.py | python&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Install Django using pip:&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;pip install Django&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt; That's it. &amp;lt;/p&amp;gt;&lt;br /&gt;
====Django Assignment====&lt;br /&gt;
&amp;lt;p&amp;gt;Complete the [https://docs.djangoproject.com/en/1.4/intro/tutorial01/ tutorial] on the django website. You will create a Polls app. There are four parts to this tutorial.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;It is important you do all the steps in the tutorial to get comfortable defining models, views, templates, and using the interactive shell and the admin app. Understanding the concepts will make the project go much quicker.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;h5&amp;gt;[https://docs.djangoproject.com/en/1.4/intro/tutorial01/ Part 1]&amp;lt;/h5&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Create a project&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Start the development server&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Setup an SQLite database&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Create the Polls app and define the models&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Interact with the database using the interactive python shell&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&lt;br /&gt;
&amp;lt;h5&amp;gt;[https://docs.djangoproject.com/en/1.4/intro/tutorial02/ Part 2]&amp;lt;/h5&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Activate the admin site&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Add the poll app to the admin site&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Modify the database using the admin site&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&lt;br /&gt;
&amp;lt;h5&amp;gt;[https://docs.djangoproject.com/en/1.4/intro/tutorial03/ Part 3]&amp;lt;/h5&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Configure URL handling&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Create some views&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&lt;br /&gt;
&amp;lt;h5&amp;gt;[https://docs.djangoproject.com/en/1.4/intro/tutorial04/ Part 4]&amp;lt;/h5&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Write a form that modifies the database&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Refactor to use generic views&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h5&amp;gt;Switch to Apache Webserver&amp;lt;/h5&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;run &amp;lt;code&amp;gt;yum install mod_wsgi&amp;lt;/code&amp;gt; to install the apache and the module necessary for serving your django app.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Add these lines to /etc/httpd/conf/httpd.conf&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;Alias /static /var/www/*APPNAME*/static&lt;br /&gt;
&amp;lt;Directory /var/www/*APPNAME*/static&amp;gt;&lt;br /&gt;
Order deny,allow&lt;br /&gt;
Allow from all&lt;br /&gt;
&amp;lt;/Directory&amp;gt;&lt;br /&gt;
WSGIScriptAlias / /var/www/*APPNAME*/apache/django.wsgi&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Move your app to /var/www and make the directory /var/www/*APPNAME*/apache. In that directory create the file django.wsgi and Inside that file put:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import os&lt;br /&gt;
import sys&lt;br /&gt;
sys.path.append('/var/www/*APPNAME*')&lt;br /&gt;
os.environ['DJANGO_SETTINGS_MODULE'] = '*APPNAME*.settings'&lt;br /&gt;
import django.core.handlers.wsgi&lt;br /&gt;
application = django.core.handlers.wsgi.WSGIHandler()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Be sure to change any references to old paths in the django settings.py file&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Group Project ==&lt;br /&gt;
&lt;br /&gt;
You may work in pairs on this project. Your group will create an image tagging and browsing site using Django as described below.&lt;br /&gt;
&lt;br /&gt;
=== Image Tagging/Browsing Site ===&lt;br /&gt;
&lt;br /&gt;
A site that lets users upload images, apply multiple tags to them, and browse through images of a certain tag.&lt;br /&gt;
When looking at an image, it lists all associated tags so you can switch albums.&lt;br /&gt;
&lt;br /&gt;
==== Requirements ====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Make a database that stores images and tags. An image can have multiple tags, and each tag can have multiple images.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;The home page should allow users to find tags that they want to view. (e.g. lolcat).&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;After clicking a link to a tag, it should take you to a page with the newest image for that tag.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Clicking on the current image should take to to the next image according to date added. When at the last image, link to the first.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Make it clear which tag you are currently browsing. Beside or below the current image, also display the full list of tags that belong to the current image (e.g. lolcat, meme, internet, funny). You should be able to click on any of the tags to begin looking through that collection of images.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Provide a way for users who are logged in to add new images and new tags.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Validate user input&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Provide a way for users to register, login, and change their password.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Have a link that sends an email to a user with a link for resetting their password in case they forget it.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Style the site with statically-served CSS (i.e. link to static .css files and don't write CSS inside the html templates) &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Notes ====&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;You may store images as external web links. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Try to find and figure out as many Django shortcuts as you can. You do not need to write your own url parsing, validation, login/registration/reset forms etc. For these common tasks, there is almost always built-in functionality that will do what you want in very few lines.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;The admin interface and the interactive python shell will be very helpful when getting started with the database.&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Grading ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;font-size:2em; line-height:2em;&amp;quot;&amp;gt;'''Due Date: Wednesday December 5th by 1pm (both individual and group)'''&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
!Python Assignment&lt;br /&gt;
!Points&lt;br /&gt;
|-&lt;br /&gt;
|Compute Final Grades&lt;br /&gt;
|0.25&lt;br /&gt;
|-&lt;br /&gt;
|Compute Letter Grade&lt;br /&gt;
|0.25&lt;br /&gt;
|-&lt;br /&gt;
|Sort by Last Name&lt;br /&gt;
|0.25&lt;br /&gt;
|-&lt;br /&gt;
|Accept Command Line Argument&lt;br /&gt;
|0.25&lt;br /&gt;
|-&lt;br /&gt;
!colspan=&amp;quot;2&amp;quot;|Django Assignment:&lt;br /&gt;
|- &lt;br /&gt;
|Models defined, database set up       &lt;br /&gt;
|0.25&lt;br /&gt;
|-&lt;br /&gt;
|Admin app enabled and working&lt;br /&gt;
|0.25&lt;br /&gt;
|-&lt;br /&gt;
|URLs matched to correct views&lt;br /&gt;
|0.25&lt;br /&gt;
|-&lt;br /&gt;
|Templates for viewing and voting using generic views&lt;br /&gt;
|0.25&lt;br /&gt;
|-&lt;br /&gt;
|Apache serving the site&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
!colspan=&amp;quot;2&amp;quot;|Group Portion:&lt;br /&gt;
|-&lt;br /&gt;
|Models defined and database set up&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|View of single image with current tag and list of all tags&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Navigation between images and tags&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
|Main page displays all tags sorted by number of images&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
|User registration, login/logout and change password&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
|Forgot password sends email with working reset link&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
|Validation of all user input&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
|Add new images and tags, only if logged in&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
|Static CSS applied to some templates&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
|Creative Portion&lt;br /&gt;
|2&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Total Points = 9&lt;br /&gt;
&lt;br /&gt;
Turn in after 1pm on the 5th = 1 point off&lt;br /&gt;
&lt;br /&gt;
Turn in on the 6th = 2 points off&lt;br /&gt;
&lt;br /&gt;
Turn in on the 7th = 3 points off&lt;br /&gt;
&lt;br /&gt;
All projects should be completed by the last day of class, Friday the 7th.  &lt;br /&gt;
&lt;br /&gt;
[[Category:Module 6]]&lt;br /&gt;
[[Category:Modules]]&lt;/div&gt;</summary>
		<author><name>Marc</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=Module_5&amp;diff=912</id>
		<title>Module 5</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=Module_5&amp;diff=912"/>
		<updated>2012-11-26T17:38:38Z</updated>

		<summary type="html">&lt;p&gt;Marc: /* Grading */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In Module 6, you will learn about python, a programming language, and Django, a web framework.&lt;br /&gt;
&lt;br /&gt;
This article contains your assignments for Module 6.&lt;br /&gt;
&lt;br /&gt;
== Individual Assignments ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Python Tutorial ===&lt;br /&gt;
&lt;br /&gt;
====Install Python Tools====&lt;br /&gt;
*&amp;lt;code&amp;gt;sudo yum install python-setuptools&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
*&amp;lt;code&amp;gt;sudo yum install python-devel&amp;lt;/code&amp;gt;&lt;br /&gt;
====Python Assignment====&lt;br /&gt;
*You will write a python script that reads a set of student grades in from a file and does some basic parsing and processing. [http://docs.python.org/tutorial/inputoutput.html#reading-and-writing-files here] is the section of the python tutorial on reading and writing files.&lt;br /&gt;
*An example grades file is [http://research.engineering.wustl.edu/~todd/cse330/grades.txt here]. For the sake of simplicity you can assume that the file name is always going to be grades.txt.&lt;br /&gt;
*The first line of the file is of the form: NUM_LABS,NUM_EXAMS,LAB_WEIGHT&lt;br /&gt;
*All of the other lines in the file are of the form: FIRSTNAME LASTNAME|GRADE|TYPE&lt;br /&gt;
*The FIRSTNAME and LASTNAME fields are the student's full name (always only a first and last name), the GRADE is one grade for the student, and the TYPE describes what kind of assignment the grade was for, in this case either a 'lab' or an 'exam'.&lt;br /&gt;
*Your script should read in a grades file with the above format and perform the following:&lt;br /&gt;
*# Compute the final grade for every student, given that there were a total of NUM_LABS labs, NUM_EXAMS exams, and that the labs account for a total of LAB_WEIGHT percent of the grade.&lt;br /&gt;
*# Compute the final letter grade based on the final numeric grade (A = 90 or above, B = 80 - 90, C = 70 - 80, D = 60 - 70, F = below 60). &lt;br /&gt;
*# Ignore any blank lines.&lt;br /&gt;
*# Sort the students by last name, and print out final grades in that sorted order.&lt;br /&gt;
*# No names should be hard coded into the script (you will run your script on another file with different student names when we grade your assignment).&lt;br /&gt;
*# Finally, the script should take one optional command line argument, which is a string to match against student names.  Only names that match the string in full or in part, should be printed out with their final grades.&lt;br /&gt;
*#*For example, with the argument 'John' grades for both John Smith and John Locke should be printed (if those are the only two Johns in the grades.txt file)&lt;br /&gt;
&lt;br /&gt;
=== Django Tutorial===&lt;br /&gt;
====Install Djgano====&lt;br /&gt;
&amp;lt;p&amp;gt; This procedure assumes you are using and Amazon AMI Linux on an ec2 instance. An in-depth install guide can be found on the [https://docs.djangoproject.com/en/dev/topics/install/# Django website], but a quick version is below. Run these commands as root. &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Install Distribute (prerequisite for pip):&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;curl http://python-distribute.org/distribute_setup.py | python&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Install pip:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;curl https://raw.github.com/pypa/pip/master/contrib/get-pip.py | python&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Install Django using pip:&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;pip install Django&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt; That's it. &amp;lt;/p&amp;gt;&lt;br /&gt;
====Django Assignment====&lt;br /&gt;
&amp;lt;p&amp;gt;Complete the [https://docs.djangoproject.com/en/1.4/intro/tutorial01/ tutorial] on the django website. You will create a Polls app. There are four parts to this tutorial.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;It is important you do all the steps in the tutorial to get comfortable defining models, views, templates, and using the interactive shell and the admin app. Understanding the concepts will make the project go much quicker.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;h5&amp;gt;[https://docs.djangoproject.com/en/1.4/intro/tutorial01/ Part 1]&amp;lt;/h5&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Create a project&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Start the development server&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Setup an SQLite database&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Create the Polls app and define the models&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Interact with the database using the interactive python shell&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&lt;br /&gt;
&amp;lt;h5&amp;gt;[https://docs.djangoproject.com/en/1.4/intro/tutorial02/ Part 2]&amp;lt;/h5&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Activate the admin site&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Add the poll app to the admin site&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Modify the database using the admin site&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&lt;br /&gt;
&amp;lt;h5&amp;gt;[https://docs.djangoproject.com/en/1.4/intro/tutorial03/ Part 3]&amp;lt;/h5&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Configure URL handling&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Create some views&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&lt;br /&gt;
&amp;lt;h5&amp;gt;[https://docs.djangoproject.com/en/1.4/intro/tutorial04/ Part 4]&amp;lt;/h5&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Write a form that modifies the database&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Refactor to use generic views&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h5&amp;gt;Switch to Apache Webserver&amp;lt;/h5&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;run &amp;lt;code&amp;gt;yum install mod_wsgi&amp;lt;/code&amp;gt; to install the apache and the module necessary for serving your django app.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Add these lines to /etc/httpd/conf/httpd.conf&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;Alias /static /var/www/*APPNAME*/static&lt;br /&gt;
&amp;lt;Directory /var/www/*APPNAME*/static&amp;gt;&lt;br /&gt;
Order deny,allow&lt;br /&gt;
Allow from all&lt;br /&gt;
&amp;lt;/Directory&amp;gt;&lt;br /&gt;
WSGIScriptAlias / /var/www/*APPNAME*/apache/django.wsgi&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Move your app to /var/www and make the directory /var/www/*APPNAME*/apache. In that directory create the file django.wsgi and Inside that file put:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import os&lt;br /&gt;
import sys&lt;br /&gt;
sys.path.append('/var/www/*APPNAME*')&lt;br /&gt;
os.environ['DJANGO_SETTINGS_MODULE'] = '*APPNAME*.settings'&lt;br /&gt;
import django.core.handlers.wsgi&lt;br /&gt;
application = django.core.handlers.wsgi.WSGIHandler()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Be sure to change any references to old paths in the django settings.py file&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Group Project ==&lt;br /&gt;
&lt;br /&gt;
You may work in pairs on this project. Your group will create an image tagging and browsing site using Django as described below.&lt;br /&gt;
&lt;br /&gt;
=== Image Tagging/Browsing Site ===&lt;br /&gt;
&lt;br /&gt;
A site that lets users upload images, apply multiple tags to them, and browse through images of a certain tag.&lt;br /&gt;
When looking at an image, it lists all associated tags so you can switch albums.&lt;br /&gt;
&lt;br /&gt;
==== Requirements ====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Make a database that stores images and tags. An image can have multiple tags, and each tag can have multiple images.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;The home page should allow users to find tags that they want to view. (e.g. lolcat).&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;After clicking a link to a tag, it should take you to a page with the newest image for that tag.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Clicking on the current image should take to to the next image according to date added. When at the last image, link to the first.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Make it clear which tag you are currently browsing. Beside or below the current image, also display the full list of tags that belong to the current image (e.g. lolcat, meme, internet, funny). You should be able to click on any of the tags to begin looking through that collection of images.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Provide a way for users who are logged in to add new images and new tags.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Validate user input&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Provide a way for users to register, login, and change their password.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Have a link that sends an email to a user with a link for resetting their password in case they forget it.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Style the site with statically-served CSS (i.e. link to static .css files and don't write CSS inside the html templates) &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Notes ====&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;You may store images as external web links. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Try to find and figure out as many Django shortcuts as you can. You do not need to write your own url parsing, validation, login/registration/reset forms etc. For these common tasks, there is almost always built-in functionality that will do what you want in very few lines.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;The admin interface and the interactive python shell will be very helpful when getting started with the database.&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Grading ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;font-size:2em; line-height:2em;&amp;quot;&amp;gt;'''Due Date: Wednesday December 5th by 1pm (both individual and group)'''&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
!Python Assignment&lt;br /&gt;
!Points&lt;br /&gt;
|-&lt;br /&gt;
|Compute Final Grades&lt;br /&gt;
|0.25&lt;br /&gt;
|-&lt;br /&gt;
|Compute Letter Grade&lt;br /&gt;
|0.25&lt;br /&gt;
|-&lt;br /&gt;
|Sort by Last Name&lt;br /&gt;
|0.25&lt;br /&gt;
|-&lt;br /&gt;
|Accept Command Line Argument&lt;br /&gt;
|0.25&lt;br /&gt;
|-&lt;br /&gt;
!colspan=&amp;quot;2&amp;quot;|Django Assignment:&lt;br /&gt;
|- &lt;br /&gt;
|Models defined, database set up       &lt;br /&gt;
|0.25&lt;br /&gt;
|-&lt;br /&gt;
|Admin app enabled and working&lt;br /&gt;
|0.25&lt;br /&gt;
|-&lt;br /&gt;
|URLs matched to correct views&lt;br /&gt;
|0.25&lt;br /&gt;
|-&lt;br /&gt;
|Templates for viewing and voting using generic views&lt;br /&gt;
|0.25&lt;br /&gt;
|-&lt;br /&gt;
|Apache serving the site&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
!colspan=&amp;quot;2&amp;quot;|Group Portion:&lt;br /&gt;
|-&lt;br /&gt;
|Models defined and database set up&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
|View of single image with current tag and list of all tags&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
|Navigation between images and tags&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
|Main page displays all tags sorted by number of images&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
|User registration, login/logout and change password&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
|Forgot password sends email with working reset link&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
|Validation of all user input&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
|Add new images and tags, only if logged in&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
|Static CSS applied to some templates&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
|Creative Portion&lt;br /&gt;
|2&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Total Points = 9&lt;br /&gt;
&lt;br /&gt;
Turn in after 1pm on the 5th = 1 point off&lt;br /&gt;
&lt;br /&gt;
Turn in on the 6th = 2 points off&lt;br /&gt;
&lt;br /&gt;
Turn in on the 7th = 3 points off&lt;br /&gt;
&lt;br /&gt;
All projects should be completed by the last day of class, Friday the 7th.  &lt;br /&gt;
&lt;br /&gt;
[[Category:Module 6]]&lt;br /&gt;
[[Category:Modules]]&lt;/div&gt;</summary>
		<author><name>Marc</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=Module_5&amp;diff=911</id>
		<title>Module 5</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=Module_5&amp;diff=911"/>
		<updated>2012-11-26T17:36:50Z</updated>

		<summary type="html">&lt;p&gt;Marc: /* Grading */  changed creative t0 1 point, clearled explained late points&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In Module 6, you will learn about python, a programming language, and Django, a web framework.&lt;br /&gt;
&lt;br /&gt;
This article contains your assignments for Module 6.&lt;br /&gt;
&lt;br /&gt;
== Individual Assignments ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Python Tutorial ===&lt;br /&gt;
&lt;br /&gt;
====Install Python Tools====&lt;br /&gt;
*&amp;lt;code&amp;gt;sudo yum install python-setuptools&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
*&amp;lt;code&amp;gt;sudo yum install python-devel&amp;lt;/code&amp;gt;&lt;br /&gt;
====Python Assignment====&lt;br /&gt;
*You will write a python script that reads a set of student grades in from a file and does some basic parsing and processing. [http://docs.python.org/tutorial/inputoutput.html#reading-and-writing-files here] is the section of the python tutorial on reading and writing files.&lt;br /&gt;
*An example grades file is [http://research.engineering.wustl.edu/~todd/cse330/grades.txt here]. For the sake of simplicity you can assume that the file name is always going to be grades.txt.&lt;br /&gt;
*The first line of the file is of the form: NUM_LABS,NUM_EXAMS,LAB_WEIGHT&lt;br /&gt;
*All of the other lines in the file are of the form: FIRSTNAME LASTNAME|GRADE|TYPE&lt;br /&gt;
*The FIRSTNAME and LASTNAME fields are the student's full name (always only a first and last name), the GRADE is one grade for the student, and the TYPE describes what kind of assignment the grade was for, in this case either a 'lab' or an 'exam'.&lt;br /&gt;
*Your script should read in a grades file with the above format and perform the following:&lt;br /&gt;
*# Compute the final grade for every student, given that there were a total of NUM_LABS labs, NUM_EXAMS exams, and that the labs account for a total of LAB_WEIGHT percent of the grade.&lt;br /&gt;
*# Compute the final letter grade based on the final numeric grade (A = 90 or above, B = 80 - 90, C = 70 - 80, D = 60 - 70, F = below 60). &lt;br /&gt;
*# Ignore any blank lines.&lt;br /&gt;
*# Sort the students by last name, and print out final grades in that sorted order.&lt;br /&gt;
*# No names should be hard coded into the script (you will run your script on another file with different student names when we grade your assignment).&lt;br /&gt;
*# Finally, the script should take one optional command line argument, which is a string to match against student names.  Only names that match the string in full or in part, should be printed out with their final grades.&lt;br /&gt;
*#*For example, with the argument 'John' grades for both John Smith and John Locke should be printed (if those are the only two Johns in the grades.txt file)&lt;br /&gt;
&lt;br /&gt;
=== Django Tutorial===&lt;br /&gt;
====Install Djgano====&lt;br /&gt;
&amp;lt;p&amp;gt; This procedure assumes you are using and Amazon AMI Linux on an ec2 instance. An in-depth install guide can be found on the [https://docs.djangoproject.com/en/dev/topics/install/# Django website], but a quick version is below. Run these commands as root. &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Install Distribute (prerequisite for pip):&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;curl http://python-distribute.org/distribute_setup.py | python&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Install pip:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;curl https://raw.github.com/pypa/pip/master/contrib/get-pip.py | python&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Install Django using pip:&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;pip install Django&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt; That's it. &amp;lt;/p&amp;gt;&lt;br /&gt;
====Django Assignment====&lt;br /&gt;
&amp;lt;p&amp;gt;Complete the [https://docs.djangoproject.com/en/1.4/intro/tutorial01/ tutorial] on the django website. You will create a Polls app. There are four parts to this tutorial.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;It is important you do all the steps in the tutorial to get comfortable defining models, views, templates, and using the interactive shell and the admin app. Understanding the concepts will make the project go much quicker.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;h5&amp;gt;[https://docs.djangoproject.com/en/1.4/intro/tutorial01/ Part 1]&amp;lt;/h5&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Create a project&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Start the development server&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Setup an SQLite database&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Create the Polls app and define the models&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Interact with the database using the interactive python shell&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&lt;br /&gt;
&amp;lt;h5&amp;gt;[https://docs.djangoproject.com/en/1.4/intro/tutorial02/ Part 2]&amp;lt;/h5&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Activate the admin site&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Add the poll app to the admin site&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Modify the database using the admin site&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&lt;br /&gt;
&amp;lt;h5&amp;gt;[https://docs.djangoproject.com/en/1.4/intro/tutorial03/ Part 3]&amp;lt;/h5&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Configure URL handling&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Create some views&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&lt;br /&gt;
&amp;lt;h5&amp;gt;[https://docs.djangoproject.com/en/1.4/intro/tutorial04/ Part 4]&amp;lt;/h5&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Write a form that modifies the database&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Refactor to use generic views&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h5&amp;gt;Switch to Apache Webserver&amp;lt;/h5&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;run &amp;lt;code&amp;gt;yum install mod_wsgi&amp;lt;/code&amp;gt; to install the apache and the module necessary for serving your django app.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Add these lines to /etc/httpd/conf/httpd.conf&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;Alias /static /var/www/*APPNAME*/static&lt;br /&gt;
&amp;lt;Directory /var/www/*APPNAME*/static&amp;gt;&lt;br /&gt;
Order deny,allow&lt;br /&gt;
Allow from all&lt;br /&gt;
&amp;lt;/Directory&amp;gt;&lt;br /&gt;
WSGIScriptAlias / /var/www/*APPNAME*/apache/django.wsgi&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Move your app to /var/www and make the directory /var/www/*APPNAME*/apache. In that directory create the file django.wsgi and Inside that file put:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import os&lt;br /&gt;
import sys&lt;br /&gt;
sys.path.append('/var/www/*APPNAME*')&lt;br /&gt;
os.environ['DJANGO_SETTINGS_MODULE'] = '*APPNAME*.settings'&lt;br /&gt;
import django.core.handlers.wsgi&lt;br /&gt;
application = django.core.handlers.wsgi.WSGIHandler()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Be sure to change any references to old paths in the django settings.py file&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Group Project ==&lt;br /&gt;
&lt;br /&gt;
You may work in pairs on this project. Your group will create an image tagging and browsing site using Django as described below.&lt;br /&gt;
&lt;br /&gt;
=== Image Tagging/Browsing Site ===&lt;br /&gt;
&lt;br /&gt;
A site that lets users upload images, apply multiple tags to them, and browse through images of a certain tag.&lt;br /&gt;
When looking at an image, it lists all associated tags so you can switch albums.&lt;br /&gt;
&lt;br /&gt;
==== Requirements ====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Make a database that stores images and tags. An image can have multiple tags, and each tag can have multiple images.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;The home page should allow users to find tags that they want to view. (e.g. lolcat).&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;After clicking a link to a tag, it should take you to a page with the newest image for that tag.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Clicking on the current image should take to to the next image according to date added. When at the last image, link to the first.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Make it clear which tag you are currently browsing. Beside or below the current image, also display the full list of tags that belong to the current image (e.g. lolcat, meme, internet, funny). You should be able to click on any of the tags to begin looking through that collection of images.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Provide a way for users who are logged in to add new images and new tags.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Validate user input&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Provide a way for users to register, login, and change their password.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Have a link that sends an email to a user with a link for resetting their password in case they forget it.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Style the site with statically-served CSS (i.e. link to static .css files and don't write CSS inside the html templates) &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Notes ====&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;You may store images as external web links. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Try to find and figure out as many Django shortcuts as you can. You do not need to write your own url parsing, validation, login/registration/reset forms etc. For these common tasks, there is almost always built-in functionality that will do what you want in very few lines.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;The admin interface and the interactive python shell will be very helpful when getting started with the database.&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Grading ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;font-size:2em; line-height:2em;&amp;quot;&amp;gt;'''Due Date: Wednesday December 5th by 1pm (both individual and group)'''&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
!Python Assignment&lt;br /&gt;
!Points&lt;br /&gt;
|-&lt;br /&gt;
|Compute Final Grades&lt;br /&gt;
|0.25&lt;br /&gt;
|-&lt;br /&gt;
|Compute Letter Grade&lt;br /&gt;
|0.25&lt;br /&gt;
|-&lt;br /&gt;
|Sort by Last Name&lt;br /&gt;
|0.25&lt;br /&gt;
|-&lt;br /&gt;
|Accept Command Line Argument&lt;br /&gt;
|0.25&lt;br /&gt;
|-&lt;br /&gt;
!colspan=&amp;quot;2&amp;quot;|Django Assignment:&lt;br /&gt;
|- &lt;br /&gt;
|Models defined, database set up       &lt;br /&gt;
|0.25&lt;br /&gt;
|-&lt;br /&gt;
|Admin app enabled and working&lt;br /&gt;
|0.25&lt;br /&gt;
|-&lt;br /&gt;
|URLs matched to correct views&lt;br /&gt;
|0.25&lt;br /&gt;
|-&lt;br /&gt;
|Templates for viewing and voting using generic views&lt;br /&gt;
|0.25&lt;br /&gt;
|-&lt;br /&gt;
|Apache serving the site&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
!colspan=&amp;quot;2&amp;quot;|Group Portion:&lt;br /&gt;
|-&lt;br /&gt;
|Models defined and database set up&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
|View of single image with current tag and list of all tags&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
|Navigation between images and tags&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
|Main page displays all tags sorted by number of images&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
|User registration, login/logout and change password&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
|Forgot password sends email with working reset link&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
|Validation of all user input&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
|Add new images and tags, only if logged in&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
|Static CSS applied to some templates&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
|Creative Portion&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Total Points = 10&lt;br /&gt;
&lt;br /&gt;
Turn in after 1pm on the 5th = 1 point off&lt;br /&gt;
&lt;br /&gt;
Turn in on the 6th = 2 points off&lt;br /&gt;
&lt;br /&gt;
Turn in on the 7th = 3 points off&lt;br /&gt;
&lt;br /&gt;
All projects should be completed by the last day of class, Friday the 7th.  &lt;br /&gt;
&lt;br /&gt;
[[Category:Module 6]]&lt;br /&gt;
[[Category:Modules]]&lt;/div&gt;</summary>
		<author><name>Marc</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=Module_6&amp;diff=892</id>
		<title>Module 6</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=Module_6&amp;diff=892"/>
		<updated>2012-10-31T23:36:39Z</updated>

		<summary type="html">&lt;p&gt;Marc: /* Grading */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In Module 4, you will learn about JavaScript, the prevailing client-side language, and AJAX, a method for performing asynchronous updates to a web page (without refreshing the page).&lt;br /&gt;
&lt;br /&gt;
This article contains your assignments for Module 4.&lt;br /&gt;
&lt;br /&gt;
== Individual Assignments ==&lt;br /&gt;
&lt;br /&gt;
=== JavaScript Calculator ===&lt;br /&gt;
&lt;br /&gt;
In Module 2, you made a calculator using PHP.  Now you will be making one using JavaScript.&lt;br /&gt;
&lt;br /&gt;
Read the JavaScript guide first: [[Javascript and AJAX]]&lt;br /&gt;
&lt;br /&gt;
* The web page should have two input fields and a radio button group for the operation, with the 4 basic math operations represented (add, subtract, multiply, divide).&lt;br /&gt;
* JavaScript should monitor all three fields and display the current result whenever the user changes any value in any field, without refreshing the page.&lt;br /&gt;
*: '''Tip 1:''' Consider using either the ''change'' or the ''keyup'' event on the text fields, and either the ''change'' or the ''click'' event on the radio buttons.&lt;br /&gt;
*: '''Tip 2:''' Re-read [[Javascript and AJAX|the JavaScript guide]] if you need help figuring our how to bind callback functions to events, or how to determine which radio button is currently selected.  (There are examples for both of these!)&lt;br /&gt;
* The calculator should be completely self-contained; i.e., you should not be making any requests to any other server-side or client-side scripts or web pages after the initial page load.&lt;br /&gt;
&lt;br /&gt;
'''Tip:''' You can embed JavaScript code into an HTML document like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;
// your code here&lt;br /&gt;
&amp;lt;/script&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Tip:''' If your code isn't working the way you expect, use a JavaScript error console.  In Chrome, for example, press Ctrl-Shift-I (or Cmd-Option-I) to open the WebKit inspector.&lt;br /&gt;
&lt;br /&gt;
=== Weather Widget ===&lt;br /&gt;
&lt;br /&gt;
In this section, you will make a web page that displays the weather forecast using AJAX requests to a weather server.  You should complete this section ''without'' using JavaScript libraries like jQuery.&lt;br /&gt;
&lt;br /&gt;
# Make an empty HTML document; name it '''weather.html'''&lt;br /&gt;
#: Refer to the [[HTML and CSS]] guide for the skeleton of an HTML document&lt;br /&gt;
# Define a function in JavaScript; call it '''fetchWeather()'''.  You may write your JavaScript in an embedded script in your head tag.&lt;br /&gt;
# Inside your '''fetchWeather()''' function, make an AJAX request to the weather server.&lt;br /&gt;
#: We have a server that outputs the current weather in JSON format.  The format is documented in the [[#JSON Structure]] section below.&lt;br /&gt;
#: '''URL:''' http://research.engineering.wustl.edu/~todd/cse330/module4/weather_json.php&lt;br /&gt;
#: We kindly thank Yahoo Weather for providing us with up-to-date weather information.&lt;br /&gt;
#* '''IMPORTANT:''' Under normal circumstances, AJAX requests ''cannot'' be performed cross-domain for security reasons.  We have set the &amp;lt;code&amp;gt;Access-Control-Allow-Origin&amp;lt;/code&amp;gt; header on our server to allow requests from your EC2 instances, or from localhost.  '''You will therefore need to upload your code to your EC2, or access it via localhost, in order for the AJAX requests to work.'''  This means that you cannot, for example, complete this part of the individual portion in JSFiddle.&lt;br /&gt;
# In your callback, process the JSON and use JavaScript to manipulate the HTML DOM to display the following information on your page:&lt;br /&gt;
#* Location&lt;br /&gt;
#** City, in a &amp;lt;nowiki&amp;gt;&amp;lt;strong&amp;gt;&amp;lt;/nowiki&amp;gt; tag&lt;br /&gt;
#** State, not in any tag&lt;br /&gt;
#* Humidity&lt;br /&gt;
#* Current Temperature&lt;br /&gt;
#* Image for Tomorrow's Forecast (see [[#Weather Condition Images]] below for more information)&lt;br /&gt;
#* Image for the Day After Tomorrow's Forecast&lt;br /&gt;
# Finally, bind '''fetchWeather()''' to the DOMContentLoaded event so that your weather widget is automatically initialized when the page is loaded:&lt;br /&gt;
#: &amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;document.addEventListener(&amp;quot;DOMContentLoaded&amp;quot;, fetchWeather, false);&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Use the following HTML:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;weather&amp;quot; id=&amp;quot;weatherWidget&amp;quot;&amp;gt;&lt;br /&gt;
	&amp;lt;div class=&amp;quot;weather-loc&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
	&amp;lt;div class=&amp;quot;weather-humidity&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
	&amp;lt;div class=&amp;quot;weather-temp&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
	&amp;lt;img class=&amp;quot;weather-tomorrow&amp;quot; /&amp;gt;&lt;br /&gt;
	&amp;lt;img class=&amp;quot;weather-dayaftertomorrow&amp;quot; /&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Include the CSS file from here: http://research.engineering.wustl.edu/~todd/cse330/module4/weather.css&lt;br /&gt;
&lt;br /&gt;
When everything is working, the weather widget should look something like this:&lt;br /&gt;
&lt;br /&gt;
[[File:WeatherWidget.png]]&lt;br /&gt;
&lt;br /&gt;
'''Important:''' The widget in this section needs to work in only Firefox and Chrome.  It does '''''not''''' need to work Internet Explorer.&lt;br /&gt;
&lt;br /&gt;
==== Tips ====&lt;br /&gt;
&lt;br /&gt;
===== JSON Structure =====&lt;br /&gt;
&lt;br /&gt;
The JSON from our server looks like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
   &amp;quot;updated&amp;quot;: &amp;quot;Thu, 11 Oct 2012 5:54 pm CDT&amp;quot;,&lt;br /&gt;
   &amp;quot;location&amp;quot;: {&lt;br /&gt;
      &amp;quot;city&amp;quot;: &amp;quot;St. Louis&amp;quot;,&lt;br /&gt;
      &amp;quot;state&amp;quot;: &amp;quot;MO&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;wind&amp;quot;: {&lt;br /&gt;
      &amp;quot;chill&amp;quot;: &amp;quot;62&amp;quot;,&lt;br /&gt;
      &amp;quot;direction&amp;quot;: &amp;quot;150&amp;quot;,&lt;br /&gt;
      &amp;quot;speed&amp;quot;: &amp;quot;3 mph&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;atmosphere&amp;quot;: {&lt;br /&gt;
      &amp;quot;humidity&amp;quot;: &amp;quot;50&amp;quot;,&lt;br /&gt;
      &amp;quot;visibility&amp;quot;: &amp;quot;10&amp;quot;,&lt;br /&gt;
      &amp;quot;pressure&amp;quot;: &amp;quot;30.12 in&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;current&amp;quot;: {&lt;br /&gt;
      &amp;quot;code&amp;quot;: &amp;quot;28&amp;quot;,&lt;br /&gt;
      &amp;quot;text&amp;quot;: &amp;quot;Mostly Cloudy&amp;quot;,&lt;br /&gt;
      &amp;quot;temp&amp;quot;: &amp;quot;62°F&amp;quot;,&lt;br /&gt;
      &amp;quot;date&amp;quot;: &amp;quot;Thu, 11 Oct 2012 5:54 pm CDT&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;tomorrow&amp;quot;: {&lt;br /&gt;
      &amp;quot;code&amp;quot;: &amp;quot;29&amp;quot;,&lt;br /&gt;
      &amp;quot;text&amp;quot;: &amp;quot;Clouds Early/Clearing Late&amp;quot;,&lt;br /&gt;
      &amp;quot;low&amp;quot;: &amp;quot;45°F&amp;quot;,&lt;br /&gt;
      &amp;quot;high&amp;quot;: &amp;quot;61°F&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;dayafter&amp;quot;: {&lt;br /&gt;
      &amp;quot;code&amp;quot;: &amp;quot;30&amp;quot;,&lt;br /&gt;
      &amp;quot;text&amp;quot;: &amp;quot;Partly Cloudy&amp;quot;,&lt;br /&gt;
      &amp;quot;low&amp;quot;: &amp;quot;53°F&amp;quot;,&lt;br /&gt;
      &amp;quot;high&amp;quot;: &amp;quot;65°F&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;credit&amp;quot;: &amp;quot;http://us.rd.yahoo.com/dailynews/rss/weather/St._Louis__MO/*http://weather.yahoo.com/forecast/USMO0170_f.html&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Weather Condition Images =====&lt;br /&gt;
&lt;br /&gt;
Each day's forecast has a code.  There are images associated with these codes.&lt;br /&gt;
&lt;br /&gt;
One place to get the images is from here: &amp;lt;nowiki&amp;gt;http://us.yimg.com/i/us/nws/weather/gr/&amp;lt;/nowiki&amp;gt;'''##'''&amp;lt;nowiki&amp;gt;ds.png&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Replace the '''##''' with the forecast code.  For example, for code 32, the URL would be: http://us.yimg.com/i/us/nws/weather/gr/32ds.png&lt;br /&gt;
&lt;br /&gt;
=== jQuery Dialogs ===&lt;br /&gt;
&lt;br /&gt;
Helpful Resource: [http://docs.jquery.com/Main_Page jQuery Documentation] ... Some additional tips: [[jQuery]]&lt;br /&gt;
&lt;br /&gt;
Create a simple page using jQuery dialogs.&lt;br /&gt;
&lt;br /&gt;
* Create a page that has the words &amp;quot;Google&amp;quot; and &amp;quot;Yahoo&amp;quot;.&lt;br /&gt;
* When the user clicks the &amp;quot;Google&amp;quot; text, open a jQuery dialog window with one jQuery dialog button.  If the button is pressed, display the Google logo image (the image can be stored on your web server) on the web page, and if the dialog is closed any other way, do nothing.&lt;br /&gt;
* When the user clicks the &amp;quot;Yahoo&amp;quot; text, open a jQuery dialog window with one jQuery dialog button.  If the button is pressed, display the Yahoo logo image (the image can be stored on your web server) on the web page, and if the dialog is closed any other way, do nothing.&lt;br /&gt;
* Initially there should be no image on the page (i.e., the img should be hidden with the CSS display attribute).  After one of the two images is displayed, if the user clicks on the image, a jQuery dialog box should be opened with one dialog button, and if the button is pressed then the image should be hidden again.  Otherwise, do nothing.&lt;br /&gt;
&lt;br /&gt;
== Group Project ==&lt;br /&gt;
&lt;br /&gt;
You will work in pairs on this project.&lt;br /&gt;
&lt;br /&gt;
'''Important Reminder:''' frequently commit your work to your subversion repository as a backup!&lt;br /&gt;
&lt;br /&gt;
I forgot if I already mentioned this, but '''start early on this project!''' It will take longer than you think, I promise!&lt;br /&gt;
&lt;br /&gt;
=== Calendar ===&lt;br /&gt;
&lt;br /&gt;
Build a simple calendar that allows users to add and remove events dynamically.&lt;br /&gt;
&lt;br /&gt;
You will use JavaScript to process user interactions at the web browser, without ever refreshing the browser after the initial web page load.  You may use a JavaScript library of your choice, including jQuery.  (No extra credit will be given for ''not'' using a JavaScript library.)&lt;br /&gt;
&lt;br /&gt;
Your application should utilize AJAX to run server-side PHP scripts that query your database to save and retrieve information, including user accounts and events.&lt;br /&gt;
&lt;br /&gt;
==== Examples ====&lt;br /&gt;
&lt;br /&gt;
* https://calendar.google.com/&lt;br /&gt;
* http://www.zoho.com/calendar/&lt;br /&gt;
&lt;br /&gt;
==== Requirements ====&lt;br /&gt;
&lt;br /&gt;
* Support a month-by-month view of the calendar.&lt;br /&gt;
*: Show one month at a time, with buttons to move forward or backward.&lt;br /&gt;
*: There should be no limit to how far forward or backward the user can go.&lt;br /&gt;
* Users can register and log in to the website.&lt;br /&gt;
*: You may leverage your MySQL project code and database from last week to get started.&lt;br /&gt;
*: You may alternatively use [[Web Application Security, Part 2#OpenID|OpenID]] for user authentication.  Note that you will still need a Users table in order associate calendar events with a certain OpenID.&lt;br /&gt;
* Unregistered users should see no events on the calendar.&lt;br /&gt;
* Registered users can add events.&lt;br /&gt;
*: All events should have a date and time, but do not need to have a duration.&lt;br /&gt;
*: You do ''not'' need to support recurring events (where you add an event that repeats, for example, every monday).&lt;br /&gt;
* Registered users see only events that they have added.&lt;br /&gt;
*: Your AJAX should not ask the server for events from a certain username.  Instead, your AJAX should ask the server for events, and the server should respond with the events for only the currently-logged-in user (from the session).  Can you think of why?&lt;br /&gt;
* Registered users can delete their events, but not the events of others.&lt;br /&gt;
*: Again, the server should delete events based on the username present in the session.  (If it deletes only based on an Event ID, an attacker could feed any arbitrary Event ID to your server, even if he/she didn't own that event.)&lt;br /&gt;
* All user and event data should be kept in a database.&lt;br /&gt;
* At no time should the main page need to be reloaded.&lt;br /&gt;
*: User registration, user authentication, event addition, and event deletion should all be handled by JavaScript and AJAX requests to your server.&lt;br /&gt;
* Your page needs to work in the versions of Firefox and Chrome installed on the lab computers.&lt;br /&gt;
&lt;br /&gt;
'''Tip:''' Run your database schema by a TA before implementing it.&lt;br /&gt;
&lt;br /&gt;
==== Calendar Helper Library ====&lt;br /&gt;
&lt;br /&gt;
To help you get started with your calendar, we have written some JavaScript helper functions.  The code is available at:&lt;br /&gt;
* Full Version (for you to refer): http://research.engineering.wustl.edu/~todd/cse330/module4/calendar.js&lt;br /&gt;
* Minified Version (to include in your pages):http://research.engineering.wustl.edu/~todd/cse330/module4/calendar.min.js&lt;br /&gt;
&lt;br /&gt;
For example, this is how you would make a button to load the next month and show alerts containing all the days in the weeks contained by that month.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
// For our purposes, we can keep the current month in a variable in the global scope&lt;br /&gt;
var currentMonth = new Month(2012, 9); // October 2012&lt;br /&gt;
&lt;br /&gt;
// Change the month when the &amp;quot;next&amp;quot; button is pressed&lt;br /&gt;
document.getElementById(&amp;quot;next_month_btn&amp;quot;).addEventListener(&amp;quot;click&amp;quot;, function(event){&lt;br /&gt;
	currentMonth = currentMonth.nextMonth(); // Previous month would be currentMonth.prevMonth()&lt;br /&gt;
	updateCalendar(); // Whenever the month is updated, we'll need to re-render the calendar in HTML&lt;br /&gt;
	alert(&amp;quot;The new month is &amp;quot;+currentMonth.month+&amp;quot; &amp;quot;+currentMonth.year);&lt;br /&gt;
}, false);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
// This updateCalendar() function only alerts the dates in the currently specified month.  You need to write&lt;br /&gt;
// it to modify the DOM (optionally using jQuery) to display the days and weeks in the current month.&lt;br /&gt;
function updateCalendar(){&lt;br /&gt;
	var weeks = currentMonth.getWeeks();&lt;br /&gt;
	&lt;br /&gt;
	for(var w in weeks){&lt;br /&gt;
		var days = weeks[w].getDates();&lt;br /&gt;
		// days contains normal JavaScript Date objects.&lt;br /&gt;
		&lt;br /&gt;
		alert(&amp;quot;Week starting on &amp;quot;+days[0]);&lt;br /&gt;
		&lt;br /&gt;
		for(var d in days){&lt;br /&gt;
			// You can see console.log() output in your JavaScript debugging tool, like Firebug,&lt;br /&gt;
			// WebWit Inspector, or Dragonfly.&lt;br /&gt;
			console.log(days[d].toISOString());&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Important:''' JavaScript starts the months of a year, and the days of a week, at index 0.  This means that '''''in JavaScript, January is month 0, and December is month 11.'''''  Our calendar helper functions maintain this JavaScript convention.&lt;br /&gt;
&lt;br /&gt;
=== Web Security and Validation ===&lt;br /&gt;
&lt;br /&gt;
Your project needs to demonstrate that thought was put into web security and best practice.  For more information, see this week's Web Application Security guide: [[Web Application Security, Part 3]]&lt;br /&gt;
&lt;br /&gt;
In particular:&lt;br /&gt;
&lt;br /&gt;
* '''Your application needs to prevent XSS attacks.'''  The easiest way to prevent this is to continue sanitizing ''all'' of your output using '''htmlentities()'''.&lt;br /&gt;
* '''Perform precautionary measures to prevent session hijacking attacks.'''&lt;br /&gt;
*: You should specify your session cookie to be HTTP-Only.  However, for the means of this module, you need not test for user agent consistency.&lt;br /&gt;
* '''Optional:''' Validate your JavaScript code using [http://www.jshint.com/ JSHint] '''''or''''' [http://jslint.com/ JSLint] for 0.5 points of Creative Portion.&lt;br /&gt;
&lt;br /&gt;
You should continue the practices that you have learned in past weeks:&lt;br /&gt;
&lt;br /&gt;
* Pass tokens in forms to prevent CSRF attacks.&lt;br /&gt;
*: '''Hint:''' You will need to send your CSRF tokens in your AJAX requests.  Remember that AJAX still submits forms and runs server-side scripts, just like the vanilla forms you've been using in Modules 2 and 3.&lt;br /&gt;
* Use prepared queries to prevent SQL Injection attacks.&lt;br /&gt;
* If storing passwords in a database, always store them salted and encrypted.&lt;br /&gt;
* Your page should validate with no errors through the W3C validator.&lt;br /&gt;
&lt;br /&gt;
== Grading ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;font-size:2em; line-height:2em;&amp;quot;&amp;gt;'''Due Date: Monday, October 29th by 1pm (both individual and group)'''&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Please see the notes at the bottom:&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
!Assignment&lt;br /&gt;
!Points&lt;br /&gt;
|-&lt;br /&gt;
|Calculator&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
|Weather Widget&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|jQuery Dialogs&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
!colspan=&amp;quot;2&amp;quot;|Group Portion:&lt;br /&gt;
|-&lt;br /&gt;
|Calendar month view correct and Move between months (without page reload)&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|User authentication and registration (without page reload)&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Add events (new event shown in calendar without page reload)&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Events added are private and other users cannot see them&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
|Delete events (event removed from calendar without page reload)&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
|-&lt;br /&gt;
|Safe from XSS and Session Hijacking&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|-&lt;br /&gt;
|Validation, CSRF, Salted Passwords, Safe SQL Queries&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Creative Portion&lt;br /&gt;
|2&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Total: 10 Points&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*You must get your creative portion part approved from any TA at least one day before the due date.  The creative portion is worth 20% of the module grade, and your effort should reflect this.  You may receive a deduction if your creative portion idea is not approved.&lt;br /&gt;
&lt;br /&gt;
*You will still lose one point per day late.  As the module is only worth 10 points, that results in a 10% penalty.  (Note that all modules are weighted similarly, 10 points for this module does not mean it is only worth half of the previous module).&lt;br /&gt;
&lt;br /&gt;
*Late Penalty: Monday by Midnight (-1), Tuesday by Midnight (-2), Wednesday by Midnight (-3), Thursday by Midnight (-4), Friday by Midnight (-5).  After that, please talk to the instructor.&lt;br /&gt;
&lt;br /&gt;
[[Category:Module 4]]&lt;br /&gt;
[[Category:Modules]]&lt;/div&gt;</summary>
		<author><name>Marc</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=Module_6&amp;diff=888</id>
		<title>Module 6</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=Module_6&amp;diff=888"/>
		<updated>2012-10-26T03:16:42Z</updated>

		<summary type="html">&lt;p&gt;Marc: /* Web Security and Validation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In Module 4, you will learn about JavaScript, the prevailing client-side language, and AJAX, a method for performing asynchronous updates to a web page (without refreshing the page).&lt;br /&gt;
&lt;br /&gt;
This article contains your assignments for Module 4.&lt;br /&gt;
&lt;br /&gt;
== Individual Assignments ==&lt;br /&gt;
&lt;br /&gt;
=== JavaScript Calculator ===&lt;br /&gt;
&lt;br /&gt;
In Module 2, you made a calculator using PHP.  Now you will be making one using JavaScript.&lt;br /&gt;
&lt;br /&gt;
Read the JavaScript guide first: [[Javascript and AJAX]]&lt;br /&gt;
&lt;br /&gt;
* The web page should have two input fields and a radio button group for the operation, with the 4 basic math operations represented (add, subtract, multiply, divide).&lt;br /&gt;
* JavaScript should monitor all three fields and display the current result whenever the user changes any value in any field, without refreshing the page.&lt;br /&gt;
*: '''Tip 1:''' Consider using either the ''change'' or the ''keyup'' event on the text fields, and either the ''change'' or the ''click'' event on the radio buttons.&lt;br /&gt;
*: '''Tip 2:''' Re-read [[Javascript and AJAX|the JavaScript guide]] if you need help figuring our how to bind callback functions to events, or how to determine which radio button is currently selected.  (There are examples for both of these!)&lt;br /&gt;
* The calculator should be completely self-contained; i.e., you should not be making any requests to any other server-side or client-side scripts or web pages after the initial page load.&lt;br /&gt;
&lt;br /&gt;
'''Tip:''' You can embed JavaScript code into an HTML document like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;
// your code here&lt;br /&gt;
&amp;lt;/script&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Tip:''' If your code isn't working the way you expect, use a JavaScript error console.  In Chrome, for example, press Ctrl-Shift-I (or Cmd-Option-I) to open the WebKit inspector.&lt;br /&gt;
&lt;br /&gt;
=== Weather Widget ===&lt;br /&gt;
&lt;br /&gt;
In this section, you will make a web page that displays the weather forecast using AJAX requests to a weather server.  You should complete this section ''without'' using JavaScript libraries like jQuery.&lt;br /&gt;
&lt;br /&gt;
# Make an empty HTML document; name it '''weather.html'''&lt;br /&gt;
#: Refer to the [[HTML and CSS]] guide for the skeleton of an HTML document&lt;br /&gt;
# Define a function in JavaScript; call it '''fetchWeather()'''.  You may write your JavaScript in an embedded script in your head tag.&lt;br /&gt;
# Inside your '''fetchWeather()''' function, make an AJAX request to the weather server.&lt;br /&gt;
#: We have a server that outputs the current weather in JSON format.  The format is documented in the [[#JSON Structure]] section below.&lt;br /&gt;
#: '''URL:''' http://research.engineering.wustl.edu/~todd/cse330/module4/weather_json.php&lt;br /&gt;
#: We kindly thank Yahoo Weather for providing us with up-to-date weather information.&lt;br /&gt;
#* '''IMPORTANT:''' Under normal circumstances, AJAX requests ''cannot'' be performed cross-domain for security reasons.  We have set the &amp;lt;code&amp;gt;Access-Control-Allow-Origin&amp;lt;/code&amp;gt; header on our server to allow requests from your EC2 instances, or from localhost.  '''You will therefore need to upload your code to your EC2, or access it via localhost, in order for the AJAX requests to work.'''  This means that you cannot, for example, complete this part of the individual portion in JSFiddle.&lt;br /&gt;
# In your callback, process the JSON and use JavaScript to manipulate the HTML DOM to display the following information on your page:&lt;br /&gt;
#* Location&lt;br /&gt;
#** City, in a &amp;lt;nowiki&amp;gt;&amp;lt;strong&amp;gt;&amp;lt;/nowiki&amp;gt; tag&lt;br /&gt;
#** State, not in any tag&lt;br /&gt;
#* Humidity&lt;br /&gt;
#* Current Temperature&lt;br /&gt;
#* Image for Tomorrow's Forecast (see [[#Weather Condition Images]] below for more information)&lt;br /&gt;
#* Image for the Day After Tomorrow's Forecast&lt;br /&gt;
# Finally, bind '''fetchWeather()''' to the DOMContentLoaded event so that your weather widget is automatically initialized when the page is loaded:&lt;br /&gt;
#: &amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;document.addEventListener(&amp;quot;DOMContentLoaded&amp;quot;, fetchWeather, false);&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Use the following HTML:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;weather&amp;quot; id=&amp;quot;weatherWidget&amp;quot;&amp;gt;&lt;br /&gt;
	&amp;lt;div class=&amp;quot;weather-loc&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
	&amp;lt;div class=&amp;quot;weather-humidity&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
	&amp;lt;div class=&amp;quot;weather-temp&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
	&amp;lt;img class=&amp;quot;weather-tomorrow&amp;quot; /&amp;gt;&lt;br /&gt;
	&amp;lt;img class=&amp;quot;weather-dayaftertomorrow&amp;quot; /&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Include the CSS file from here: http://research.engineering.wustl.edu/~todd/cse330/module4/weather.css&lt;br /&gt;
&lt;br /&gt;
When everything is working, the weather widget should look something like this:&lt;br /&gt;
&lt;br /&gt;
[[File:WeatherWidget.png]]&lt;br /&gt;
&lt;br /&gt;
'''Important:''' The widget in this section needs to work in only Firefox and Chrome.  It does '''''not''''' need to work Internet Explorer.&lt;br /&gt;
&lt;br /&gt;
==== Tips ====&lt;br /&gt;
&lt;br /&gt;
===== JSON Structure =====&lt;br /&gt;
&lt;br /&gt;
The JSON from our server looks like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
   &amp;quot;updated&amp;quot;: &amp;quot;Thu, 11 Oct 2012 5:54 pm CDT&amp;quot;,&lt;br /&gt;
   &amp;quot;location&amp;quot;: {&lt;br /&gt;
      &amp;quot;city&amp;quot;: &amp;quot;St. Louis&amp;quot;,&lt;br /&gt;
      &amp;quot;state&amp;quot;: &amp;quot;MO&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;wind&amp;quot;: {&lt;br /&gt;
      &amp;quot;chill&amp;quot;: &amp;quot;62&amp;quot;,&lt;br /&gt;
      &amp;quot;direction&amp;quot;: &amp;quot;150&amp;quot;,&lt;br /&gt;
      &amp;quot;speed&amp;quot;: &amp;quot;3 mph&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;atmosphere&amp;quot;: {&lt;br /&gt;
      &amp;quot;humidity&amp;quot;: &amp;quot;50&amp;quot;,&lt;br /&gt;
      &amp;quot;visibility&amp;quot;: &amp;quot;10&amp;quot;,&lt;br /&gt;
      &amp;quot;pressure&amp;quot;: &amp;quot;30.12 in&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;current&amp;quot;: {&lt;br /&gt;
      &amp;quot;code&amp;quot;: &amp;quot;28&amp;quot;,&lt;br /&gt;
      &amp;quot;text&amp;quot;: &amp;quot;Mostly Cloudy&amp;quot;,&lt;br /&gt;
      &amp;quot;temp&amp;quot;: &amp;quot;62°F&amp;quot;,&lt;br /&gt;
      &amp;quot;date&amp;quot;: &amp;quot;Thu, 11 Oct 2012 5:54 pm CDT&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;tomorrow&amp;quot;: {&lt;br /&gt;
      &amp;quot;code&amp;quot;: &amp;quot;29&amp;quot;,&lt;br /&gt;
      &amp;quot;text&amp;quot;: &amp;quot;Clouds Early/Clearing Late&amp;quot;,&lt;br /&gt;
      &amp;quot;low&amp;quot;: &amp;quot;45°F&amp;quot;,&lt;br /&gt;
      &amp;quot;high&amp;quot;: &amp;quot;61°F&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;dayafter&amp;quot;: {&lt;br /&gt;
      &amp;quot;code&amp;quot;: &amp;quot;30&amp;quot;,&lt;br /&gt;
      &amp;quot;text&amp;quot;: &amp;quot;Partly Cloudy&amp;quot;,&lt;br /&gt;
      &amp;quot;low&amp;quot;: &amp;quot;53°F&amp;quot;,&lt;br /&gt;
      &amp;quot;high&amp;quot;: &amp;quot;65°F&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;credit&amp;quot;: &amp;quot;http://us.rd.yahoo.com/dailynews/rss/weather/St._Louis__MO/*http://weather.yahoo.com/forecast/USMO0170_f.html&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Weather Condition Images =====&lt;br /&gt;
&lt;br /&gt;
Each day's forecast has a code.  There are images associated with these codes.&lt;br /&gt;
&lt;br /&gt;
One place to get the images is from here: &amp;lt;nowiki&amp;gt;http://us.yimg.com/i/us/nws/weather/gr/&amp;lt;/nowiki&amp;gt;'''##'''&amp;lt;nowiki&amp;gt;ds.png&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Replace the '''##''' with the forecast code.  For example, for code 32, the URL would be: http://us.yimg.com/i/us/nws/weather/gr/32ds.png&lt;br /&gt;
&lt;br /&gt;
=== jQuery Dialogs ===&lt;br /&gt;
&lt;br /&gt;
Helpful Resource: [http://docs.jquery.com/Main_Page jQuery Documentation] ... Some additional tips: [[jQuery]]&lt;br /&gt;
&lt;br /&gt;
Create a simple page using jQuery dialogs.&lt;br /&gt;
&lt;br /&gt;
* Create a page that has the words &amp;quot;Google&amp;quot; and &amp;quot;Yahoo&amp;quot;.&lt;br /&gt;
* When the user clicks the &amp;quot;Google&amp;quot; text, open a jQuery dialog window with one jQuery dialog button.  If the button is pressed, display the Google logo image (the image can be stored on your web server) on the web page, and if the dialog is closed any other way, do nothing.&lt;br /&gt;
* When the user clicks the &amp;quot;Yahoo&amp;quot; text, open a jQuery dialog window with one jQuery dialog button.  If the button is pressed, display the Yahoo logo image (the image can be stored on your web server) on the web page, and if the dialog is closed any other way, do nothing.&lt;br /&gt;
* Initially there should be no image on the page (i.e., the img should be hidden with the CSS display attribute).  After one of the two images is displayed, if the user clicks on the image, a jQuery dialog box should be opened with one dialog button, and if the button is pressed then the image should be hidden again.  Otherwise, do nothing.&lt;br /&gt;
&lt;br /&gt;
== Group Project ==&lt;br /&gt;
&lt;br /&gt;
You will work in pairs on this project.&lt;br /&gt;
&lt;br /&gt;
'''Important Reminder:''' frequently commit your work to your subversion repository as a backup!&lt;br /&gt;
&lt;br /&gt;
I forgot if I already mentioned this, but '''start early on this project!''' It will take longer than you think, I promise!&lt;br /&gt;
&lt;br /&gt;
=== Calendar ===&lt;br /&gt;
&lt;br /&gt;
Build a simple calendar that allows users to add and remove events dynamically.&lt;br /&gt;
&lt;br /&gt;
You will use JavaScript to process user interactions at the web browser, without ever refreshing the browser after the initial web page load.  You may use a JavaScript library of your choice, including jQuery.  (No extra credit will be given for ''not'' using a JavaScript library.)&lt;br /&gt;
&lt;br /&gt;
Your application should utilize AJAX to run server-side PHP scripts that query your database to save and retrieve information, including user accounts and events.&lt;br /&gt;
&lt;br /&gt;
==== Examples ====&lt;br /&gt;
&lt;br /&gt;
* https://calendar.google.com/&lt;br /&gt;
* http://www.zoho.com/calendar/&lt;br /&gt;
&lt;br /&gt;
==== Requirements ====&lt;br /&gt;
&lt;br /&gt;
* Support a month-by-month view of the calendar.&lt;br /&gt;
*: Show one month at a time, with buttons to move forward or backward.&lt;br /&gt;
*: There should be no limit to how far forward or backward the user can go.&lt;br /&gt;
* Users can register and log in to the website.&lt;br /&gt;
*: You may leverage your MySQL project code and database from last week to get started.&lt;br /&gt;
*: You may alternatively use OpenID for user authentication.  Note that you will still need a Users table in order associate calendar events with a certain OpenID.&lt;br /&gt;
* Unregistered users should see no events on the calendar.&lt;br /&gt;
* Registered users can add events.&lt;br /&gt;
*: All events should have a date and time, but do not need to have a duration.&lt;br /&gt;
*: You do ''not'' need to support recurring events (where you add an event that repeats, for example, every monday).&lt;br /&gt;
* Registered users see only events that they have added.&lt;br /&gt;
* Registered users can delete their events, but not the events of others.&lt;br /&gt;
* All user and event data should be kept in a database.&lt;br /&gt;
* At no time should the main page need to be reloaded.&lt;br /&gt;
*: User registration, user authentication, event addition, and event deletion should all be handled by JavaScript and AJAX requests to your server.&lt;br /&gt;
* Your page needs to work in the versions of Firefox and Chrome installed on the lab computers.&lt;br /&gt;
&lt;br /&gt;
'''Tip:''' Run your database schema by a TA before implementing it.&lt;br /&gt;
&lt;br /&gt;
==== Calendar Helper Library ====&lt;br /&gt;
&lt;br /&gt;
To help you get started with your calendar, we have written some JavaScript helper functions.  The code is available at:&lt;br /&gt;
* Full Version (for you to refer): http://research.engineering.wustl.edu/~todd/cse330/module4/calendar.js&lt;br /&gt;
* Minified Version (to include in your pages):http://research.engineering.wustl.edu/~todd/cse330/module4/calendar.min.js&lt;br /&gt;
&lt;br /&gt;
For example, this is how you would make a button to load the next month and show alerts containing all the days in the weeks contained by that month.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
// For our purposes, we can keep the current month in a variable in the global scope&lt;br /&gt;
var currentMonth = new Month(2012, 9); // October 2012&lt;br /&gt;
&lt;br /&gt;
// Change the month when the &amp;quot;next&amp;quot; button is pressed&lt;br /&gt;
document.getElementById(&amp;quot;next_month_btn&amp;quot;).addEventListener(&amp;quot;click&amp;quot;, function(event){&lt;br /&gt;
	currentMonth = currentMonth.nextMonth(); // Previous month would be currentMonth.prevMonth()&lt;br /&gt;
	updateCalendar(); // Whenever the month is updated, we'll need to re-render the calendar in HTML&lt;br /&gt;
	alert(&amp;quot;The new month is &amp;quot;+currentMonth.month+&amp;quot; &amp;quot;+currentMonth.year);&lt;br /&gt;
}, false);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
// This updateCalendar() function only alerts the dates in the currently specified month.  You need to write&lt;br /&gt;
// it to modify the DOM (optionally using jQuery) to display the days and weeks in the current month.&lt;br /&gt;
function updateCalendar(){&lt;br /&gt;
	var weeks = currentMonth.getWeeks();&lt;br /&gt;
	&lt;br /&gt;
	for(var w in weeks){&lt;br /&gt;
		var days = weeks[w].getDates();&lt;br /&gt;
		// days contains normal JavaScript Date objects.&lt;br /&gt;
		&lt;br /&gt;
		alert(&amp;quot;Week starting on &amp;quot;+days[0]);&lt;br /&gt;
		&lt;br /&gt;
		for(var d in days){&lt;br /&gt;
			// You can see console.log() output in your JavaScript debugging tool, like Firebug,&lt;br /&gt;
			// WebWit Inspector, or Dragonfly.&lt;br /&gt;
			console.log(days[d].toISOString());&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Important:''' JavaScript starts the months of a year, and the days of a week, at index 0.  This means that '''''in JavaScript, January is month 0, and December is month 11.'''''  Our calendar helper functions maintain this JavaScript convention.&lt;br /&gt;
&lt;br /&gt;
=== Web Security and Validation ===&lt;br /&gt;
&lt;br /&gt;
Your project needs to demonstrate that thought was put into web security and best practice.  For more information, see this week's Web Application Security guide: [[Web Application Security, Part 3]]&lt;br /&gt;
&lt;br /&gt;
In particular:&lt;br /&gt;
&lt;br /&gt;
* '''Your application needs to prevent XSS attacks.'''  The easiest way to prevent this is to continue sanitizing ''all'' of your output using '''htmlentities()'''.&lt;br /&gt;
* '''Perform precautionary measures to prevent session hijacking attacks.'''&lt;br /&gt;
*: You should specify your session cookie to be HTTP-Only.  However, for the means of this module, you need not test for user agent consistency.&lt;br /&gt;
* '''Optional:''' Validate your JavaScript code using [http://www.jshint.com/ JSHint] for 0.5 points of Creative Portion, or [http://jslint.com/ JSLint] for 0.5 points of Creative Portion.  You cannot earn credit for both.  &lt;br /&gt;
&lt;br /&gt;
You should continue the practices that you have learned in past weeks:&lt;br /&gt;
&lt;br /&gt;
* Pass tokens in forms to prevent CSRF attacks.&lt;br /&gt;
*: '''Hint:''' You will need to send your CSRF tokens in your AJAX requests.  Remember that AJAX still submits forms and runs server-side scripts, just like the vanilla forms you've been using in Modules 2 and 3.&lt;br /&gt;
* Use prepared queries to prevent SQL Injection attacks.&lt;br /&gt;
* If storing passwords in a database, always store them salted and encrypted.&lt;br /&gt;
* Your page should validate with no errors through the W3C validator.&lt;br /&gt;
&lt;br /&gt;
== Grading ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;font-size:2em; line-height:2em;&amp;quot;&amp;gt;'''Due Date: Monday, October 29th by 1pm (both individual and group)'''&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Please see the notes at the bottom:&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
!Assignment&lt;br /&gt;
!Points&lt;br /&gt;
|-&lt;br /&gt;
|Calculator&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
|Weather Widget&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|jQuery Dialogs&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
!colspan=&amp;quot;2&amp;quot;|Group Portion:&lt;br /&gt;
|-&lt;br /&gt;
|Calendar month view correct and Move between months (without page reload)&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|User authentication and registration (without page reload)&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Add events (new event shown in calendar without page reload)&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Events added are private and other users cannot see them&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
|Delete events (event removed from calendar without page reload)&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
|-&lt;br /&gt;
|Safe from XSS and Session Hijacking&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|-&lt;br /&gt;
|Validation, CSRF, Salted Passwords, Safe SQL Queries&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Creative Portion&lt;br /&gt;
|2&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Total: 10 Points&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*You must get your creative portion part approved from any TA at least one day before the due date.  The creative portion is worth 20% of the module grade, and your effort should reflect this.  You may receive a deduction if your creative portion idea is not approved.&lt;br /&gt;
&lt;br /&gt;
*You will still lose one point per day late.  As the module is only worth 10 points, that results in a 10% penalty.  (Note that all modules are weighted similarly, 10 points for this module does not mean it is only worth half of the previous module).&lt;br /&gt;
&lt;br /&gt;
[[Category:Module 4]]&lt;br /&gt;
[[Category:Modules]]&lt;/div&gt;</summary>
		<author><name>Marc</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=Module_6&amp;diff=870</id>
		<title>Module 6</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=Module_6&amp;diff=870"/>
		<updated>2012-10-24T22:48:54Z</updated>

		<summary type="html">&lt;p&gt;Marc: /* Grading */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In Module 4, you will learn about JavaScript, the prevailing client-side language, and AJAX, a method for performing asynchronous updates to a web page (without refreshing the page).&lt;br /&gt;
&lt;br /&gt;
This article contains your assignments for Module 4.&lt;br /&gt;
&lt;br /&gt;
== Individual Assignments ==&lt;br /&gt;
&lt;br /&gt;
=== JavaScript Calculator ===&lt;br /&gt;
&lt;br /&gt;
In Module 2, you made a calculator using PHP.  Now you will be making one using JavaScript.&lt;br /&gt;
&lt;br /&gt;
Read the JavaScript guide first: [[Javascript and AJAX]]&lt;br /&gt;
&lt;br /&gt;
* The web page should have two input fields and a radio button group for the operation, with the 4 basic math operations represented (add,subtract,multiply,divide).&lt;br /&gt;
* The javascript should monitor all three fields and display the current result whenever the user changes any value in any field, without refreshing the page.&lt;br /&gt;
* The calculator should be completely self-contained; i.e., you should not be making any requests to any other server-side or client-side scripts or web pages after the initial page load.&lt;br /&gt;
&lt;br /&gt;
'''Tip:''' You can embed JavaScript code into an HTML document like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;
// your code here&lt;br /&gt;
&amp;lt;/script&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Tip:''' If your code isn't working the way you expect, use a JavaScript error console.  In Chrome, for example, press Ctrl-Shift-I (or Cmd-Option-I) to open the WebKit inspector.&lt;br /&gt;
&lt;br /&gt;
=== Weather Widget ===&lt;br /&gt;
&lt;br /&gt;
In this section, you will make a web page that displays the weather forecast using AJAX requests to a weather server.  You should complete this section ''without'' using JavaScript libraries like jQuery.&lt;br /&gt;
&lt;br /&gt;
# Make an empty HTML document; name it '''weather.html'''&lt;br /&gt;
#: Refer to the [[HTML and CSS]] guide for the skeleton of an HTML document&lt;br /&gt;
# Define a function in JavaScript; call it '''fetchWeather()'''.  You may write your JavaScript in an embedded script in your head tag.&lt;br /&gt;
# Inside your '''fetchWeather()''' function, make an AJAX request to the weather server.&lt;br /&gt;
#: We have a server that outputs the current weather in JSON format.  The format is documented in the [[#JSON Structure]] section below.&lt;br /&gt;
#: '''URL:''' http://research.engineering.wustl.edu/~todd/cse330/module4/weather_json.php&lt;br /&gt;
#: We kindly thank Yahoo Weather for providing us with up-to-date weather information.&lt;br /&gt;
#* '''Note:''' You normally cannot perform AJAX requests cross-domain.  We have set the &amp;lt;code&amp;gt;Access-Control-Allow-Origin&amp;lt;/code&amp;gt; header on our server to allow requests from your EC2 instances.&lt;br /&gt;
# In your callback, process the JSON and use JavaScript to manipulate the HTML DOM to display the following information on your page:&lt;br /&gt;
#* Location&lt;br /&gt;
#** City, in a &amp;lt;nowiki&amp;gt;&amp;lt;strong&amp;gt;&amp;lt;/nowiki&amp;gt; tag&lt;br /&gt;
#** State, not in any tag&lt;br /&gt;
#* Humidity&lt;br /&gt;
#* Current Temperature&lt;br /&gt;
#* Image for Tomorrow's Forecast (see [[#Weather Condition Images]] below for more information)&lt;br /&gt;
#* Image for the Day After Tomorrow's Forecast&lt;br /&gt;
# Finally, bind '''fetchWeather()''' to the DOMContentLoaded event so that your weather widget is automatically initialized when the page is loaded:&lt;br /&gt;
#: &amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;document.addEventListener(&amp;quot;DOMContentLoaded&amp;quot;, fetchWeather, false);&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Use the following HTML:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;weather&amp;quot; id=&amp;quot;weatherWidget&amp;quot;&amp;gt;&lt;br /&gt;
	&amp;lt;div class=&amp;quot;weather-loc&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
	&amp;lt;div class=&amp;quot;weather-humidity&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
	&amp;lt;div class=&amp;quot;weather-temp&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
	&amp;lt;img class=&amp;quot;weather-tomorrow&amp;quot; /&amp;gt;&lt;br /&gt;
	&amp;lt;img class=&amp;quot;weather-dayaftertomorrow&amp;quot; /&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Include the CSS file from here: http://research.engineering.wustl.edu/~todd/cse330/module4/weather.css&lt;br /&gt;
&lt;br /&gt;
When everything is working, the weather widget should look something like this:&lt;br /&gt;
&lt;br /&gt;
[[File:WeatherWidget.png]]&lt;br /&gt;
&lt;br /&gt;
'''Important:''' The widget in this section needs to work in only Firefox and Chrome.  It does '''''not''''' need to work Internet Explorer.&lt;br /&gt;
&lt;br /&gt;
==== Tips ====&lt;br /&gt;
&lt;br /&gt;
===== JSON Structure =====&lt;br /&gt;
&lt;br /&gt;
The JSON from our server looks like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
   &amp;quot;updated&amp;quot;: &amp;quot;Thu, 11 Oct 2012 5:54 pm CDT&amp;quot;,&lt;br /&gt;
   &amp;quot;location&amp;quot;: {&lt;br /&gt;
      &amp;quot;city&amp;quot;: &amp;quot;St. Louis&amp;quot;,&lt;br /&gt;
      &amp;quot;state&amp;quot;: &amp;quot;MO&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;wind&amp;quot;: {&lt;br /&gt;
      &amp;quot;chill&amp;quot;: &amp;quot;62&amp;quot;,&lt;br /&gt;
      &amp;quot;direction&amp;quot;: &amp;quot;150&amp;quot;,&lt;br /&gt;
      &amp;quot;speed&amp;quot;: &amp;quot;3 mph&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;atmosphere&amp;quot;: {&lt;br /&gt;
      &amp;quot;humidity&amp;quot;: &amp;quot;50&amp;quot;,&lt;br /&gt;
      &amp;quot;visibility&amp;quot;: &amp;quot;10&amp;quot;,&lt;br /&gt;
      &amp;quot;pressure&amp;quot;: &amp;quot;30.12 in&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;current&amp;quot;: {&lt;br /&gt;
      &amp;quot;code&amp;quot;: &amp;quot;28&amp;quot;,&lt;br /&gt;
      &amp;quot;text&amp;quot;: &amp;quot;Mostly Cloudy&amp;quot;,&lt;br /&gt;
      &amp;quot;temp&amp;quot;: &amp;quot;62°F&amp;quot;,&lt;br /&gt;
      &amp;quot;date&amp;quot;: &amp;quot;Thu, 11 Oct 2012 5:54 pm CDT&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;tomorrow&amp;quot;: {&lt;br /&gt;
      &amp;quot;code&amp;quot;: &amp;quot;29&amp;quot;,&lt;br /&gt;
      &amp;quot;text&amp;quot;: &amp;quot;Clouds Early/Clearing Late&amp;quot;,&lt;br /&gt;
      &amp;quot;low&amp;quot;: &amp;quot;45°F&amp;quot;,&lt;br /&gt;
      &amp;quot;high&amp;quot;: &amp;quot;61°F&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;dayafter&amp;quot;: {&lt;br /&gt;
      &amp;quot;code&amp;quot;: &amp;quot;30&amp;quot;,&lt;br /&gt;
      &amp;quot;text&amp;quot;: &amp;quot;Partly Cloudy&amp;quot;,&lt;br /&gt;
      &amp;quot;low&amp;quot;: &amp;quot;53°F&amp;quot;,&lt;br /&gt;
      &amp;quot;high&amp;quot;: &amp;quot;65°F&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;credit&amp;quot;: &amp;quot;http://us.rd.yahoo.com/dailynews/rss/weather/St._Louis__MO/*http://weather.yahoo.com/forecast/USMO0170_f.html&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Weather Condition Images =====&lt;br /&gt;
&lt;br /&gt;
Each day's forecast has a code.  There are images associated with these codes.&lt;br /&gt;
&lt;br /&gt;
One place to get the images is from here: &amp;lt;nowiki&amp;gt;http://us.yimg.com/i/us/nws/weather/gr/&amp;lt;/nowiki&amp;gt;'''##'''&amp;lt;nowiki&amp;gt;ds.png&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Replace the '''##''' with the forecast code.  For example, for code 32, the URL would be: http://us.yimg.com/i/us/nws/weather/gr/32ds.png&lt;br /&gt;
&lt;br /&gt;
=== jQuery Dialogs ===&lt;br /&gt;
&lt;br /&gt;
Helpful Resource: [http://docs.jquery.com/Main_Page jQuery Documentation] ... Some additional tips: [[jQuery]]&lt;br /&gt;
&lt;br /&gt;
Create a simple page using jQuery dialogs.&lt;br /&gt;
&lt;br /&gt;
* Create a page that has the words &amp;quot;Google&amp;quot; and &amp;quot;Yahoo&amp;quot;.&lt;br /&gt;
* When the user clicks the &amp;quot;Google&amp;quot; text, open a jQuery dialog window with one jQuery dialog button.  If the button is pressed, display the Google logo image (the image can be stored on your web server) on the web page, and if the dialog is closed any other way, do nothing.&lt;br /&gt;
* When the user clicks the &amp;quot;Yahoo&amp;quot; text, open a jQuery dialog window with one jQuery dialog button.  If the button is pressed, display the Yahoo logo image (the image can be stored on your web server) on the web page, and if the dialog is closed any other way, do nothing.&lt;br /&gt;
* Initially there should be no image on the page (i.e., the img should be hidden with the CSS display attribute).  After one of the two images is displayed, if the user clicks on the image, a jQuery dialog box should be opened with one dialog button, and if the button is pressed then the image should be hidden again.  Otherwise, do nothing.&lt;br /&gt;
&lt;br /&gt;
== Group Project ==&lt;br /&gt;
&lt;br /&gt;
You will work in pairs on this project.&lt;br /&gt;
&lt;br /&gt;
'''Important Reminder:''' frequently commit your work to your subversion repository as a backup!&lt;br /&gt;
&lt;br /&gt;
I forgot if I already mentioned this, but '''start early on this project!''' It will take longer than you think, I promise!&lt;br /&gt;
&lt;br /&gt;
=== Calendar ===&lt;br /&gt;
&lt;br /&gt;
Build a simple calendar that allows users to add and remove events dynamically.&lt;br /&gt;
&lt;br /&gt;
You will use JavaScript to process user interactions at the web browser, without ever refreshing the browser after the initial web page load.  You may use a JavaScript library of your choice, including jQuery.  (No extra credit will be given for ''not'' using a JavaScript library.)&lt;br /&gt;
&lt;br /&gt;
Your application should utilize AJAX to run server-side PHP scripts that query your database to save and retrieve information, including user accounts and events.&lt;br /&gt;
&lt;br /&gt;
==== Examples ====&lt;br /&gt;
&lt;br /&gt;
* https://calendar.google.com/&lt;br /&gt;
* http://www.zoho.com/calendar/&lt;br /&gt;
&lt;br /&gt;
==== Requirements ====&lt;br /&gt;
&lt;br /&gt;
* Support a month-by-month view of the calendar.&lt;br /&gt;
*: Show one month at a time, with buttons to move forward or backward.&lt;br /&gt;
*: There should be no limit to how far forward or backward the user can go.&lt;br /&gt;
* Users can register and log in to the website.&lt;br /&gt;
*: You may leverage your MySQL project code and database from last week to get started.&lt;br /&gt;
*: You may alternatively use OpenID for user authentication.  Note that you will still need a Users table in order associate calendar events with a certain OpenID.&lt;br /&gt;
* Unregistered users should see no events on the calendar.&lt;br /&gt;
* Registered users can add events.&lt;br /&gt;
*: All events should have a date and time, but do not need to have a duration.&lt;br /&gt;
*: You do ''not'' need to support recurring events (where you add an event that repeats, for example, every monday).&lt;br /&gt;
* Registered users see only events that they have added.&lt;br /&gt;
* Registered users can delete their events, but not the events of others.&lt;br /&gt;
* All user and event data should be kept in a database.&lt;br /&gt;
* At no time should the main page need to be reloaded.&lt;br /&gt;
*: User registration, user authentication, event addition, and event deletion should all be handled by JavaScript and AJAX requests to your server.&lt;br /&gt;
* Your page needs to work in the versions of Firefox and Chrome installed on the lab computers.&lt;br /&gt;
&lt;br /&gt;
'''Tip:''' Run your database schema by a TA before implementing it.&lt;br /&gt;
&lt;br /&gt;
==== Calendar Helper Library ====&lt;br /&gt;
&lt;br /&gt;
To help you get started with your calendar, we have written some JavaScript helper functions.  The code is available at:&lt;br /&gt;
* Full Version (for you to refer): http://research.engineering.wustl.edu/~todd/cse330/module4/calendar.js&lt;br /&gt;
* Minified Version (to include in your pages):http://research.engineering.wustl.edu/~todd/cse330/module4/calendar.min.js&lt;br /&gt;
&lt;br /&gt;
For example, this is how you would make a button to load the next month and show alerts containing all the days in the weeks contained by that month.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
// For our purposes, we can keep the current month in a variable in the global scope&lt;br /&gt;
var currentMonth = new Month(2012, 9); // October 2012&lt;br /&gt;
&lt;br /&gt;
// Change the month when the &amp;quot;next&amp;quot; button is pressed&lt;br /&gt;
document.getElementById(&amp;quot;next_month_btn&amp;quot;).addEventListener(&amp;quot;click&amp;quot;, function(event){&lt;br /&gt;
	currentMonth = currentMonth.nextMonth(); // Previous month would be currentMonth.prevMonth()&lt;br /&gt;
	updateCalendar(); // Whenever the month is updated, we'll need to re-render the calendar in HTML&lt;br /&gt;
	alert(&amp;quot;The new month is &amp;quot;+currentMonth.month+&amp;quot; &amp;quot;+currentMonth.year);&lt;br /&gt;
}, false);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
// This updateCalendar() function only alerts the dates in the currently specified month.  You need to write&lt;br /&gt;
// it to modify the DOM (optionally using jQuery) to display the days and weeks in the current month.&lt;br /&gt;
function updateCalendar(){&lt;br /&gt;
	var weeks = currentMonth.getWeeks();&lt;br /&gt;
	&lt;br /&gt;
	for(var w in weeks){&lt;br /&gt;
		var days = weeks[w].getDates();&lt;br /&gt;
		// days contains normal JavaScript Date objects.&lt;br /&gt;
		&lt;br /&gt;
		alert(&amp;quot;Week starting on &amp;quot;+days[0]);&lt;br /&gt;
		&lt;br /&gt;
		for(var d in days){&lt;br /&gt;
			// You can see console.log() output in your JavaScript debugging tool, like Firebug,&lt;br /&gt;
			// WebWit Inspector, or Dragonfly.&lt;br /&gt;
			console.log(days[d].toISOString());&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Important:''' JavaScript starts the months of a year, and the days of a week, at index 0.  This means that '''''in JavaScript, January is month 0, and December is month 11.'''''  Our calendar helper functions maintain this JavaScript convention.&lt;br /&gt;
&lt;br /&gt;
=== Web Security and Validation ===&lt;br /&gt;
&lt;br /&gt;
Your project needs to demonstrate that thought was put into web security and best practice.  For more information, see this week's Web Application Security guide: [[Web Application Security, Part 3]]&lt;br /&gt;
&lt;br /&gt;
In particular:&lt;br /&gt;
&lt;br /&gt;
* '''Your application needs to prevent XSS attacks.'''  The easiest way to prevent this is to continue sanitizing ''all'' of your output using '''htmlentities()'''.&lt;br /&gt;
* '''Perform precautionary measures to prevent session hijacking attacks.'''&lt;br /&gt;
*: You should specify your session cookie to be HTTP-Only.  However, for the means of this module, you need not test for user agent consistency.&lt;br /&gt;
* '''Optional:''' Validate your JavaScript code using [http://www.jshint.com/ JSHint] for 0.5 points of Creative Portion, or [http://jslint.com/ JSLint] for 0.75 points of Creative Portion.  (JSLint is more demanding than JSHint, and so it is worth more points.)  You cannot earn credit for both.  &lt;br /&gt;
&lt;br /&gt;
You should continue the practices that you have learned in past weeks:&lt;br /&gt;
&lt;br /&gt;
* Pass tokens in forms to prevent CSRF attacks.&lt;br /&gt;
*: '''Hint:''' You will need to send your CSRF tokens in your AJAX requests.  Remember that AJAX still submits forms and runs server-side scripts, just like the vanilla forms you've been using in Modules 2 and 3.&lt;br /&gt;
* Use prepared queries to prevent SQL Injection attacks.&lt;br /&gt;
* If storing passwords in a database, always store them salted and encrypted.&lt;br /&gt;
* Your page should validate with no errors through the W3C validator.&lt;br /&gt;
&lt;br /&gt;
== Grading ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;font-size:2em; line-height:2em;&amp;quot;&amp;gt;'''Due Date: Monday, October 29th by 1pm (both individual and group)'''&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Please see the notes at the bottom:&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
!Assignment&lt;br /&gt;
!Points&lt;br /&gt;
|-&lt;br /&gt;
|Calculator&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
|Weather Widget&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|jQuery Dialogs&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
!colspan=&amp;quot;2&amp;quot;|Group Portion:&lt;br /&gt;
|-&lt;br /&gt;
|Calendar month view correct and Move between months (without page reload)&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|User authentication and registration (without page reload)&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Add events (new event shown in calendar without page reload)&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Events added are private and other users cannot see them&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
|Delete events (event removed from calendar without page reload)&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
|-&lt;br /&gt;
|Safe from XSS and Session Hijacking&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|-&lt;br /&gt;
|Validation, CSRF, Salted Passwords, Safe SQL Queries&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Creative Portion&lt;br /&gt;
|2&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Total: 10 Points&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*You must get your creative portion part approved from any TA at least one day before the due date.  The creative portion is worth 20% of the module grade, and your effort should reflect this.  You may receive a deduction if your creative portion idea is not approved.&lt;br /&gt;
&lt;br /&gt;
*You will still lose one point per day late.  As the module is only worth 10 points, that results in a 10% penalty.  (Note that all modules are weighted similarly, 10 points for this module does not mean it is only worth half of the previous module).&lt;br /&gt;
&lt;br /&gt;
[[Category:Module 4]]&lt;br /&gt;
[[Category:Modules]]&lt;/div&gt;</summary>
		<author><name>Marc</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=Module_6&amp;diff=822</id>
		<title>Module 6</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=Module_6&amp;diff=822"/>
		<updated>2012-10-15T16:59:41Z</updated>

		<summary type="html">&lt;p&gt;Marc: /* Grading */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In Module 4, you will learn about JavaScript, the prevailing client-side language, and AJAX, a method for performing asynchronous updates to a web page (without refreshing the page).&lt;br /&gt;
&lt;br /&gt;
This article contains your assignments for Module 4.&lt;br /&gt;
&lt;br /&gt;
== Individual Assignments ==&lt;br /&gt;
&lt;br /&gt;
=== JavaScript Calculator ===&lt;br /&gt;
&lt;br /&gt;
In Module 2, you made a calculator using PHP.  Now you will be making one using JavaScript.&lt;br /&gt;
&lt;br /&gt;
Read the JavaScript guide first: [[Javascript and AJAX]]&lt;br /&gt;
&lt;br /&gt;
* The web page should have two input fields and a radio button group for the operation, with the 4 basic math operations represented (add,subtract,multiply,divide).&lt;br /&gt;
* The javascript should monitor all three fields and display the current result whenever the user changes any value in any field, without refreshing the page.&lt;br /&gt;
* The calculator should be completely self-contained; i.e., you should not be making any requests to any other server-side or client-side scripts or web pages after the initial page load.&lt;br /&gt;
&lt;br /&gt;
'''Tip:''' You can embed JavaScript code into an HTML document like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;
// your code here&lt;br /&gt;
&amp;lt;/script&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Tip:''' If your code isn't working the way you expect, use a JavaScript error console.  In Chrome, for example, press Ctrl-Shift-I (or Cmd-Option-I) to open the WebKit inspector.&lt;br /&gt;
&lt;br /&gt;
=== Weather Widget ===&lt;br /&gt;
&lt;br /&gt;
In this section, you will make a web page that displays the weather forecast using AJAX requests to a weather server.  You should complete this section ''without'' using JavaScript libraries like jQuery.&lt;br /&gt;
&lt;br /&gt;
# Make an empty HTML document; name it '''weather.html'''&lt;br /&gt;
#: Refer to the [[HTML and CSS]] guide for the skeleton of an HTML document&lt;br /&gt;
# Define a function in JavaScript; call it '''fetchWeather()'''.  You may write your JavaScript in an embedded script in your head tag.&lt;br /&gt;
# Inside your '''fetchWeather()''' function, make an AJAX request to the weather server.&lt;br /&gt;
#: We have a server that outputs the current weather in JSON format.  The format is documented in the [[#JSON Structure]] section below.&lt;br /&gt;
#: '''URL:''' http://research.engineering.wustl.edu/~todd/cse330/module4/weather_json.php&lt;br /&gt;
#: We kindly thank Yahoo Weather for providing us with up-to-date weather information.&lt;br /&gt;
#* '''Note:''' You normally cannot perform AJAX requests cross-domain.  We have set the &amp;lt;code&amp;gt;Access-Control-Allow-Origin&amp;lt;/code&amp;gt; header on our server to allow requests from your EC2 instances.&lt;br /&gt;
# In your callback, process the JSON and use JavaScript to manipulate the HTML DOM to display the following information on your page:&lt;br /&gt;
#* Location&lt;br /&gt;
#** City, in a &amp;lt;nowiki&amp;gt;&amp;lt;strong&amp;gt;&amp;lt;/nowiki&amp;gt; tag&lt;br /&gt;
#** State, not in any tag&lt;br /&gt;
#* Humidity&lt;br /&gt;
#* Current Temperature&lt;br /&gt;
#* Image for Tomorrow's Forecast (see [[#Weather Condition Images]] below for more information)&lt;br /&gt;
#* Image for the Day After Tomorrow's Forecast&lt;br /&gt;
# Finally, bind '''fetchWeather()''' to the DOMContentReady event so that your weather widget is automatically initialized when the page is loaded:&lt;br /&gt;
#: &amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;document.addEventListener(&amp;quot;DOMContentReady&amp;quot;, fetchWeather, false);&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Use the following HTML:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;weather&amp;quot; id=&amp;quot;weatherWidget&amp;quot;&amp;gt;&lt;br /&gt;
	&amp;lt;div class=&amp;quot;weather-loc&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
	&amp;lt;div class=&amp;quot;weather-humidity&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
	&amp;lt;div class=&amp;quot;weather-temp&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
	&amp;lt;img class=&amp;quot;weather-tomorrow&amp;quot; /&amp;gt;&lt;br /&gt;
	&amp;lt;img class=&amp;quot;weather-dayaftertomorrow&amp;quot; /&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Include the CSS file from here: http://research.engineering.wustl.edu/~todd/cse330/module4/weather.css&lt;br /&gt;
&lt;br /&gt;
When everything is working, the weather widget should look something like this:&lt;br /&gt;
&lt;br /&gt;
[[File:WeatherWidget.png]]&lt;br /&gt;
&lt;br /&gt;
'''Important:''' The widget in this section needs to work in only Firefox and Chrome.  It does '''''not''''' need to work Internet Explorer.&lt;br /&gt;
&lt;br /&gt;
==== Tips ====&lt;br /&gt;
&lt;br /&gt;
===== JSON Structure =====&lt;br /&gt;
&lt;br /&gt;
The JSON from our server looks like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
   &amp;quot;updated&amp;quot;: &amp;quot;Thu, 11 Oct 2012 5:54 pm CDT&amp;quot;,&lt;br /&gt;
   &amp;quot;location&amp;quot;: {&lt;br /&gt;
      &amp;quot;city&amp;quot;: &amp;quot;St. Louis&amp;quot;,&lt;br /&gt;
      &amp;quot;state&amp;quot;: &amp;quot;MO&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;wind&amp;quot;: {&lt;br /&gt;
      &amp;quot;chill&amp;quot;: &amp;quot;62&amp;quot;,&lt;br /&gt;
      &amp;quot;direction&amp;quot;: &amp;quot;150&amp;quot;,&lt;br /&gt;
      &amp;quot;speed&amp;quot;: &amp;quot;3 mph&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;atmosphere&amp;quot;: {&lt;br /&gt;
      &amp;quot;humidity&amp;quot;: &amp;quot;50&amp;quot;,&lt;br /&gt;
      &amp;quot;visibility&amp;quot;: &amp;quot;10&amp;quot;,&lt;br /&gt;
      &amp;quot;pressure&amp;quot;: &amp;quot;30.12 in&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;current&amp;quot;: {&lt;br /&gt;
      &amp;quot;code&amp;quot;: &amp;quot;28&amp;quot;,&lt;br /&gt;
      &amp;quot;text&amp;quot;: &amp;quot;Mostly Cloudy&amp;quot;,&lt;br /&gt;
      &amp;quot;temp&amp;quot;: &amp;quot;62°F&amp;quot;,&lt;br /&gt;
      &amp;quot;date&amp;quot;: &amp;quot;Thu, 11 Oct 2012 5:54 pm CDT&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;tomorrow&amp;quot;: {&lt;br /&gt;
      &amp;quot;code&amp;quot;: &amp;quot;29&amp;quot;,&lt;br /&gt;
      &amp;quot;text&amp;quot;: &amp;quot;Clouds Early/Clearing Late&amp;quot;,&lt;br /&gt;
      &amp;quot;low&amp;quot;: &amp;quot;45°F&amp;quot;,&lt;br /&gt;
      &amp;quot;high&amp;quot;: &amp;quot;61°F&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;dayafter&amp;quot;: {&lt;br /&gt;
      &amp;quot;code&amp;quot;: &amp;quot;30&amp;quot;,&lt;br /&gt;
      &amp;quot;text&amp;quot;: &amp;quot;Partly Cloudy&amp;quot;,&lt;br /&gt;
      &amp;quot;low&amp;quot;: &amp;quot;53°F&amp;quot;,&lt;br /&gt;
      &amp;quot;high&amp;quot;: &amp;quot;65°F&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;credit&amp;quot;: &amp;quot;http://us.rd.yahoo.com/dailynews/rss/weather/St._Louis__MO/*http://weather.yahoo.com/forecast/USMO0170_f.html&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Weather Condition Images =====&lt;br /&gt;
&lt;br /&gt;
Each day's forecast has a code.  There are images associated with these codes.&lt;br /&gt;
&lt;br /&gt;
You can get images from here: &amp;lt;nowiki&amp;gt;http://us.i1.yimg.com/us.yimg.com/i/us/nws/weather/gr/&amp;lt;/nowiki&amp;gt;'''##'''&amp;lt;nowiki&amp;gt;ds.png&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Replace the '''##''' with the forecast code.  For example, for code 32, the URL would be: http://us.i1.yimg.com/us.yimg.com/i/us/nws/weather/gr/32ds.png&lt;br /&gt;
&lt;br /&gt;
=== jQuery Dialogs ===&lt;br /&gt;
&lt;br /&gt;
Helpful Resource: [http://docs.jquery.com/Main_Page jQuery Documentation] ... Some additional tips: [[jQuery]]&lt;br /&gt;
&lt;br /&gt;
Create a simple page using jQuery dialogs.&lt;br /&gt;
&lt;br /&gt;
* Create a page that has the words &amp;quot;Google&amp;quot; and &amp;quot;Yahoo&amp;quot;.&lt;br /&gt;
* When the user clicks the &amp;quot;Google&amp;quot; text, open a jQuery dialog window with one jQuery dialog button.  If the button is pressed, display the Google logo image (the image can be stored on your web server) on the web page, and if the dialog is closed any other way, do nothing.&lt;br /&gt;
* When the user clicks the &amp;quot;Yahoo&amp;quot; text, open a jQuery dialog window with one jQuery dialog button.  If the button is pressed, display the Yahoo logo image (the image can be stored on your web server) on the web page, and if the dialog is closed any other way, do nothing.&lt;br /&gt;
* Initially there should be no image on the page (i.e., the img should be hidden with the CSS display attribute).  After one of the two images is displayed, if the user clicks on the image, a jQuery dialog box should be opened with one dialog button, and if the button is pressed then the image should be hidden again.  Otherwise, do nothing.&lt;br /&gt;
&lt;br /&gt;
== Group Project ==&lt;br /&gt;
&lt;br /&gt;
You will work in pairs on this project.&lt;br /&gt;
&lt;br /&gt;
'''Important Reminder:''' frequently commit your work to your subversion repository as a backup!&lt;br /&gt;
&lt;br /&gt;
I forgot if I already mentioned this, but '''start early on this project!''' It will take longer than you think, I promise!&lt;br /&gt;
&lt;br /&gt;
=== Calendar ===&lt;br /&gt;
&lt;br /&gt;
Build a simple calendar that allows users to add and remove events dynamically.&lt;br /&gt;
&lt;br /&gt;
You will use JavaScript to process user interactions at the web browser, without ever refreshing the browser after the initial web page load.  You may use a JavaScript library of your choice, including jQuery.  (No extra credit will be given for ''not'' using a JavaScript library.)&lt;br /&gt;
&lt;br /&gt;
Your application should utilize AJAX to run server-side PHP scripts that query your database to save and retrieve information, including user accounts and events.&lt;br /&gt;
&lt;br /&gt;
==== Examples ====&lt;br /&gt;
&lt;br /&gt;
* https://calendar.google.com/&lt;br /&gt;
* http://www.zoho.com/calendar/&lt;br /&gt;
&lt;br /&gt;
==== Requirements ====&lt;br /&gt;
&lt;br /&gt;
* Support a month-by-month view of the calendar.&lt;br /&gt;
*: Show one month at a time, with buttons to move forward or backward.&lt;br /&gt;
*: There should be no limit to how far forward or backward the user can go.&lt;br /&gt;
* Users can register and log in to the website.&lt;br /&gt;
*: You may leverage your MySQL project code and database from last week to get started.&lt;br /&gt;
*: You may alternatively use OpenID for user authentication.  Note that you will still need a Users table in order associate calendar events with a certain OpenID.&lt;br /&gt;
* Unregistered users should see no events on the calendar.&lt;br /&gt;
* Registered users can add events.&lt;br /&gt;
*: All events should have a date and time, but do not need to have a duration.&lt;br /&gt;
*: You do ''not'' need to support recurring events (where you add an event that repeats, for example, every monday).&lt;br /&gt;
* Registered users see only events that they have added.&lt;br /&gt;
* Registered users can delete their events, but not the events of others.&lt;br /&gt;
* All user and event data should be kept in a database.&lt;br /&gt;
* At no time should the main page need to be reloaded.&lt;br /&gt;
*: User registration, user authentication, event addition, and event deletion should all be handled by JavaScript and AJAX requests to your server.&lt;br /&gt;
* Your page needs to work in the versions of Firefox and Chrome installed on the lab computers.&lt;br /&gt;
&lt;br /&gt;
'''Tip:''' Run your database schema by a TA before implementing it.&lt;br /&gt;
&lt;br /&gt;
==== Calendar Helper Library ====&lt;br /&gt;
&lt;br /&gt;
To help you get started with your calendar, we have written some JavaScript helper functions.  The code is available at:&lt;br /&gt;
* Full Version (for you to refer): http://research.engineering.wustl.edu/~todd/cse330/module4/calendar.js&lt;br /&gt;
* Minified Version (to include in your pages):http://research.engineering.wustl.edu/~todd/cse330/module4/calendar.min.js&lt;br /&gt;
&lt;br /&gt;
For example, this is how you would make a button to load the next month and show alerts containing all the days in the weeks contained by that month.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
// For our purposes, we can keep the current month in a variable in the global scope&lt;br /&gt;
var currentMonth = new Month(2012, 9); // October 2012&lt;br /&gt;
&lt;br /&gt;
// Change the month when the &amp;quot;next&amp;quot; button is pressed&lt;br /&gt;
document.getElementById(&amp;quot;next_month_btn&amp;quot;).addEventListener(&amp;quot;click&amp;quot;, function(event){&lt;br /&gt;
	currentMonth = currentMonth.nextMonth(); // Previous month would be currentMonth.prevMonth()&lt;br /&gt;
	updateCalendar(); // Whenever the month is updated, we'll need to re-render the calendar in HTML&lt;br /&gt;
	alert(&amp;quot;The new month is &amp;quot;+currentMonth.month+&amp;quot; &amp;quot;+currentMonth.year);&lt;br /&gt;
}, false);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
// This updateCalendar() function only alerts the dates in the currently specified month.  You need to write&lt;br /&gt;
// it to modify the DOM (optionally using jQuery) to display the days and weeks in the current month.&lt;br /&gt;
function updateCalendar(){&lt;br /&gt;
	var weeks = currentMonth.getWeeks();&lt;br /&gt;
	&lt;br /&gt;
	for(var w in weeks){&lt;br /&gt;
		var days = weeks[w].getDates();&lt;br /&gt;
		// days contains normal JavaScript Date objects.&lt;br /&gt;
		&lt;br /&gt;
		alert(&amp;quot;Week starting on &amp;quot;+days[0]);&lt;br /&gt;
		&lt;br /&gt;
		for(var d in days){&lt;br /&gt;
			// You can see console.log() output in your JavaScript debugging tool, like Firebug,&lt;br /&gt;
			// WebWit Inspector, or Dragonfly.&lt;br /&gt;
			console.log(days[d].toISOString());&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Important:''' JavaScript starts the months of a year, and the days of a week, at index 0.  This means that '''''in JavaScript, January is month 0, and December is month 11.'''''  Our calendar helper functions maintain this JavaScript convention.&lt;br /&gt;
&lt;br /&gt;
=== Web Security and Validation ===&lt;br /&gt;
&lt;br /&gt;
Your project needs to demonstrate that thought was put into web security and best practice.  For more information, see this week's Web Application Security guide: [[Web Application Security, Part 3]]&lt;br /&gt;
&lt;br /&gt;
In particular:&lt;br /&gt;
&lt;br /&gt;
* '''Your application needs to prevent XSS attacks.'''  The easiest way to prevent this is to continue sanitizing ''all'' of your output using '''htmlentities()'''.&lt;br /&gt;
* '''Perform precautionary measures to prevent session hijacking attacks.'''&lt;br /&gt;
*: You should specify your session cookie to be HTTP-Only.  However, for the means of this module, you need not test for user agent consistency.&lt;br /&gt;
* '''Optional:''' Validate your JavaScript code using [http://www.jshint.com/ JSHint] for 0.5 points of Creative Portion, or [http://jslint.com/ JSLint] for 0.5 points of Creative Portion.  You cannot do both.  &lt;br /&gt;
&lt;br /&gt;
You should continue the practices that you have learned in past weeks:&lt;br /&gt;
&lt;br /&gt;
* Pass tokens in forms to prevent CSRF attacks.&lt;br /&gt;
*: '''Hint:''' You will need to send your CSRF tokens in your AJAX requests.  Remember that AJAX still submits forms and runs server-side scripts, just like the vanilla forms you've been using in Modules 2 and 3.&lt;br /&gt;
* Use prepared queries to prevent SQL Injection attacks.&lt;br /&gt;
* If storing passwords in a database, always store them salted and encrypted.&lt;br /&gt;
* Your page should validate with no errors through the W3C validator.&lt;br /&gt;
&lt;br /&gt;
== Grading ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;font-size:2em; line-height:2em;&amp;quot;&amp;gt;'''Due Date: Monday, October 29th by 1pm (both individual and group)'''&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Please see the notes at the bottom:&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
!Assignment&lt;br /&gt;
!Points&lt;br /&gt;
|-&lt;br /&gt;
|Calculator&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
|Weather Widget&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|jQuery Dialogs&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
!colspan=&amp;quot;2&amp;quot;|Group Portion:&lt;br /&gt;
|-&lt;br /&gt;
|Calendar month view correct and Move between months (without page reload)&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|User authentication and registration (without page reload)&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Add events (new event shown in calendar without page reload)&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Events added are private and other users cannot see them&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
|Delete events (event removed from calendar without page reload)&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
|-&lt;br /&gt;
|Safe from XSS and Session Hijacking&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|-&lt;br /&gt;
|Validation, CSRF, Salted Passwords, Safe SQL Queries&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Creative Portion&lt;br /&gt;
|2&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Total: 10 Points&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*You must get written permission at least one day before the due date for your creative portion.  Failure to get written permission will result in a one point penalty(the point will be deducted when grades are entered into the gradebook, and not at your demo time).  You will lose the point even if your creative portion is amazing.  Send permission requests to Marc (see the Google Group), and include both your and your partner's ID numbers in the title.&lt;br /&gt;
&lt;br /&gt;
*You will still lose one point per day late.  As the module is only worth 10 points, that results in a 10% penalty.  (Note that all modules are weighted similarly, 10 points for this module does not mean it is only worth half of the previous module).&lt;br /&gt;
&lt;br /&gt;
[[Category:Module 4]]&lt;br /&gt;
[[Category:Modules]]&lt;/div&gt;</summary>
		<author><name>Marc</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=Module_6&amp;diff=821</id>
		<title>Module 6</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=Module_6&amp;diff=821"/>
		<updated>2012-10-15T16:58:59Z</updated>

		<summary type="html">&lt;p&gt;Marc: /* Grading */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In Module 4, you will learn about JavaScript, the prevailing client-side language, and AJAX, a method for performing asynchronous updates to a web page (without refreshing the page).&lt;br /&gt;
&lt;br /&gt;
This article contains your assignments for Module 4.&lt;br /&gt;
&lt;br /&gt;
== Individual Assignments ==&lt;br /&gt;
&lt;br /&gt;
=== JavaScript Calculator ===&lt;br /&gt;
&lt;br /&gt;
In Module 2, you made a calculator using PHP.  Now you will be making one using JavaScript.&lt;br /&gt;
&lt;br /&gt;
Read the JavaScript guide first: [[Javascript and AJAX]]&lt;br /&gt;
&lt;br /&gt;
* The web page should have two input fields and a radio button group for the operation, with the 4 basic math operations represented (add,subtract,multiply,divide).&lt;br /&gt;
* The javascript should monitor all three fields and display the current result whenever the user changes any value in any field, without refreshing the page.&lt;br /&gt;
* The calculator should be completely self-contained; i.e., you should not be making any requests to any other server-side or client-side scripts or web pages after the initial page load.&lt;br /&gt;
&lt;br /&gt;
'''Tip:''' You can embed JavaScript code into an HTML document like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;
// your code here&lt;br /&gt;
&amp;lt;/script&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Tip:''' If your code isn't working the way you expect, use a JavaScript error console.  In Chrome, for example, press Ctrl-Shift-I (or Cmd-Option-I) to open the WebKit inspector.&lt;br /&gt;
&lt;br /&gt;
=== Weather Widget ===&lt;br /&gt;
&lt;br /&gt;
In this section, you will make a web page that displays the weather forecast using AJAX requests to a weather server.  You should complete this section ''without'' using JavaScript libraries like jQuery.&lt;br /&gt;
&lt;br /&gt;
# Make an empty HTML document; name it '''weather.html'''&lt;br /&gt;
#: Refer to the [[HTML and CSS]] guide for the skeleton of an HTML document&lt;br /&gt;
# Define a function in JavaScript; call it '''fetchWeather()'''.  You may write your JavaScript in an embedded script in your head tag.&lt;br /&gt;
# Inside your '''fetchWeather()''' function, make an AJAX request to the weather server.&lt;br /&gt;
#: We have a server that outputs the current weather in JSON format.  The format is documented in the [[#JSON Structure]] section below.&lt;br /&gt;
#: '''URL:''' http://research.engineering.wustl.edu/~todd/cse330/module4/weather_json.php&lt;br /&gt;
#: We kindly thank Yahoo Weather for providing us with up-to-date weather information.&lt;br /&gt;
#* '''Note:''' You normally cannot perform AJAX requests cross-domain.  We have set the &amp;lt;code&amp;gt;Access-Control-Allow-Origin&amp;lt;/code&amp;gt; header on our server to allow requests from your EC2 instances.&lt;br /&gt;
# In your callback, process the JSON and use JavaScript to manipulate the HTML DOM to display the following information on your page:&lt;br /&gt;
#* Location&lt;br /&gt;
#** City, in a &amp;lt;nowiki&amp;gt;&amp;lt;strong&amp;gt;&amp;lt;/nowiki&amp;gt; tag&lt;br /&gt;
#** State, not in any tag&lt;br /&gt;
#* Humidity&lt;br /&gt;
#* Current Temperature&lt;br /&gt;
#* Image for Tomorrow's Forecast (see [[#Weather Condition Images]] below for more information)&lt;br /&gt;
#* Image for the Day After Tomorrow's Forecast&lt;br /&gt;
# Finally, bind '''fetchWeather()''' to the DOMContentReady event so that your weather widget is automatically initialized when the page is loaded:&lt;br /&gt;
#: &amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;document.addEventListener(&amp;quot;DOMContentReady&amp;quot;, fetchWeather, false);&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Use the following HTML:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;weather&amp;quot; id=&amp;quot;weatherWidget&amp;quot;&amp;gt;&lt;br /&gt;
	&amp;lt;div class=&amp;quot;weather-loc&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
	&amp;lt;div class=&amp;quot;weather-humidity&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
	&amp;lt;div class=&amp;quot;weather-temp&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
	&amp;lt;img class=&amp;quot;weather-tomorrow&amp;quot; /&amp;gt;&lt;br /&gt;
	&amp;lt;img class=&amp;quot;weather-dayaftertomorrow&amp;quot; /&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Include the CSS file from here: http://research.engineering.wustl.edu/~todd/cse330/module4/weather.css&lt;br /&gt;
&lt;br /&gt;
When everything is working, the weather widget should look something like this:&lt;br /&gt;
&lt;br /&gt;
[[File:WeatherWidget.png]]&lt;br /&gt;
&lt;br /&gt;
'''Important:''' The widget in this section needs to work in only Firefox and Chrome.  It does '''''not''''' need to work Internet Explorer.&lt;br /&gt;
&lt;br /&gt;
==== Tips ====&lt;br /&gt;
&lt;br /&gt;
===== JSON Structure =====&lt;br /&gt;
&lt;br /&gt;
The JSON from our server looks like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
   &amp;quot;updated&amp;quot;: &amp;quot;Thu, 11 Oct 2012 5:54 pm CDT&amp;quot;,&lt;br /&gt;
   &amp;quot;location&amp;quot;: {&lt;br /&gt;
      &amp;quot;city&amp;quot;: &amp;quot;St. Louis&amp;quot;,&lt;br /&gt;
      &amp;quot;state&amp;quot;: &amp;quot;MO&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;wind&amp;quot;: {&lt;br /&gt;
      &amp;quot;chill&amp;quot;: &amp;quot;62&amp;quot;,&lt;br /&gt;
      &amp;quot;direction&amp;quot;: &amp;quot;150&amp;quot;,&lt;br /&gt;
      &amp;quot;speed&amp;quot;: &amp;quot;3 mph&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;atmosphere&amp;quot;: {&lt;br /&gt;
      &amp;quot;humidity&amp;quot;: &amp;quot;50&amp;quot;,&lt;br /&gt;
      &amp;quot;visibility&amp;quot;: &amp;quot;10&amp;quot;,&lt;br /&gt;
      &amp;quot;pressure&amp;quot;: &amp;quot;30.12 in&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;current&amp;quot;: {&lt;br /&gt;
      &amp;quot;code&amp;quot;: &amp;quot;28&amp;quot;,&lt;br /&gt;
      &amp;quot;text&amp;quot;: &amp;quot;Mostly Cloudy&amp;quot;,&lt;br /&gt;
      &amp;quot;temp&amp;quot;: &amp;quot;62°F&amp;quot;,&lt;br /&gt;
      &amp;quot;date&amp;quot;: &amp;quot;Thu, 11 Oct 2012 5:54 pm CDT&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;tomorrow&amp;quot;: {&lt;br /&gt;
      &amp;quot;code&amp;quot;: &amp;quot;29&amp;quot;,&lt;br /&gt;
      &amp;quot;text&amp;quot;: &amp;quot;Clouds Early/Clearing Late&amp;quot;,&lt;br /&gt;
      &amp;quot;low&amp;quot;: &amp;quot;45°F&amp;quot;,&lt;br /&gt;
      &amp;quot;high&amp;quot;: &amp;quot;61°F&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;dayafter&amp;quot;: {&lt;br /&gt;
      &amp;quot;code&amp;quot;: &amp;quot;30&amp;quot;,&lt;br /&gt;
      &amp;quot;text&amp;quot;: &amp;quot;Partly Cloudy&amp;quot;,&lt;br /&gt;
      &amp;quot;low&amp;quot;: &amp;quot;53°F&amp;quot;,&lt;br /&gt;
      &amp;quot;high&amp;quot;: &amp;quot;65°F&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;credit&amp;quot;: &amp;quot;http://us.rd.yahoo.com/dailynews/rss/weather/St._Louis__MO/*http://weather.yahoo.com/forecast/USMO0170_f.html&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Weather Condition Images =====&lt;br /&gt;
&lt;br /&gt;
Each day's forecast has a code.  There are images associated with these codes.&lt;br /&gt;
&lt;br /&gt;
You can get images from here: &amp;lt;nowiki&amp;gt;http://us.i1.yimg.com/us.yimg.com/i/us/nws/weather/gr/&amp;lt;/nowiki&amp;gt;'''##'''&amp;lt;nowiki&amp;gt;ds.png&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Replace the '''##''' with the forecast code.  For example, for code 32, the URL would be: http://us.i1.yimg.com/us.yimg.com/i/us/nws/weather/gr/32ds.png&lt;br /&gt;
&lt;br /&gt;
=== jQuery Dialogs ===&lt;br /&gt;
&lt;br /&gt;
Helpful Resource: [http://docs.jquery.com/Main_Page jQuery Documentation] ... Some additional tips: [[jQuery]]&lt;br /&gt;
&lt;br /&gt;
Create a simple page using jQuery dialogs.&lt;br /&gt;
&lt;br /&gt;
* Create a page that has the words &amp;quot;Google&amp;quot; and &amp;quot;Yahoo&amp;quot;.&lt;br /&gt;
* When the user clicks the &amp;quot;Google&amp;quot; text, open a jQuery dialog window with one jQuery dialog button.  If the button is pressed, display the Google logo image (the image can be stored on your web server) on the web page, and if the dialog is closed any other way, do nothing.&lt;br /&gt;
* When the user clicks the &amp;quot;Yahoo&amp;quot; text, open a jQuery dialog window with one jQuery dialog button.  If the button is pressed, display the Yahoo logo image (the image can be stored on your web server) on the web page, and if the dialog is closed any other way, do nothing.&lt;br /&gt;
* Initially there should be no image on the page (i.e., the img should be hidden with the CSS display attribute).  After one of the two images is displayed, if the user clicks on the image, a jQuery dialog box should be opened with one dialog button, and if the button is pressed then the image should be hidden again.  Otherwise, do nothing.&lt;br /&gt;
&lt;br /&gt;
== Group Project ==&lt;br /&gt;
&lt;br /&gt;
You will work in pairs on this project.&lt;br /&gt;
&lt;br /&gt;
'''Important Reminder:''' frequently commit your work to your subversion repository as a backup!&lt;br /&gt;
&lt;br /&gt;
I forgot if I already mentioned this, but '''start early on this project!''' It will take longer than you think, I promise!&lt;br /&gt;
&lt;br /&gt;
=== Calendar ===&lt;br /&gt;
&lt;br /&gt;
Build a simple calendar that allows users to add and remove events dynamically.&lt;br /&gt;
&lt;br /&gt;
You will use JavaScript to process user interactions at the web browser, without ever refreshing the browser after the initial web page load.  You may use a JavaScript library of your choice, including jQuery.  (No extra credit will be given for ''not'' using a JavaScript library.)&lt;br /&gt;
&lt;br /&gt;
Your application should utilize AJAX to run server-side PHP scripts that query your database to save and retrieve information, including user accounts and events.&lt;br /&gt;
&lt;br /&gt;
==== Examples ====&lt;br /&gt;
&lt;br /&gt;
* https://calendar.google.com/&lt;br /&gt;
* http://www.zoho.com/calendar/&lt;br /&gt;
&lt;br /&gt;
==== Requirements ====&lt;br /&gt;
&lt;br /&gt;
* Support a month-by-month view of the calendar.&lt;br /&gt;
*: Show one month at a time, with buttons to move forward or backward.&lt;br /&gt;
*: There should be no limit to how far forward or backward the user can go.&lt;br /&gt;
* Users can register and log in to the website.&lt;br /&gt;
*: You may leverage your MySQL project code and database from last week to get started.&lt;br /&gt;
*: You may alternatively use OpenID for user authentication.  Note that you will still need a Users table in order associate calendar events with a certain OpenID.&lt;br /&gt;
* Unregistered users should see no events on the calendar.&lt;br /&gt;
* Registered users can add events.&lt;br /&gt;
*: All events should have a date and time, but do not need to have a duration.&lt;br /&gt;
*: You do ''not'' need to support recurring events (where you add an event that repeats, for example, every monday).&lt;br /&gt;
* Registered users see only events that they have added.&lt;br /&gt;
* Registered users can delete their events, but not the events of others.&lt;br /&gt;
* All user and event data should be kept in a database.&lt;br /&gt;
* At no time should the main page need to be reloaded.&lt;br /&gt;
*: User registration, user authentication, event addition, and event deletion should all be handled by JavaScript and AJAX requests to your server.&lt;br /&gt;
* Your page needs to work in the versions of Firefox and Chrome installed on the lab computers.&lt;br /&gt;
&lt;br /&gt;
'''Tip:''' Run your database schema by a TA before implementing it.&lt;br /&gt;
&lt;br /&gt;
==== Calendar Helper Library ====&lt;br /&gt;
&lt;br /&gt;
To help you get started with your calendar, we have written some JavaScript helper functions.  The code is available at:&lt;br /&gt;
* Full Version (for you to refer): http://research.engineering.wustl.edu/~todd/cse330/module4/calendar.js&lt;br /&gt;
* Minified Version (to include in your pages):http://research.engineering.wustl.edu/~todd/cse330/module4/calendar.min.js&lt;br /&gt;
&lt;br /&gt;
For example, this is how you would make a button to load the next month and show alerts containing all the days in the weeks contained by that month.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
// For our purposes, we can keep the current month in a variable in the global scope&lt;br /&gt;
var currentMonth = new Month(2012, 9); // October 2012&lt;br /&gt;
&lt;br /&gt;
// Change the month when the &amp;quot;next&amp;quot; button is pressed&lt;br /&gt;
document.getElementById(&amp;quot;next_month_btn&amp;quot;).addEventListener(&amp;quot;click&amp;quot;, function(event){&lt;br /&gt;
	currentMonth = currentMonth.nextMonth(); // Previous month would be currentMonth.prevMonth()&lt;br /&gt;
	updateCalendar(); // Whenever the month is updated, we'll need to re-render the calendar in HTML&lt;br /&gt;
	alert(&amp;quot;The new month is &amp;quot;+currentMonth.month+&amp;quot; &amp;quot;+currentMonth.year);&lt;br /&gt;
}, false);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
// This updateCalendar() function only alerts the dates in the currently specified month.  You need to write&lt;br /&gt;
// it to modify the DOM (optionally using jQuery) to display the days and weeks in the current month.&lt;br /&gt;
function updateCalendar(){&lt;br /&gt;
	var weeks = currentMonth.getWeeks();&lt;br /&gt;
	&lt;br /&gt;
	for(var w in weeks){&lt;br /&gt;
		var days = weeks[w].getDates();&lt;br /&gt;
		// days contains normal JavaScript Date objects.&lt;br /&gt;
		&lt;br /&gt;
		alert(&amp;quot;Week starting on &amp;quot;+days[0]);&lt;br /&gt;
		&lt;br /&gt;
		for(var d in days){&lt;br /&gt;
			// You can see console.log() output in your JavaScript debugging tool, like Firebug,&lt;br /&gt;
			// WebWit Inspector, or Dragonfly.&lt;br /&gt;
			console.log(days[d].toISOString());&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Important:''' JavaScript starts the months of a year, and the days of a week, at index 0.  This means that '''''in JavaScript, January is month 0, and December is month 11.'''''  Our calendar helper functions maintain this JavaScript convention.&lt;br /&gt;
&lt;br /&gt;
=== Web Security and Validation ===&lt;br /&gt;
&lt;br /&gt;
Your project needs to demonstrate that thought was put into web security and best practice.  For more information, see this week's Web Application Security guide: [[Web Application Security, Part 3]]&lt;br /&gt;
&lt;br /&gt;
In particular:&lt;br /&gt;
&lt;br /&gt;
* '''Your application needs to prevent XSS attacks.'''  The easiest way to prevent this is to continue sanitizing ''all'' of your output using '''htmlentities()'''.&lt;br /&gt;
* '''Perform precautionary measures to prevent session hijacking attacks.'''&lt;br /&gt;
*: You should specify your session cookie to be HTTP-Only.  However, for the means of this module, you need not test for user agent consistency.&lt;br /&gt;
* '''Optional:''' Validate your JavaScript code using [http://www.jshint.com/ JSHint] for 0.5 points of Creative Portion, or [http://jslint.com/ JSLint] for 0.5 points of Creative Portion.  You cannot do both.  &lt;br /&gt;
&lt;br /&gt;
You should continue the practices that you have learned in past weeks:&lt;br /&gt;
&lt;br /&gt;
* Pass tokens in forms to prevent CSRF attacks.&lt;br /&gt;
*: '''Hint:''' You will need to send your CSRF tokens in your AJAX requests.  Remember that AJAX still submits forms and runs server-side scripts, just like the vanilla forms you've been using in Modules 2 and 3.&lt;br /&gt;
* Use prepared queries to prevent SQL Injection attacks.&lt;br /&gt;
* If storing passwords in a database, always store them salted and encrypted.&lt;br /&gt;
* Your page should validate with no errors through the W3C validator.&lt;br /&gt;
&lt;br /&gt;
== Grading ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;font-size:2em; line-height:2em;&amp;quot;&amp;gt;'''Due Date: Monday, October 29th by 1pm (both individual and group)'''&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Please see the notes at the bottom:&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
!Assignment&lt;br /&gt;
!Points&lt;br /&gt;
|-&lt;br /&gt;
|Calculator&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
|Weather Widget&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|jQuery Dialogs&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
!colspan=&amp;quot;2&amp;quot;|Group Portion:&lt;br /&gt;
|-&lt;br /&gt;
|Calendar month view correct and Move between months (without page reload)&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|User authentication and registration (without page reload)&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Add events (new event shown in calendar without page reload)&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Events added are private and other users cannot see them&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
|Delete events (event removed from calendar without page reload)&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
|-&lt;br /&gt;
|Safe from XSS and Session Hijacking&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|-&lt;br /&gt;
|Validation, CSRF, Salted Passwords, Safe SQL Queries&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Creative Portion&lt;br /&gt;
|2&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Total: 10 Points&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*You must get written permission at least one day before the due date for your creative portion.  Failure to get written permission will result in a one point penalty(the point will be deducted when grades are entered into the gradebook, and not at your demo time).  You will lose the point even if your creative portion is amazing.  Send permission requests to Marc (see the Google Group).&lt;br /&gt;
&lt;br /&gt;
*You will still lose one point per day late.  As the module is only worth 10 points, that results in a 10% penalty.  (Note that all modules are weighted similarly, 10 points for this module does not mean it is only worth half of the previous module).&lt;br /&gt;
&lt;br /&gt;
[[Category:Module 4]]&lt;br /&gt;
[[Category:Modules]]&lt;/div&gt;</summary>
		<author><name>Marc</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=Module_6&amp;diff=820</id>
		<title>Module 6</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=Module_6&amp;diff=820"/>
		<updated>2012-10-15T16:58:38Z</updated>

		<summary type="html">&lt;p&gt;Marc: /* Grading */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In Module 4, you will learn about JavaScript, the prevailing client-side language, and AJAX, a method for performing asynchronous updates to a web page (without refreshing the page).&lt;br /&gt;
&lt;br /&gt;
This article contains your assignments for Module 4.&lt;br /&gt;
&lt;br /&gt;
== Individual Assignments ==&lt;br /&gt;
&lt;br /&gt;
=== JavaScript Calculator ===&lt;br /&gt;
&lt;br /&gt;
In Module 2, you made a calculator using PHP.  Now you will be making one using JavaScript.&lt;br /&gt;
&lt;br /&gt;
Read the JavaScript guide first: [[Javascript and AJAX]]&lt;br /&gt;
&lt;br /&gt;
* The web page should have two input fields and a radio button group for the operation, with the 4 basic math operations represented (add,subtract,multiply,divide).&lt;br /&gt;
* The javascript should monitor all three fields and display the current result whenever the user changes any value in any field, without refreshing the page.&lt;br /&gt;
* The calculator should be completely self-contained; i.e., you should not be making any requests to any other server-side or client-side scripts or web pages after the initial page load.&lt;br /&gt;
&lt;br /&gt;
'''Tip:''' You can embed JavaScript code into an HTML document like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;
// your code here&lt;br /&gt;
&amp;lt;/script&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Tip:''' If your code isn't working the way you expect, use a JavaScript error console.  In Chrome, for example, press Ctrl-Shift-I (or Cmd-Option-I) to open the WebKit inspector.&lt;br /&gt;
&lt;br /&gt;
=== Weather Widget ===&lt;br /&gt;
&lt;br /&gt;
In this section, you will make a web page that displays the weather forecast using AJAX requests to a weather server.  You should complete this section ''without'' using JavaScript libraries like jQuery.&lt;br /&gt;
&lt;br /&gt;
# Make an empty HTML document; name it '''weather.html'''&lt;br /&gt;
#: Refer to the [[HTML and CSS]] guide for the skeleton of an HTML document&lt;br /&gt;
# Define a function in JavaScript; call it '''fetchWeather()'''.  You may write your JavaScript in an embedded script in your head tag.&lt;br /&gt;
# Inside your '''fetchWeather()''' function, make an AJAX request to the weather server.&lt;br /&gt;
#: We have a server that outputs the current weather in JSON format.  The format is documented in the [[#JSON Structure]] section below.&lt;br /&gt;
#: '''URL:''' http://research.engineering.wustl.edu/~todd/cse330/module4/weather_json.php&lt;br /&gt;
#: We kindly thank Yahoo Weather for providing us with up-to-date weather information.&lt;br /&gt;
#* '''Note:''' You normally cannot perform AJAX requests cross-domain.  We have set the &amp;lt;code&amp;gt;Access-Control-Allow-Origin&amp;lt;/code&amp;gt; header on our server to allow requests from your EC2 instances.&lt;br /&gt;
# In your callback, process the JSON and use JavaScript to manipulate the HTML DOM to display the following information on your page:&lt;br /&gt;
#* Location&lt;br /&gt;
#** City, in a &amp;lt;nowiki&amp;gt;&amp;lt;strong&amp;gt;&amp;lt;/nowiki&amp;gt; tag&lt;br /&gt;
#** State, not in any tag&lt;br /&gt;
#* Humidity&lt;br /&gt;
#* Current Temperature&lt;br /&gt;
#* Image for Tomorrow's Forecast (see [[#Weather Condition Images]] below for more information)&lt;br /&gt;
#* Image for the Day After Tomorrow's Forecast&lt;br /&gt;
# Finally, bind '''fetchWeather()''' to the DOMContentReady event so that your weather widget is automatically initialized when the page is loaded:&lt;br /&gt;
#: &amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;document.addEventListener(&amp;quot;DOMContentReady&amp;quot;, fetchWeather, false);&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Use the following HTML:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;weather&amp;quot; id=&amp;quot;weatherWidget&amp;quot;&amp;gt;&lt;br /&gt;
	&amp;lt;div class=&amp;quot;weather-loc&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
	&amp;lt;div class=&amp;quot;weather-humidity&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
	&amp;lt;div class=&amp;quot;weather-temp&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
	&amp;lt;img class=&amp;quot;weather-tomorrow&amp;quot; /&amp;gt;&lt;br /&gt;
	&amp;lt;img class=&amp;quot;weather-dayaftertomorrow&amp;quot; /&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Include the CSS file from here: http://research.engineering.wustl.edu/~todd/cse330/module4/weather.css&lt;br /&gt;
&lt;br /&gt;
When everything is working, the weather widget should look something like this:&lt;br /&gt;
&lt;br /&gt;
[[File:WeatherWidget.png]]&lt;br /&gt;
&lt;br /&gt;
'''Important:''' The widget in this section needs to work in only Firefox and Chrome.  It does '''''not''''' need to work Internet Explorer.&lt;br /&gt;
&lt;br /&gt;
==== Tips ====&lt;br /&gt;
&lt;br /&gt;
===== JSON Structure =====&lt;br /&gt;
&lt;br /&gt;
The JSON from our server looks like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
   &amp;quot;updated&amp;quot;: &amp;quot;Thu, 11 Oct 2012 5:54 pm CDT&amp;quot;,&lt;br /&gt;
   &amp;quot;location&amp;quot;: {&lt;br /&gt;
      &amp;quot;city&amp;quot;: &amp;quot;St. Louis&amp;quot;,&lt;br /&gt;
      &amp;quot;state&amp;quot;: &amp;quot;MO&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;wind&amp;quot;: {&lt;br /&gt;
      &amp;quot;chill&amp;quot;: &amp;quot;62&amp;quot;,&lt;br /&gt;
      &amp;quot;direction&amp;quot;: &amp;quot;150&amp;quot;,&lt;br /&gt;
      &amp;quot;speed&amp;quot;: &amp;quot;3 mph&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;atmosphere&amp;quot;: {&lt;br /&gt;
      &amp;quot;humidity&amp;quot;: &amp;quot;50&amp;quot;,&lt;br /&gt;
      &amp;quot;visibility&amp;quot;: &amp;quot;10&amp;quot;,&lt;br /&gt;
      &amp;quot;pressure&amp;quot;: &amp;quot;30.12 in&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;current&amp;quot;: {&lt;br /&gt;
      &amp;quot;code&amp;quot;: &amp;quot;28&amp;quot;,&lt;br /&gt;
      &amp;quot;text&amp;quot;: &amp;quot;Mostly Cloudy&amp;quot;,&lt;br /&gt;
      &amp;quot;temp&amp;quot;: &amp;quot;62°F&amp;quot;,&lt;br /&gt;
      &amp;quot;date&amp;quot;: &amp;quot;Thu, 11 Oct 2012 5:54 pm CDT&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;tomorrow&amp;quot;: {&lt;br /&gt;
      &amp;quot;code&amp;quot;: &amp;quot;29&amp;quot;,&lt;br /&gt;
      &amp;quot;text&amp;quot;: &amp;quot;Clouds Early/Clearing Late&amp;quot;,&lt;br /&gt;
      &amp;quot;low&amp;quot;: &amp;quot;45°F&amp;quot;,&lt;br /&gt;
      &amp;quot;high&amp;quot;: &amp;quot;61°F&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;dayafter&amp;quot;: {&lt;br /&gt;
      &amp;quot;code&amp;quot;: &amp;quot;30&amp;quot;,&lt;br /&gt;
      &amp;quot;text&amp;quot;: &amp;quot;Partly Cloudy&amp;quot;,&lt;br /&gt;
      &amp;quot;low&amp;quot;: &amp;quot;53°F&amp;quot;,&lt;br /&gt;
      &amp;quot;high&amp;quot;: &amp;quot;65°F&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;credit&amp;quot;: &amp;quot;http://us.rd.yahoo.com/dailynews/rss/weather/St._Louis__MO/*http://weather.yahoo.com/forecast/USMO0170_f.html&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Weather Condition Images =====&lt;br /&gt;
&lt;br /&gt;
Each day's forecast has a code.  There are images associated with these codes.&lt;br /&gt;
&lt;br /&gt;
You can get images from here: &amp;lt;nowiki&amp;gt;http://us.i1.yimg.com/us.yimg.com/i/us/nws/weather/gr/&amp;lt;/nowiki&amp;gt;'''##'''&amp;lt;nowiki&amp;gt;ds.png&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Replace the '''##''' with the forecast code.  For example, for code 32, the URL would be: http://us.i1.yimg.com/us.yimg.com/i/us/nws/weather/gr/32ds.png&lt;br /&gt;
&lt;br /&gt;
=== jQuery Dialogs ===&lt;br /&gt;
&lt;br /&gt;
Helpful Resource: [http://docs.jquery.com/Main_Page jQuery Documentation] ... Some additional tips: [[jQuery]]&lt;br /&gt;
&lt;br /&gt;
Create a simple page using jQuery dialogs.&lt;br /&gt;
&lt;br /&gt;
* Create a page that has the words &amp;quot;Google&amp;quot; and &amp;quot;Yahoo&amp;quot;.&lt;br /&gt;
* When the user clicks the &amp;quot;Google&amp;quot; text, open a jQuery dialog window with one jQuery dialog button.  If the button is pressed, display the Google logo image (the image can be stored on your web server) on the web page, and if the dialog is closed any other way, do nothing.&lt;br /&gt;
* When the user clicks the &amp;quot;Yahoo&amp;quot; text, open a jQuery dialog window with one jQuery dialog button.  If the button is pressed, display the Yahoo logo image (the image can be stored on your web server) on the web page, and if the dialog is closed any other way, do nothing.&lt;br /&gt;
* Initially there should be no image on the page (i.e., the img should be hidden with the CSS display attribute).  After one of the two images is displayed, if the user clicks on the image, a jQuery dialog box should be opened with one dialog button, and if the button is pressed then the image should be hidden again.  Otherwise, do nothing.&lt;br /&gt;
&lt;br /&gt;
== Group Project ==&lt;br /&gt;
&lt;br /&gt;
You will work in pairs on this project.&lt;br /&gt;
&lt;br /&gt;
'''Important Reminder:''' frequently commit your work to your subversion repository as a backup!&lt;br /&gt;
&lt;br /&gt;
I forgot if I already mentioned this, but '''start early on this project!''' It will take longer than you think, I promise!&lt;br /&gt;
&lt;br /&gt;
=== Calendar ===&lt;br /&gt;
&lt;br /&gt;
Build a simple calendar that allows users to add and remove events dynamically.&lt;br /&gt;
&lt;br /&gt;
You will use JavaScript to process user interactions at the web browser, without ever refreshing the browser after the initial web page load.  You may use a JavaScript library of your choice, including jQuery.  (No extra credit will be given for ''not'' using a JavaScript library.)&lt;br /&gt;
&lt;br /&gt;
Your application should utilize AJAX to run server-side PHP scripts that query your database to save and retrieve information, including user accounts and events.&lt;br /&gt;
&lt;br /&gt;
==== Examples ====&lt;br /&gt;
&lt;br /&gt;
* https://calendar.google.com/&lt;br /&gt;
* http://www.zoho.com/calendar/&lt;br /&gt;
&lt;br /&gt;
==== Requirements ====&lt;br /&gt;
&lt;br /&gt;
* Support a month-by-month view of the calendar.&lt;br /&gt;
*: Show one month at a time, with buttons to move forward or backward.&lt;br /&gt;
*: There should be no limit to how far forward or backward the user can go.&lt;br /&gt;
* Users can register and log in to the website.&lt;br /&gt;
*: You may leverage your MySQL project code and database from last week to get started.&lt;br /&gt;
*: You may alternatively use OpenID for user authentication.  Note that you will still need a Users table in order associate calendar events with a certain OpenID.&lt;br /&gt;
* Unregistered users should see no events on the calendar.&lt;br /&gt;
* Registered users can add events.&lt;br /&gt;
*: All events should have a date and time, but do not need to have a duration.&lt;br /&gt;
*: You do ''not'' need to support recurring events (where you add an event that repeats, for example, every monday).&lt;br /&gt;
* Registered users see only events that they have added.&lt;br /&gt;
* Registered users can delete their events, but not the events of others.&lt;br /&gt;
* All user and event data should be kept in a database.&lt;br /&gt;
* At no time should the main page need to be reloaded.&lt;br /&gt;
*: User registration, user authentication, event addition, and event deletion should all be handled by JavaScript and AJAX requests to your server.&lt;br /&gt;
* Your page needs to work in the versions of Firefox and Chrome installed on the lab computers.&lt;br /&gt;
&lt;br /&gt;
'''Tip:''' Run your database schema by a TA before implementing it.&lt;br /&gt;
&lt;br /&gt;
==== Calendar Helper Library ====&lt;br /&gt;
&lt;br /&gt;
To help you get started with your calendar, we have written some JavaScript helper functions.  The code is available at:&lt;br /&gt;
* Full Version (for you to refer): http://research.engineering.wustl.edu/~todd/cse330/module4/calendar.js&lt;br /&gt;
* Minified Version (to include in your pages):http://research.engineering.wustl.edu/~todd/cse330/module4/calendar.min.js&lt;br /&gt;
&lt;br /&gt;
For example, this is how you would make a button to load the next month and show alerts containing all the days in the weeks contained by that month.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
// For our purposes, we can keep the current month in a variable in the global scope&lt;br /&gt;
var currentMonth = new Month(2012, 9); // October 2012&lt;br /&gt;
&lt;br /&gt;
// Change the month when the &amp;quot;next&amp;quot; button is pressed&lt;br /&gt;
document.getElementById(&amp;quot;next_month_btn&amp;quot;).addEventListener(&amp;quot;click&amp;quot;, function(event){&lt;br /&gt;
	currentMonth = currentMonth.nextMonth(); // Previous month would be currentMonth.prevMonth()&lt;br /&gt;
	updateCalendar(); // Whenever the month is updated, we'll need to re-render the calendar in HTML&lt;br /&gt;
	alert(&amp;quot;The new month is &amp;quot;+currentMonth.month+&amp;quot; &amp;quot;+currentMonth.year);&lt;br /&gt;
}, false);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
// This updateCalendar() function only alerts the dates in the currently specified month.  You need to write&lt;br /&gt;
// it to modify the DOM (optionally using jQuery) to display the days and weeks in the current month.&lt;br /&gt;
function updateCalendar(){&lt;br /&gt;
	var weeks = currentMonth.getWeeks();&lt;br /&gt;
	&lt;br /&gt;
	for(var w in weeks){&lt;br /&gt;
		var days = weeks[w].getDates();&lt;br /&gt;
		// days contains normal JavaScript Date objects.&lt;br /&gt;
		&lt;br /&gt;
		alert(&amp;quot;Week starting on &amp;quot;+days[0]);&lt;br /&gt;
		&lt;br /&gt;
		for(var d in days){&lt;br /&gt;
			// You can see console.log() output in your JavaScript debugging tool, like Firebug,&lt;br /&gt;
			// WebWit Inspector, or Dragonfly.&lt;br /&gt;
			console.log(days[d].toISOString());&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Important:''' JavaScript starts the months of a year, and the days of a week, at index 0.  This means that '''''in JavaScript, January is month 0, and December is month 11.'''''  Our calendar helper functions maintain this JavaScript convention.&lt;br /&gt;
&lt;br /&gt;
=== Web Security and Validation ===&lt;br /&gt;
&lt;br /&gt;
Your project needs to demonstrate that thought was put into web security and best practice.  For more information, see this week's Web Application Security guide: [[Web Application Security, Part 3]]&lt;br /&gt;
&lt;br /&gt;
In particular:&lt;br /&gt;
&lt;br /&gt;
* '''Your application needs to prevent XSS attacks.'''  The easiest way to prevent this is to continue sanitizing ''all'' of your output using '''htmlentities()'''.&lt;br /&gt;
* '''Perform precautionary measures to prevent session hijacking attacks.'''&lt;br /&gt;
*: You should specify your session cookie to be HTTP-Only.  However, for the means of this module, you need not test for user agent consistency.&lt;br /&gt;
* '''Optional:''' Validate your JavaScript code using [http://www.jshint.com/ JSHint] for 0.5 points of Creative Portion, or [http://jslint.com/ JSLint] for 0.5 points of Creative Portion.  You cannot do both.  &lt;br /&gt;
&lt;br /&gt;
You should continue the practices that you have learned in past weeks:&lt;br /&gt;
&lt;br /&gt;
* Pass tokens in forms to prevent CSRF attacks.&lt;br /&gt;
*: '''Hint:''' You will need to send your CSRF tokens in your AJAX requests.  Remember that AJAX still submits forms and runs server-side scripts, just like the vanilla forms you've been using in Modules 2 and 3.&lt;br /&gt;
* Use prepared queries to prevent SQL Injection attacks.&lt;br /&gt;
* If storing passwords in a database, always store them salted and encrypted.&lt;br /&gt;
* Your page should validate with no errors through the W3C validator.&lt;br /&gt;
&lt;br /&gt;
== Grading ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;font-size:2em; line-height:2em;&amp;quot;&amp;gt;'''Due Date: Monday, October 29th by 1pm (both individual and group)'''&amp;lt;/span&amp;gt;&lt;br /&gt;
Please see the notes at the bottom:&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
!Assignment&lt;br /&gt;
!Points&lt;br /&gt;
|-&lt;br /&gt;
|Calculator&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
|Weather Widget&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|jQuery Dialogs&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
!colspan=&amp;quot;2&amp;quot;|Group Portion:&lt;br /&gt;
|-&lt;br /&gt;
|Calendar month view correct and Move between months (without page reload)&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|User authentication and registration (without page reload)&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Add events (new event shown in calendar without page reload)&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Events added are private and other users cannot see them&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
|Delete events (event removed from calendar without page reload)&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
|-&lt;br /&gt;
|Safe from XSS and Session Hijacking&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|-&lt;br /&gt;
|Validation, CSRF, Salted Passwords, Safe SQL Queries&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Creative Portion&lt;br /&gt;
|2&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Total: 10 Points&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*You must get written permission at least one day before the due date for your creative portion.  Failure to get written permission will result in a one point penalty(the point will be deducted when grades are entered into the gradebook, and not at your demo time).  You will lose the point even if your creative portion is amazing.  Send permission requests to Marc (see the Google Group).*&lt;br /&gt;
&lt;br /&gt;
*You will still lose one point per day late.  As the module is only worth 10 points, that results in a 10% penalty.  (Note that all modules are weighted similarly, 10 points for this module does not mean it is only worth half of the previous module).&lt;br /&gt;
&lt;br /&gt;
[[Category:Module 4]]&lt;br /&gt;
[[Category:Modules]]&lt;/div&gt;</summary>
		<author><name>Marc</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=Module_6&amp;diff=819</id>
		<title>Module 6</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=Module_6&amp;diff=819"/>
		<updated>2012-10-15T16:58:24Z</updated>

		<summary type="html">&lt;p&gt;Marc: /* Grading */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In Module 4, you will learn about JavaScript, the prevailing client-side language, and AJAX, a method for performing asynchronous updates to a web page (without refreshing the page).&lt;br /&gt;
&lt;br /&gt;
This article contains your assignments for Module 4.&lt;br /&gt;
&lt;br /&gt;
== Individual Assignments ==&lt;br /&gt;
&lt;br /&gt;
=== JavaScript Calculator ===&lt;br /&gt;
&lt;br /&gt;
In Module 2, you made a calculator using PHP.  Now you will be making one using JavaScript.&lt;br /&gt;
&lt;br /&gt;
Read the JavaScript guide first: [[Javascript and AJAX]]&lt;br /&gt;
&lt;br /&gt;
* The web page should have two input fields and a radio button group for the operation, with the 4 basic math operations represented (add,subtract,multiply,divide).&lt;br /&gt;
* The javascript should monitor all three fields and display the current result whenever the user changes any value in any field, without refreshing the page.&lt;br /&gt;
* The calculator should be completely self-contained; i.e., you should not be making any requests to any other server-side or client-side scripts or web pages after the initial page load.&lt;br /&gt;
&lt;br /&gt;
'''Tip:''' You can embed JavaScript code into an HTML document like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;
// your code here&lt;br /&gt;
&amp;lt;/script&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Tip:''' If your code isn't working the way you expect, use a JavaScript error console.  In Chrome, for example, press Ctrl-Shift-I (or Cmd-Option-I) to open the WebKit inspector.&lt;br /&gt;
&lt;br /&gt;
=== Weather Widget ===&lt;br /&gt;
&lt;br /&gt;
In this section, you will make a web page that displays the weather forecast using AJAX requests to a weather server.  You should complete this section ''without'' using JavaScript libraries like jQuery.&lt;br /&gt;
&lt;br /&gt;
# Make an empty HTML document; name it '''weather.html'''&lt;br /&gt;
#: Refer to the [[HTML and CSS]] guide for the skeleton of an HTML document&lt;br /&gt;
# Define a function in JavaScript; call it '''fetchWeather()'''.  You may write your JavaScript in an embedded script in your head tag.&lt;br /&gt;
# Inside your '''fetchWeather()''' function, make an AJAX request to the weather server.&lt;br /&gt;
#: We have a server that outputs the current weather in JSON format.  The format is documented in the [[#JSON Structure]] section below.&lt;br /&gt;
#: '''URL:''' http://research.engineering.wustl.edu/~todd/cse330/module4/weather_json.php&lt;br /&gt;
#: We kindly thank Yahoo Weather for providing us with up-to-date weather information.&lt;br /&gt;
#* '''Note:''' You normally cannot perform AJAX requests cross-domain.  We have set the &amp;lt;code&amp;gt;Access-Control-Allow-Origin&amp;lt;/code&amp;gt; header on our server to allow requests from your EC2 instances.&lt;br /&gt;
# In your callback, process the JSON and use JavaScript to manipulate the HTML DOM to display the following information on your page:&lt;br /&gt;
#* Location&lt;br /&gt;
#** City, in a &amp;lt;nowiki&amp;gt;&amp;lt;strong&amp;gt;&amp;lt;/nowiki&amp;gt; tag&lt;br /&gt;
#** State, not in any tag&lt;br /&gt;
#* Humidity&lt;br /&gt;
#* Current Temperature&lt;br /&gt;
#* Image for Tomorrow's Forecast (see [[#Weather Condition Images]] below for more information)&lt;br /&gt;
#* Image for the Day After Tomorrow's Forecast&lt;br /&gt;
# Finally, bind '''fetchWeather()''' to the DOMContentReady event so that your weather widget is automatically initialized when the page is loaded:&lt;br /&gt;
#: &amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;document.addEventListener(&amp;quot;DOMContentReady&amp;quot;, fetchWeather, false);&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Use the following HTML:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;weather&amp;quot; id=&amp;quot;weatherWidget&amp;quot;&amp;gt;&lt;br /&gt;
	&amp;lt;div class=&amp;quot;weather-loc&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
	&amp;lt;div class=&amp;quot;weather-humidity&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
	&amp;lt;div class=&amp;quot;weather-temp&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
	&amp;lt;img class=&amp;quot;weather-tomorrow&amp;quot; /&amp;gt;&lt;br /&gt;
	&amp;lt;img class=&amp;quot;weather-dayaftertomorrow&amp;quot; /&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Include the CSS file from here: http://research.engineering.wustl.edu/~todd/cse330/module4/weather.css&lt;br /&gt;
&lt;br /&gt;
When everything is working, the weather widget should look something like this:&lt;br /&gt;
&lt;br /&gt;
[[File:WeatherWidget.png]]&lt;br /&gt;
&lt;br /&gt;
'''Important:''' The widget in this section needs to work in only Firefox and Chrome.  It does '''''not''''' need to work Internet Explorer.&lt;br /&gt;
&lt;br /&gt;
==== Tips ====&lt;br /&gt;
&lt;br /&gt;
===== JSON Structure =====&lt;br /&gt;
&lt;br /&gt;
The JSON from our server looks like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
   &amp;quot;updated&amp;quot;: &amp;quot;Thu, 11 Oct 2012 5:54 pm CDT&amp;quot;,&lt;br /&gt;
   &amp;quot;location&amp;quot;: {&lt;br /&gt;
      &amp;quot;city&amp;quot;: &amp;quot;St. Louis&amp;quot;,&lt;br /&gt;
      &amp;quot;state&amp;quot;: &amp;quot;MO&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;wind&amp;quot;: {&lt;br /&gt;
      &amp;quot;chill&amp;quot;: &amp;quot;62&amp;quot;,&lt;br /&gt;
      &amp;quot;direction&amp;quot;: &amp;quot;150&amp;quot;,&lt;br /&gt;
      &amp;quot;speed&amp;quot;: &amp;quot;3 mph&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;atmosphere&amp;quot;: {&lt;br /&gt;
      &amp;quot;humidity&amp;quot;: &amp;quot;50&amp;quot;,&lt;br /&gt;
      &amp;quot;visibility&amp;quot;: &amp;quot;10&amp;quot;,&lt;br /&gt;
      &amp;quot;pressure&amp;quot;: &amp;quot;30.12 in&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;current&amp;quot;: {&lt;br /&gt;
      &amp;quot;code&amp;quot;: &amp;quot;28&amp;quot;,&lt;br /&gt;
      &amp;quot;text&amp;quot;: &amp;quot;Mostly Cloudy&amp;quot;,&lt;br /&gt;
      &amp;quot;temp&amp;quot;: &amp;quot;62°F&amp;quot;,&lt;br /&gt;
      &amp;quot;date&amp;quot;: &amp;quot;Thu, 11 Oct 2012 5:54 pm CDT&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;tomorrow&amp;quot;: {&lt;br /&gt;
      &amp;quot;code&amp;quot;: &amp;quot;29&amp;quot;,&lt;br /&gt;
      &amp;quot;text&amp;quot;: &amp;quot;Clouds Early/Clearing Late&amp;quot;,&lt;br /&gt;
      &amp;quot;low&amp;quot;: &amp;quot;45°F&amp;quot;,&lt;br /&gt;
      &amp;quot;high&amp;quot;: &amp;quot;61°F&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;dayafter&amp;quot;: {&lt;br /&gt;
      &amp;quot;code&amp;quot;: &amp;quot;30&amp;quot;,&lt;br /&gt;
      &amp;quot;text&amp;quot;: &amp;quot;Partly Cloudy&amp;quot;,&lt;br /&gt;
      &amp;quot;low&amp;quot;: &amp;quot;53°F&amp;quot;,&lt;br /&gt;
      &amp;quot;high&amp;quot;: &amp;quot;65°F&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;credit&amp;quot;: &amp;quot;http://us.rd.yahoo.com/dailynews/rss/weather/St._Louis__MO/*http://weather.yahoo.com/forecast/USMO0170_f.html&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Weather Condition Images =====&lt;br /&gt;
&lt;br /&gt;
Each day's forecast has a code.  There are images associated with these codes.&lt;br /&gt;
&lt;br /&gt;
You can get images from here: &amp;lt;nowiki&amp;gt;http://us.i1.yimg.com/us.yimg.com/i/us/nws/weather/gr/&amp;lt;/nowiki&amp;gt;'''##'''&amp;lt;nowiki&amp;gt;ds.png&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Replace the '''##''' with the forecast code.  For example, for code 32, the URL would be: http://us.i1.yimg.com/us.yimg.com/i/us/nws/weather/gr/32ds.png&lt;br /&gt;
&lt;br /&gt;
=== jQuery Dialogs ===&lt;br /&gt;
&lt;br /&gt;
Helpful Resource: [http://docs.jquery.com/Main_Page jQuery Documentation] ... Some additional tips: [[jQuery]]&lt;br /&gt;
&lt;br /&gt;
Create a simple page using jQuery dialogs.&lt;br /&gt;
&lt;br /&gt;
* Create a page that has the words &amp;quot;Google&amp;quot; and &amp;quot;Yahoo&amp;quot;.&lt;br /&gt;
* When the user clicks the &amp;quot;Google&amp;quot; text, open a jQuery dialog window with one jQuery dialog button.  If the button is pressed, display the Google logo image (the image can be stored on your web server) on the web page, and if the dialog is closed any other way, do nothing.&lt;br /&gt;
* When the user clicks the &amp;quot;Yahoo&amp;quot; text, open a jQuery dialog window with one jQuery dialog button.  If the button is pressed, display the Yahoo logo image (the image can be stored on your web server) on the web page, and if the dialog is closed any other way, do nothing.&lt;br /&gt;
* Initially there should be no image on the page (i.e., the img should be hidden with the CSS display attribute).  After one of the two images is displayed, if the user clicks on the image, a jQuery dialog box should be opened with one dialog button, and if the button is pressed then the image should be hidden again.  Otherwise, do nothing.&lt;br /&gt;
&lt;br /&gt;
== Group Project ==&lt;br /&gt;
&lt;br /&gt;
You will work in pairs on this project.&lt;br /&gt;
&lt;br /&gt;
'''Important Reminder:''' frequently commit your work to your subversion repository as a backup!&lt;br /&gt;
&lt;br /&gt;
I forgot if I already mentioned this, but '''start early on this project!''' It will take longer than you think, I promise!&lt;br /&gt;
&lt;br /&gt;
=== Calendar ===&lt;br /&gt;
&lt;br /&gt;
Build a simple calendar that allows users to add and remove events dynamically.&lt;br /&gt;
&lt;br /&gt;
You will use JavaScript to process user interactions at the web browser, without ever refreshing the browser after the initial web page load.  You may use a JavaScript library of your choice, including jQuery.  (No extra credit will be given for ''not'' using a JavaScript library.)&lt;br /&gt;
&lt;br /&gt;
Your application should utilize AJAX to run server-side PHP scripts that query your database to save and retrieve information, including user accounts and events.&lt;br /&gt;
&lt;br /&gt;
==== Examples ====&lt;br /&gt;
&lt;br /&gt;
* https://calendar.google.com/&lt;br /&gt;
* http://www.zoho.com/calendar/&lt;br /&gt;
&lt;br /&gt;
==== Requirements ====&lt;br /&gt;
&lt;br /&gt;
* Support a month-by-month view of the calendar.&lt;br /&gt;
*: Show one month at a time, with buttons to move forward or backward.&lt;br /&gt;
*: There should be no limit to how far forward or backward the user can go.&lt;br /&gt;
* Users can register and log in to the website.&lt;br /&gt;
*: You may leverage your MySQL project code and database from last week to get started.&lt;br /&gt;
*: You may alternatively use OpenID for user authentication.  Note that you will still need a Users table in order associate calendar events with a certain OpenID.&lt;br /&gt;
* Unregistered users should see no events on the calendar.&lt;br /&gt;
* Registered users can add events.&lt;br /&gt;
*: All events should have a date and time, but do not need to have a duration.&lt;br /&gt;
*: You do ''not'' need to support recurring events (where you add an event that repeats, for example, every monday).&lt;br /&gt;
* Registered users see only events that they have added.&lt;br /&gt;
* Registered users can delete their events, but not the events of others.&lt;br /&gt;
* All user and event data should be kept in a database.&lt;br /&gt;
* At no time should the main page need to be reloaded.&lt;br /&gt;
*: User registration, user authentication, event addition, and event deletion should all be handled by JavaScript and AJAX requests to your server.&lt;br /&gt;
* Your page needs to work in the versions of Firefox and Chrome installed on the lab computers.&lt;br /&gt;
&lt;br /&gt;
'''Tip:''' Run your database schema by a TA before implementing it.&lt;br /&gt;
&lt;br /&gt;
==== Calendar Helper Library ====&lt;br /&gt;
&lt;br /&gt;
To help you get started with your calendar, we have written some JavaScript helper functions.  The code is available at:&lt;br /&gt;
* Full Version (for you to refer): http://research.engineering.wustl.edu/~todd/cse330/module4/calendar.js&lt;br /&gt;
* Minified Version (to include in your pages):http://research.engineering.wustl.edu/~todd/cse330/module4/calendar.min.js&lt;br /&gt;
&lt;br /&gt;
For example, this is how you would make a button to load the next month and show alerts containing all the days in the weeks contained by that month.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
// For our purposes, we can keep the current month in a variable in the global scope&lt;br /&gt;
var currentMonth = new Month(2012, 9); // October 2012&lt;br /&gt;
&lt;br /&gt;
// Change the month when the &amp;quot;next&amp;quot; button is pressed&lt;br /&gt;
document.getElementById(&amp;quot;next_month_btn&amp;quot;).addEventListener(&amp;quot;click&amp;quot;, function(event){&lt;br /&gt;
	currentMonth = currentMonth.nextMonth(); // Previous month would be currentMonth.prevMonth()&lt;br /&gt;
	updateCalendar(); // Whenever the month is updated, we'll need to re-render the calendar in HTML&lt;br /&gt;
	alert(&amp;quot;The new month is &amp;quot;+currentMonth.month+&amp;quot; &amp;quot;+currentMonth.year);&lt;br /&gt;
}, false);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
// This updateCalendar() function only alerts the dates in the currently specified month.  You need to write&lt;br /&gt;
// it to modify the DOM (optionally using jQuery) to display the days and weeks in the current month.&lt;br /&gt;
function updateCalendar(){&lt;br /&gt;
	var weeks = currentMonth.getWeeks();&lt;br /&gt;
	&lt;br /&gt;
	for(var w in weeks){&lt;br /&gt;
		var days = weeks[w].getDates();&lt;br /&gt;
		// days contains normal JavaScript Date objects.&lt;br /&gt;
		&lt;br /&gt;
		alert(&amp;quot;Week starting on &amp;quot;+days[0]);&lt;br /&gt;
		&lt;br /&gt;
		for(var d in days){&lt;br /&gt;
			// You can see console.log() output in your JavaScript debugging tool, like Firebug,&lt;br /&gt;
			// WebWit Inspector, or Dragonfly.&lt;br /&gt;
			console.log(days[d].toISOString());&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Important:''' JavaScript starts the months of a year, and the days of a week, at index 0.  This means that '''''in JavaScript, January is month 0, and December is month 11.'''''  Our calendar helper functions maintain this JavaScript convention.&lt;br /&gt;
&lt;br /&gt;
=== Web Security and Validation ===&lt;br /&gt;
&lt;br /&gt;
Your project needs to demonstrate that thought was put into web security and best practice.  For more information, see this week's Web Application Security guide: [[Web Application Security, Part 3]]&lt;br /&gt;
&lt;br /&gt;
In particular:&lt;br /&gt;
&lt;br /&gt;
* '''Your application needs to prevent XSS attacks.'''  The easiest way to prevent this is to continue sanitizing ''all'' of your output using '''htmlentities()'''.&lt;br /&gt;
* '''Perform precautionary measures to prevent session hijacking attacks.'''&lt;br /&gt;
*: You should specify your session cookie to be HTTP-Only.  However, for the means of this module, you need not test for user agent consistency.&lt;br /&gt;
* '''Optional:''' Validate your JavaScript code using [http://www.jshint.com/ JSHint] for 0.5 points of Creative Portion, or [http://jslint.com/ JSLint] for 0.5 points of Creative Portion.  You cannot do both.  &lt;br /&gt;
&lt;br /&gt;
You should continue the practices that you have learned in past weeks:&lt;br /&gt;
&lt;br /&gt;
* Pass tokens in forms to prevent CSRF attacks.&lt;br /&gt;
*: '''Hint:''' You will need to send your CSRF tokens in your AJAX requests.  Remember that AJAX still submits forms and runs server-side scripts, just like the vanilla forms you've been using in Modules 2 and 3.&lt;br /&gt;
* Use prepared queries to prevent SQL Injection attacks.&lt;br /&gt;
* If storing passwords in a database, always store them salted and encrypted.&lt;br /&gt;
* Your page should validate with no errors through the W3C validator.&lt;br /&gt;
&lt;br /&gt;
== Grading ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;font-size:2em; line-height:2em;&amp;quot;&amp;gt;'''Due Date: Monday, October 29th by 1pm (both individual and group)'''&amp;lt;/span&amp;gt;&lt;br /&gt;
Please see the notes at the bottom:&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
!Assignment&lt;br /&gt;
!Points&lt;br /&gt;
|-&lt;br /&gt;
|Calculator&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
|Weather Widget&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|jQuery Dialogs&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
!colspan=&amp;quot;2&amp;quot;|Group Portion:&lt;br /&gt;
|-&lt;br /&gt;
|Calendar month view correct and Move between months (without page reload)&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|User authentication and registration (without page reload)&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Add events (new event shown in calendar without page reload)&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Events added are private and other users cannot see them&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
|Delete events (event removed from calendar without page reload)&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
|-&lt;br /&gt;
|Safe from XSS and Session Hijacking&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|-&lt;br /&gt;
|Validation, CSRF, Salted Passwords, Safe SQL Queries&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Creative Portion&lt;br /&gt;
|2&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Total: 10 Points&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
**You must get written permission at least one day before the due date for your creative portion.  Failure to get written permission will result in a one point penalty(the point will be deducted when grades are entered into the gradebook, and not at your demo time).  You will lose the point even if your creative portion is amazing.  Send permission requests to Marc (see the Google Group).**&lt;br /&gt;
&lt;br /&gt;
**You will still lose one point per day late.  As the module is only worth 10 points, that results in a 10% penalty.  (Note that all modules are weighted similarly, 10 points for this module does not mean it is only worth half of the previous module).&lt;br /&gt;
&lt;br /&gt;
[[Category:Module 4]]&lt;br /&gt;
[[Category:Modules]]&lt;/div&gt;</summary>
		<author><name>Marc</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=Module_6&amp;diff=818</id>
		<title>Module 6</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=Module_6&amp;diff=818"/>
		<updated>2012-10-15T16:55:33Z</updated>

		<summary type="html">&lt;p&gt;Marc: /* Web Security and Validation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In Module 4, you will learn about JavaScript, the prevailing client-side language, and AJAX, a method for performing asynchronous updates to a web page (without refreshing the page).&lt;br /&gt;
&lt;br /&gt;
This article contains your assignments for Module 4.&lt;br /&gt;
&lt;br /&gt;
== Individual Assignments ==&lt;br /&gt;
&lt;br /&gt;
=== JavaScript Calculator ===&lt;br /&gt;
&lt;br /&gt;
In Module 2, you made a calculator using PHP.  Now you will be making one using JavaScript.&lt;br /&gt;
&lt;br /&gt;
Read the JavaScript guide first: [[Javascript and AJAX]]&lt;br /&gt;
&lt;br /&gt;
* The web page should have two input fields and a radio button group for the operation, with the 4 basic math operations represented (add,subtract,multiply,divide).&lt;br /&gt;
* The javascript should monitor all three fields and display the current result whenever the user changes any value in any field, without refreshing the page.&lt;br /&gt;
* The calculator should be completely self-contained; i.e., you should not be making any requests to any other server-side or client-side scripts or web pages after the initial page load.&lt;br /&gt;
&lt;br /&gt;
'''Tip:''' You can embed JavaScript code into an HTML document like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;
// your code here&lt;br /&gt;
&amp;lt;/script&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Tip:''' If your code isn't working the way you expect, use a JavaScript error console.  In Chrome, for example, press Ctrl-Shift-I (or Cmd-Option-I) to open the WebKit inspector.&lt;br /&gt;
&lt;br /&gt;
=== Weather Widget ===&lt;br /&gt;
&lt;br /&gt;
In this section, you will make a web page that displays the weather forecast using AJAX requests to a weather server.  You should complete this section ''without'' using JavaScript libraries like jQuery.&lt;br /&gt;
&lt;br /&gt;
# Make an empty HTML document; name it '''weather.html'''&lt;br /&gt;
#: Refer to the [[HTML and CSS]] guide for the skeleton of an HTML document&lt;br /&gt;
# Define a function in JavaScript; call it '''fetchWeather()'''.  You may write your JavaScript in an embedded script in your head tag.&lt;br /&gt;
# Inside your '''fetchWeather()''' function, make an AJAX request to the weather server.&lt;br /&gt;
#: We have a server that outputs the current weather in JSON format.  The format is documented in the [[#JSON Structure]] section below.&lt;br /&gt;
#: '''URL:''' http://research.engineering.wustl.edu/~todd/cse330/module4/weather_json.php&lt;br /&gt;
#: We kindly thank Yahoo Weather for providing us with up-to-date weather information.&lt;br /&gt;
#* '''Note:''' You normally cannot perform AJAX requests cross-domain.  We have set the &amp;lt;code&amp;gt;Access-Control-Allow-Origin&amp;lt;/code&amp;gt; header on our server to allow requests from your EC2 instances.&lt;br /&gt;
# In your callback, process the JSON and use JavaScript to manipulate the HTML DOM to display the following information on your page:&lt;br /&gt;
#* Location&lt;br /&gt;
#** City, in a &amp;lt;nowiki&amp;gt;&amp;lt;strong&amp;gt;&amp;lt;/nowiki&amp;gt; tag&lt;br /&gt;
#** State, not in any tag&lt;br /&gt;
#* Humidity&lt;br /&gt;
#* Current Temperature&lt;br /&gt;
#* Image for Tomorrow's Forecast (see [[#Weather Condition Images]] below for more information)&lt;br /&gt;
#* Image for the Day After Tomorrow's Forecast&lt;br /&gt;
# Finally, bind '''fetchWeather()''' to the DOMContentReady event so that your weather widget is automatically initialized when the page is loaded:&lt;br /&gt;
#: &amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;document.addEventListener(&amp;quot;DOMContentReady&amp;quot;, fetchWeather, false);&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Use the following HTML:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;weather&amp;quot; id=&amp;quot;weatherWidget&amp;quot;&amp;gt;&lt;br /&gt;
	&amp;lt;div class=&amp;quot;weather-loc&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
	&amp;lt;div class=&amp;quot;weather-humidity&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
	&amp;lt;div class=&amp;quot;weather-temp&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
	&amp;lt;img class=&amp;quot;weather-tomorrow&amp;quot; /&amp;gt;&lt;br /&gt;
	&amp;lt;img class=&amp;quot;weather-dayaftertomorrow&amp;quot; /&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Include the CSS file from here: http://research.engineering.wustl.edu/~todd/cse330/module4/weather.css&lt;br /&gt;
&lt;br /&gt;
When everything is working, the weather widget should look something like this:&lt;br /&gt;
&lt;br /&gt;
[[File:WeatherWidget.png]]&lt;br /&gt;
&lt;br /&gt;
'''Important:''' The widget in this section needs to work in only Firefox and Chrome.  It does '''''not''''' need to work Internet Explorer.&lt;br /&gt;
&lt;br /&gt;
==== Tips ====&lt;br /&gt;
&lt;br /&gt;
===== JSON Structure =====&lt;br /&gt;
&lt;br /&gt;
The JSON from our server looks like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
   &amp;quot;updated&amp;quot;: &amp;quot;Thu, 11 Oct 2012 5:54 pm CDT&amp;quot;,&lt;br /&gt;
   &amp;quot;location&amp;quot;: {&lt;br /&gt;
      &amp;quot;city&amp;quot;: &amp;quot;St. Louis&amp;quot;,&lt;br /&gt;
      &amp;quot;state&amp;quot;: &amp;quot;MO&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;wind&amp;quot;: {&lt;br /&gt;
      &amp;quot;chill&amp;quot;: &amp;quot;62&amp;quot;,&lt;br /&gt;
      &amp;quot;direction&amp;quot;: &amp;quot;150&amp;quot;,&lt;br /&gt;
      &amp;quot;speed&amp;quot;: &amp;quot;3 mph&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;atmosphere&amp;quot;: {&lt;br /&gt;
      &amp;quot;humidity&amp;quot;: &amp;quot;50&amp;quot;,&lt;br /&gt;
      &amp;quot;visibility&amp;quot;: &amp;quot;10&amp;quot;,&lt;br /&gt;
      &amp;quot;pressure&amp;quot;: &amp;quot;30.12 in&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;current&amp;quot;: {&lt;br /&gt;
      &amp;quot;code&amp;quot;: &amp;quot;28&amp;quot;,&lt;br /&gt;
      &amp;quot;text&amp;quot;: &amp;quot;Mostly Cloudy&amp;quot;,&lt;br /&gt;
      &amp;quot;temp&amp;quot;: &amp;quot;62°F&amp;quot;,&lt;br /&gt;
      &amp;quot;date&amp;quot;: &amp;quot;Thu, 11 Oct 2012 5:54 pm CDT&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;tomorrow&amp;quot;: {&lt;br /&gt;
      &amp;quot;code&amp;quot;: &amp;quot;29&amp;quot;,&lt;br /&gt;
      &amp;quot;text&amp;quot;: &amp;quot;Clouds Early/Clearing Late&amp;quot;,&lt;br /&gt;
      &amp;quot;low&amp;quot;: &amp;quot;45°F&amp;quot;,&lt;br /&gt;
      &amp;quot;high&amp;quot;: &amp;quot;61°F&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;dayafter&amp;quot;: {&lt;br /&gt;
      &amp;quot;code&amp;quot;: &amp;quot;30&amp;quot;,&lt;br /&gt;
      &amp;quot;text&amp;quot;: &amp;quot;Partly Cloudy&amp;quot;,&lt;br /&gt;
      &amp;quot;low&amp;quot;: &amp;quot;53°F&amp;quot;,&lt;br /&gt;
      &amp;quot;high&amp;quot;: &amp;quot;65°F&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;credit&amp;quot;: &amp;quot;http://us.rd.yahoo.com/dailynews/rss/weather/St._Louis__MO/*http://weather.yahoo.com/forecast/USMO0170_f.html&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Weather Condition Images =====&lt;br /&gt;
&lt;br /&gt;
Each day's forecast has a code.  There are images associated with these codes.&lt;br /&gt;
&lt;br /&gt;
You can get images from here: &amp;lt;nowiki&amp;gt;http://us.i1.yimg.com/us.yimg.com/i/us/nws/weather/gr/&amp;lt;/nowiki&amp;gt;'''##'''&amp;lt;nowiki&amp;gt;ds.png&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Replace the '''##''' with the forecast code.  For example, for code 32, the URL would be: http://us.i1.yimg.com/us.yimg.com/i/us/nws/weather/gr/32ds.png&lt;br /&gt;
&lt;br /&gt;
=== jQuery Dialogs ===&lt;br /&gt;
&lt;br /&gt;
Helpful Resource: [http://docs.jquery.com/Main_Page jQuery Documentation] ... Some additional tips: [[jQuery]]&lt;br /&gt;
&lt;br /&gt;
Create a simple page using jQuery dialogs.&lt;br /&gt;
&lt;br /&gt;
* Create a page that has the words &amp;quot;Google&amp;quot; and &amp;quot;Yahoo&amp;quot;.&lt;br /&gt;
* When the user clicks the &amp;quot;Google&amp;quot; text, open a jQuery dialog window with one jQuery dialog button.  If the button is pressed, display the Google logo image (the image can be stored on your web server) on the web page, and if the dialog is closed any other way, do nothing.&lt;br /&gt;
* When the user clicks the &amp;quot;Yahoo&amp;quot; text, open a jQuery dialog window with one jQuery dialog button.  If the button is pressed, display the Yahoo logo image (the image can be stored on your web server) on the web page, and if the dialog is closed any other way, do nothing.&lt;br /&gt;
* Initially there should be no image on the page (i.e., the img should be hidden with the CSS display attribute).  After one of the two images is displayed, if the user clicks on the image, a jQuery dialog box should be opened with one dialog button, and if the button is pressed then the image should be hidden again.  Otherwise, do nothing.&lt;br /&gt;
&lt;br /&gt;
== Group Project ==&lt;br /&gt;
&lt;br /&gt;
You will work in pairs on this project.&lt;br /&gt;
&lt;br /&gt;
'''Important Reminder:''' frequently commit your work to your subversion repository as a backup!&lt;br /&gt;
&lt;br /&gt;
I forgot if I already mentioned this, but '''start early on this project!''' It will take longer than you think, I promise!&lt;br /&gt;
&lt;br /&gt;
=== Calendar ===&lt;br /&gt;
&lt;br /&gt;
Build a simple calendar that allows users to add and remove events dynamically.&lt;br /&gt;
&lt;br /&gt;
You will use JavaScript to process user interactions at the web browser, without ever refreshing the browser after the initial web page load.  You may use a JavaScript library of your choice, including jQuery.  (No extra credit will be given for ''not'' using a JavaScript library.)&lt;br /&gt;
&lt;br /&gt;
Your application should utilize AJAX to run server-side PHP scripts that query your database to save and retrieve information, including user accounts and events.&lt;br /&gt;
&lt;br /&gt;
==== Examples ====&lt;br /&gt;
&lt;br /&gt;
* https://calendar.google.com/&lt;br /&gt;
* http://www.zoho.com/calendar/&lt;br /&gt;
&lt;br /&gt;
==== Requirements ====&lt;br /&gt;
&lt;br /&gt;
* Support a month-by-month view of the calendar.&lt;br /&gt;
*: Show one month at a time, with buttons to move forward or backward.&lt;br /&gt;
*: There should be no limit to how far forward or backward the user can go.&lt;br /&gt;
* Users can register and log in to the website.&lt;br /&gt;
*: You may leverage your MySQL project code and database from last week to get started.&lt;br /&gt;
*: You may alternatively use OpenID for user authentication.  Note that you will still need a Users table in order associate calendar events with a certain OpenID.&lt;br /&gt;
* Unregistered users should see no events on the calendar.&lt;br /&gt;
* Registered users can add events.&lt;br /&gt;
*: All events should have a date and time, but do not need to have a duration.&lt;br /&gt;
*: You do ''not'' need to support recurring events (where you add an event that repeats, for example, every monday).&lt;br /&gt;
* Registered users see only events that they have added.&lt;br /&gt;
* Registered users can delete their events, but not the events of others.&lt;br /&gt;
* All user and event data should be kept in a database.&lt;br /&gt;
* At no time should the main page need to be reloaded.&lt;br /&gt;
*: User registration, user authentication, event addition, and event deletion should all be handled by JavaScript and AJAX requests to your server.&lt;br /&gt;
* Your page needs to work in the versions of Firefox and Chrome installed on the lab computers.&lt;br /&gt;
&lt;br /&gt;
'''Tip:''' Run your database schema by a TA before implementing it.&lt;br /&gt;
&lt;br /&gt;
==== Calendar Helper Library ====&lt;br /&gt;
&lt;br /&gt;
To help you get started with your calendar, we have written some JavaScript helper functions.  The code is available at:&lt;br /&gt;
* Full Version (for you to refer): http://research.engineering.wustl.edu/~todd/cse330/module4/calendar.js&lt;br /&gt;
* Minified Version (to include in your pages):http://research.engineering.wustl.edu/~todd/cse330/module4/calendar.min.js&lt;br /&gt;
&lt;br /&gt;
For example, this is how you would make a button to load the next month and show alerts containing all the days in the weeks contained by that month.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
// For our purposes, we can keep the current month in a variable in the global scope&lt;br /&gt;
var currentMonth = new Month(2012, 9); // October 2012&lt;br /&gt;
&lt;br /&gt;
// Change the month when the &amp;quot;next&amp;quot; button is pressed&lt;br /&gt;
document.getElementById(&amp;quot;next_month_btn&amp;quot;).addEventListener(&amp;quot;click&amp;quot;, function(event){&lt;br /&gt;
	currentMonth = currentMonth.nextMonth(); // Previous month would be currentMonth.prevMonth()&lt;br /&gt;
	updateCalendar(); // Whenever the month is updated, we'll need to re-render the calendar in HTML&lt;br /&gt;
	alert(&amp;quot;The new month is &amp;quot;+currentMonth.month+&amp;quot; &amp;quot;+currentMonth.year);&lt;br /&gt;
}, false);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
// This updateCalendar() function only alerts the dates in the currently specified month.  You need to write&lt;br /&gt;
// it to modify the DOM (optionally using jQuery) to display the days and weeks in the current month.&lt;br /&gt;
function updateCalendar(){&lt;br /&gt;
	var weeks = currentMonth.getWeeks();&lt;br /&gt;
	&lt;br /&gt;
	for(var w in weeks){&lt;br /&gt;
		var days = weeks[w].getDates();&lt;br /&gt;
		// days contains normal JavaScript Date objects.&lt;br /&gt;
		&lt;br /&gt;
		alert(&amp;quot;Week starting on &amp;quot;+days[0]);&lt;br /&gt;
		&lt;br /&gt;
		for(var d in days){&lt;br /&gt;
			// You can see console.log() output in your JavaScript debugging tool, like Firebug,&lt;br /&gt;
			// WebWit Inspector, or Dragonfly.&lt;br /&gt;
			console.log(days[d].toISOString());&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Important:''' JavaScript starts the months of a year, and the days of a week, at index 0.  This means that '''''in JavaScript, January is month 0, and December is month 11.'''''  Our calendar helper functions maintain this JavaScript convention.&lt;br /&gt;
&lt;br /&gt;
=== Web Security and Validation ===&lt;br /&gt;
&lt;br /&gt;
Your project needs to demonstrate that thought was put into web security and best practice.  For more information, see this week's Web Application Security guide: [[Web Application Security, Part 3]]&lt;br /&gt;
&lt;br /&gt;
In particular:&lt;br /&gt;
&lt;br /&gt;
* '''Your application needs to prevent XSS attacks.'''  The easiest way to prevent this is to continue sanitizing ''all'' of your output using '''htmlentities()'''.&lt;br /&gt;
* '''Perform precautionary measures to prevent session hijacking attacks.'''&lt;br /&gt;
*: You should specify your session cookie to be HTTP-Only.  However, for the means of this module, you need not test for user agent consistency.&lt;br /&gt;
* '''Optional:''' Validate your JavaScript code using [http://www.jshint.com/ JSHint] for 0.5 points of Creative Portion, or [http://jslint.com/ JSLint] for 0.5 points of Creative Portion.  You cannot do both.  &lt;br /&gt;
&lt;br /&gt;
You should continue the practices that you have learned in past weeks:&lt;br /&gt;
&lt;br /&gt;
* Pass tokens in forms to prevent CSRF attacks.&lt;br /&gt;
*: '''Hint:''' You will need to send your CSRF tokens in your AJAX requests.  Remember that AJAX still submits forms and runs server-side scripts, just like the vanilla forms you've been using in Modules 2 and 3.&lt;br /&gt;
* Use prepared queries to prevent SQL Injection attacks.&lt;br /&gt;
* If storing passwords in a database, always store them salted and encrypted.&lt;br /&gt;
* Your page should validate with no errors through the W3C validator.&lt;br /&gt;
&lt;br /&gt;
== Grading ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;font-size:2em; line-height:2em;&amp;quot;&amp;gt;'''Due Date: Monday, October 29th by 1pm (both individual and group)'''&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
!Assignment&lt;br /&gt;
!Points&lt;br /&gt;
|-&lt;br /&gt;
|Calculator&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
|Weather Widget&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|jQuery Dialogs&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
!colspan=&amp;quot;2&amp;quot;|Group Portion:&lt;br /&gt;
|-&lt;br /&gt;
|Calendar month view correct and Move between months (without page reload)&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|User authentication and registration (without page reload)&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Add events (new event shown in calendar without page reload)&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Events added are private and other users cannot see them&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
|Delete events (event removed from calendar without page reload)&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
|-&lt;br /&gt;
|Safe from XSS and Session Hijacking&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|-&lt;br /&gt;
|Validation, CSRF, Salted Passwords, Safe SQL Queries&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Creative Portion&lt;br /&gt;
|2&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Total: 10 Points&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You must get written permission at least one day before the due date for your creative portion.  Failure to get written permission will result in one point maximum.  You will be asked to provide proof of approval.&lt;br /&gt;
Send permission requests to Marc.&lt;br /&gt;
&lt;br /&gt;
[[Category:Module 4]]&lt;br /&gt;
[[Category:Modules]]&lt;/div&gt;</summary>
		<author><name>Marc</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=Module_6&amp;diff=807</id>
		<title>Module 6</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=Module_6&amp;diff=807"/>
		<updated>2012-10-14T04:04:39Z</updated>

		<summary type="html">&lt;p&gt;Marc: /* Grading */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In Module 4, you will learn about JavaScript, the prevailing client-side language, and AJAX, a method for performing asynchronous updates to a web page (without refreshing the page).&lt;br /&gt;
&lt;br /&gt;
This article contains your assignments for Module 4.&lt;br /&gt;
&lt;br /&gt;
== Individual Assignments ==&lt;br /&gt;
&lt;br /&gt;
=== JavaScript Calculator ===&lt;br /&gt;
&lt;br /&gt;
In Module 2, you made a calculator using PHP.  Now you will be making one using JavaScript.&lt;br /&gt;
&lt;br /&gt;
Read the JavaScript guide first: [[Javascript and AJAX]]&lt;br /&gt;
&lt;br /&gt;
* The web page should have two input fields and a radio button group for the operation, with the 4 basic math operations represented (add,subtract,multiply,divide).&lt;br /&gt;
* The javascript should monitor all three fields and display the current result whenever the user changes any value in any field, without refreshing the page.&lt;br /&gt;
* The calculator should be completely self-contained; i.e., you should not be making any requests to any other server-side or client-side scripts or web pages after the initial page load.&lt;br /&gt;
&lt;br /&gt;
'''Tip:''' You can embed JavaScript code into an HTML document like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;
// your code here&lt;br /&gt;
&amp;lt;/script&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Tip:''' If your code isn't working the way you expect, use a JavaScript error console.  In Chrome, for example, press Ctrl-Shift-I (or Cmd-Option-I) to open the WebKit inspector.&lt;br /&gt;
&lt;br /&gt;
=== Weather Widget ===&lt;br /&gt;
&lt;br /&gt;
In this section, you will make a web page that displays the weather forecast using AJAX requests to a weather server.  You should complete this section ''without'' using JavaScript libraries like jQuery.&lt;br /&gt;
&lt;br /&gt;
# Make an empty HTML document; name it '''weather.html'''&lt;br /&gt;
#: Refer to the [[HTML and CSS]] guide for the skeleton of an HTML document&lt;br /&gt;
# Define a function in JavaScript; call it '''fetchWeather()'''.  You may write your JavaScript in an embedded script in your head tag.&lt;br /&gt;
# Inside your '''fetchWeather()''' function, make an AJAX request to the weather server.&lt;br /&gt;
#: We have a server that outputs the current weather in JSON format.  The format is documented in the [[#JSON Structure]] section below.&lt;br /&gt;
#: '''URL:''' http://cloud.sffc1.com/wustl/weather_json.php&lt;br /&gt;
#: We kindly thank Yahoo Weather for providing us with up-to-date weather information.&lt;br /&gt;
#* '''Note:''' You normally cannot perform AJAX requests cross-domain.  We have set the &amp;lt;code&amp;gt;Access-Control-Allow-Origin&amp;lt;/code&amp;gt; header on our server to allow requests from your EC2 instances.&lt;br /&gt;
# In your callback, process the JSON and use JavaScript to manipulate the HTML DOM to display the following information on your page:&lt;br /&gt;
#* Location&lt;br /&gt;
#** City, in a &amp;lt;nowiki&amp;gt;&amp;lt;strong&amp;gt;&amp;lt;/nowiki&amp;gt; tag&lt;br /&gt;
#** State, not in any tag&lt;br /&gt;
#* Humidity&lt;br /&gt;
#* Current Temperature&lt;br /&gt;
#* Image for Tomorrow's Forecast (see [[#Weather Condition Images]] below for more information)&lt;br /&gt;
#* Image for the Day After Tomorrow's Forecast&lt;br /&gt;
# Finally, bind '''fetchWeather()''' to the DOMContentReady event so that your weather widget is automatically initialized when the page is loaded:&lt;br /&gt;
#: &amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;document.addEventListener(&amp;quot;DOMContentReady&amp;quot;, fetchWeather, false);&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Use the following HTML:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;weather&amp;quot; id=&amp;quot;weatherWidget&amp;quot;&amp;gt;&lt;br /&gt;
	&amp;lt;div class=&amp;quot;weather-loc&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
	&amp;lt;div class=&amp;quot;weather-humidity&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
	&amp;lt;div class=&amp;quot;weather-temp&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
	&amp;lt;img class=&amp;quot;weather-tomorrow&amp;quot; /&amp;gt;&lt;br /&gt;
	&amp;lt;img class=&amp;quot;weather-dayaftertomorrow&amp;quot; /&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Include the CSS file from here: http://cloud.sffc1.com/wustl/weather.css&lt;br /&gt;
&lt;br /&gt;
When everything is working, the weather widget should look something like this:&lt;br /&gt;
&lt;br /&gt;
[[File:WeatherWidget.png]]&lt;br /&gt;
&lt;br /&gt;
'''Important:''' The widget in this section needs to work in only Firefox and Chrome.  It does '''''not''''' need to work Internet Explorer.&lt;br /&gt;
&lt;br /&gt;
==== Tips ====&lt;br /&gt;
&lt;br /&gt;
===== JSON Structure =====&lt;br /&gt;
&lt;br /&gt;
The JSON from our server looks like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
   &amp;quot;updated&amp;quot;: &amp;quot;Thu, 11 Oct 2012 5:54 pm CDT&amp;quot;,&lt;br /&gt;
   &amp;quot;location&amp;quot;: {&lt;br /&gt;
      &amp;quot;city&amp;quot;: &amp;quot;St. Louis&amp;quot;,&lt;br /&gt;
      &amp;quot;state&amp;quot;: &amp;quot;MO&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;wind&amp;quot;: {&lt;br /&gt;
      &amp;quot;chill&amp;quot;: &amp;quot;62&amp;quot;,&lt;br /&gt;
      &amp;quot;direction&amp;quot;: &amp;quot;150&amp;quot;,&lt;br /&gt;
      &amp;quot;speed&amp;quot;: &amp;quot;3 mph&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;atmosphere&amp;quot;: {&lt;br /&gt;
      &amp;quot;humidity&amp;quot;: &amp;quot;50&amp;quot;,&lt;br /&gt;
      &amp;quot;visibility&amp;quot;: &amp;quot;10&amp;quot;,&lt;br /&gt;
      &amp;quot;pressure&amp;quot;: &amp;quot;30.12 in&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;current&amp;quot;: {&lt;br /&gt;
      &amp;quot;code&amp;quot;: &amp;quot;28&amp;quot;,&lt;br /&gt;
      &amp;quot;text&amp;quot;: &amp;quot;Mostly Cloudy&amp;quot;,&lt;br /&gt;
      &amp;quot;temp&amp;quot;: &amp;quot;62°F&amp;quot;,&lt;br /&gt;
      &amp;quot;date&amp;quot;: &amp;quot;Thu, 11 Oct 2012 5:54 pm CDT&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;tomorrow&amp;quot;: {&lt;br /&gt;
      &amp;quot;code&amp;quot;: &amp;quot;29&amp;quot;,&lt;br /&gt;
      &amp;quot;text&amp;quot;: &amp;quot;Clouds Early/Clearing Late&amp;quot;,&lt;br /&gt;
      &amp;quot;low&amp;quot;: &amp;quot;45°F&amp;quot;,&lt;br /&gt;
      &amp;quot;high&amp;quot;: &amp;quot;61°F&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;dayafter&amp;quot;: {&lt;br /&gt;
      &amp;quot;code&amp;quot;: &amp;quot;30&amp;quot;,&lt;br /&gt;
      &amp;quot;text&amp;quot;: &amp;quot;Partly Cloudy&amp;quot;,&lt;br /&gt;
      &amp;quot;low&amp;quot;: &amp;quot;53°F&amp;quot;,&lt;br /&gt;
      &amp;quot;high&amp;quot;: &amp;quot;65°F&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;credit&amp;quot;: &amp;quot;http://us.rd.yahoo.com/dailynews/rss/weather/St._Louis__MO/*http://weather.yahoo.com/forecast/USMO0170_f.html&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Weather Condition Images =====&lt;br /&gt;
&lt;br /&gt;
Each day's forecast has a code.  There are images associated with these codes.&lt;br /&gt;
&lt;br /&gt;
You can get images from here: &amp;lt;nowiki&amp;gt;http://us.i1.yimg.com/us.yimg.com/i/us/nws/weather/gr/&amp;lt;/nowiki&amp;gt;'''##'''&amp;lt;nowiki&amp;gt;ds.png&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Replace the '''##''' with the forecast code.  For example, for code 32, the URL would be: http://us.i1.yimg.com/us.yimg.com/i/us/nws/weather/gr/32ds.png&lt;br /&gt;
&lt;br /&gt;
=== jQuery Dialogs ===&lt;br /&gt;
&lt;br /&gt;
Helpful Resource: [http://docs.jquery.com/Main_Page jQuery Documentation] ... Some additional tips: [[jQuery]]&lt;br /&gt;
&lt;br /&gt;
Create a simple page using jQuery dialogs.&lt;br /&gt;
&lt;br /&gt;
* Create a page that has the words &amp;quot;Google&amp;quot; and &amp;quot;Yahoo&amp;quot;.&lt;br /&gt;
* When the user clicks the &amp;quot;Google&amp;quot; text, open a jQuery dialog window with one jQuery dialog button.  If the button is pressed, display the Google logo image (the image can be stored on your web server) on the web page, and if the dialog is closed any other way, do nothing.&lt;br /&gt;
* When the user clicks the &amp;quot;Yahoo&amp;quot; text, open a jQuery dialog window with one jQuery dialog button.  If the button is pressed, display the Yahoo logo image (the image can be stored on your web server) on the web page, and if the dialog is closed any other way, do nothing.&lt;br /&gt;
* Initially there should be no image on the page (i.e., the img should be hidden with the CSS display attribute).  After one of the two images is displayed, if the user clicks on the image, a jQuery dialog box should be opened with one dialog button, and if the button is pressed then the image should be hidden again.  Otherwise, do nothing.&lt;br /&gt;
&lt;br /&gt;
== Group Project ==&lt;br /&gt;
&lt;br /&gt;
You will work in pairs on this project.&lt;br /&gt;
&lt;br /&gt;
'''Important Reminder:''' frequently commit your work to your subversion repository as a backup!&lt;br /&gt;
&lt;br /&gt;
I forgot if I already mentioned this, but '''start early on this project!''' It will take longer than you think, I promise!&lt;br /&gt;
&lt;br /&gt;
=== Calendar ===&lt;br /&gt;
&lt;br /&gt;
Build a simple calendar that allows users to add and remove events dynamically.&lt;br /&gt;
&lt;br /&gt;
You will use JavaScript to process user interactions at the web browser, without ever refreshing the browser after the initial web page load.  You may use a JavaScript library of your choice, including jQuery.  (No extra credit will be given for ''not'' using a JavaScript library.)&lt;br /&gt;
&lt;br /&gt;
Your application should utilize AJAX to run server-side PHP scripts that query your database to save and retrieve information, including user accounts and events.&lt;br /&gt;
&lt;br /&gt;
==== Examples ====&lt;br /&gt;
&lt;br /&gt;
* https://calendar.google.com/&lt;br /&gt;
* http://www.zoho.com/calendar/&lt;br /&gt;
&lt;br /&gt;
==== Requirements ====&lt;br /&gt;
&lt;br /&gt;
* Support a month-by-month view of the calendar.&lt;br /&gt;
*: Show one month at a time, with buttons to move forward or backward.&lt;br /&gt;
*: There should be no limit to how far forward or backward the user can go.&lt;br /&gt;
* Users can register and log in to the website.&lt;br /&gt;
*: You may leverage your MySQL project code and database from last week to get started.&lt;br /&gt;
*: You may alternatively use OpenID for user authentication.  Note that you will still need a Users table in order associate calendar events with a certain OpenID.&lt;br /&gt;
* Unregistered users should see no events on the calendar.&lt;br /&gt;
* Registered users can add events.&lt;br /&gt;
*: All events should have a date and time, but do not need to have a duration.&lt;br /&gt;
*: You do ''not'' need to support recurring events (where you add an event that repeats, for example, every monday).&lt;br /&gt;
* Registered users see only events that they have added.&lt;br /&gt;
* Registered users can delete their events, but not the events of others.&lt;br /&gt;
* All user and event data should be kept in a database.&lt;br /&gt;
* At no time should the main page need to be reloaded.&lt;br /&gt;
*: User registration, user authentication, event addition, and event deletion should all be handled by JavaScript and AJAX requests to your server.&lt;br /&gt;
* Your page needs to work in the versions of Firefox and Chrome installed on the lab computers.&lt;br /&gt;
&lt;br /&gt;
'''Tip:''' Run your database schema by a TA before implementing it.&lt;br /&gt;
&lt;br /&gt;
==== Calendar Helper Library ====&lt;br /&gt;
&lt;br /&gt;
To help you get started with your calendar, we have written some JavaScript helper functions.  The code is available at:&lt;br /&gt;
* Full Version (for you to refer): http://cloud.sffc1.com/wustl/calendar.js&lt;br /&gt;
* Minified Version (to include in your pages): http://cloud.sffc1.com/wustl/calendar.min.js&lt;br /&gt;
&lt;br /&gt;
For example, this is how you would make a button to load the next month and show alerts containing all the days in the weeks contained by that month.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
// For our purposes, we can keep the current month in a variable in the global scope&lt;br /&gt;
var currentMonth = new Month(2012, 9); // October 2012&lt;br /&gt;
&lt;br /&gt;
// Change the month when the &amp;quot;next&amp;quot; button is pressed&lt;br /&gt;
document.getElementById(&amp;quot;next_month_btn&amp;quot;).addEventListener(&amp;quot;click&amp;quot;, function(event){&lt;br /&gt;
	currentMonth = currentMonth.nextMonth(); // Previous month would be currentMonth.prevMonth()&lt;br /&gt;
	updateCalendar(); // Whenever the month is updated, we'll need to re-render the calendar in HTML&lt;br /&gt;
	alert(&amp;quot;The new month is &amp;quot;+currentMonth.month+&amp;quot; &amp;quot;+currentMonth.year);&lt;br /&gt;
}, false);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
// This updateCalendar() function only alerts the dates in the currently specified month.  You need to write&lt;br /&gt;
// it to modify the DOM (optionally using jQuery) to display the days and weeks in the current month.&lt;br /&gt;
function updateCalendar(){&lt;br /&gt;
	var weeks = currentMonth.getWeeks();&lt;br /&gt;
	&lt;br /&gt;
	for(var w in weeks){&lt;br /&gt;
		var days = weeks[w].getDates();&lt;br /&gt;
		// days contains normal JavaScript Date objects.&lt;br /&gt;
		&lt;br /&gt;
		alert(&amp;quot;Week starting on &amp;quot;+days[0]);&lt;br /&gt;
		&lt;br /&gt;
		for(var d in days){&lt;br /&gt;
			// You can see console.log() output in your JavaScript debugging tool, like Firebug,&lt;br /&gt;
			// WebWit Inspector, or Dragonfly.&lt;br /&gt;
			console.log(days[d].toISOString());&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Important:''' JavaScript starts the months of a year, and the days of a week, at index 0.  This means that '''''in JavaScript, January is month 0, and December is month 11.'''''  Our calendar helper functions maintain this JavaScript convention.&lt;br /&gt;
&lt;br /&gt;
=== Web Security and Validation ===&lt;br /&gt;
&lt;br /&gt;
Your project needs to demonstrate that thought was put into web security and best practice.  For more information, see this week's Web Application Security guide: [[Web Application Security, Part 3]]&lt;br /&gt;
&lt;br /&gt;
In particular:&lt;br /&gt;
&lt;br /&gt;
* '''Your application needs to prevent XSS attacks.'''  The easiest way to prevent this is to continue sanitizing ''all'' of your output using '''htmlentities()'''.&lt;br /&gt;
* '''Perform precautionary measures to prevent session hijacking attacks.'''&lt;br /&gt;
*: You should specify your session cookie to be HTTP-Only.  However, for the means of this module, you need not test for user agent consistency.&lt;br /&gt;
* Validate your JavaScript code using [http://www.jshint.com/ JSHint]&lt;br /&gt;
&lt;br /&gt;
You should continue the practices that you have learned in past weeks:&lt;br /&gt;
&lt;br /&gt;
* Pass tokens in forms to prevent CSRF attacks&lt;br /&gt;
* Use prepared queries to prevent SQL Injection attacks&lt;br /&gt;
* If storing passwords in a database, always store them encrypted&lt;br /&gt;
* Your page should validate with no errors through the W3C validator.&lt;br /&gt;
&lt;br /&gt;
== Grading ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;font-size:2em; line-height:2em;&amp;quot;&amp;gt;'''Due Date: Monday, October 29th by 1pm (both individual and group)'''&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
!Assignment&lt;br /&gt;
!Points&lt;br /&gt;
|-&lt;br /&gt;
|Calculator&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
|Weather Widget&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|jQuery Dialogs&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
!colspan=&amp;quot;2&amp;quot;|Group Portion:&lt;br /&gt;
|-&lt;br /&gt;
|Calendar month view correct and Move between months (without page reload)&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|User authentication and registration (without page reload)&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Add events (new event shown in calendar without page reload)&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Events added are private and other users cannot see them&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
|Delete events (event removed from calendar without page reload)&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
|-&lt;br /&gt;
|Safe from XSS and Session Hijacking&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|-&lt;br /&gt;
|Validation, CSRF, Salted Passwords, Safe SQL Queries, JSHint&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Creative Portion&lt;br /&gt;
|2&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Total: 10 Points&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You must get written permission at least one day before the due date for your creative portion.  Failure to get written permission will result in one point maximum.  You will be asked to provide proof of approval.&lt;br /&gt;
Send permission requests to Marc.&lt;br /&gt;
&lt;br /&gt;
[[Category:Module 4]]&lt;br /&gt;
[[Category:Modules]]&lt;/div&gt;</summary>
		<author><name>Marc</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=Module_6&amp;diff=806</id>
		<title>Module 6</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=Module_6&amp;diff=806"/>
		<updated>2012-10-14T04:04:24Z</updated>

		<summary type="html">&lt;p&gt;Marc: /* Grading */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In Module 4, you will learn about JavaScript, the prevailing client-side language, and AJAX, a method for performing asynchronous updates to a web page (without refreshing the page).&lt;br /&gt;
&lt;br /&gt;
This article contains your assignments for Module 4.&lt;br /&gt;
&lt;br /&gt;
== Individual Assignments ==&lt;br /&gt;
&lt;br /&gt;
=== JavaScript Calculator ===&lt;br /&gt;
&lt;br /&gt;
In Module 2, you made a calculator using PHP.  Now you will be making one using JavaScript.&lt;br /&gt;
&lt;br /&gt;
Read the JavaScript guide first: [[Javascript and AJAX]]&lt;br /&gt;
&lt;br /&gt;
* The web page should have two input fields and a radio button group for the operation, with the 4 basic math operations represented (add,subtract,multiply,divide).&lt;br /&gt;
* The javascript should monitor all three fields and display the current result whenever the user changes any value in any field, without refreshing the page.&lt;br /&gt;
* The calculator should be completely self-contained; i.e., you should not be making any requests to any other server-side or client-side scripts or web pages after the initial page load.&lt;br /&gt;
&lt;br /&gt;
'''Tip:''' You can embed JavaScript code into an HTML document like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;
// your code here&lt;br /&gt;
&amp;lt;/script&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Tip:''' If your code isn't working the way you expect, use a JavaScript error console.  In Chrome, for example, press Ctrl-Shift-I (or Cmd-Option-I) to open the WebKit inspector.&lt;br /&gt;
&lt;br /&gt;
=== Weather Widget ===&lt;br /&gt;
&lt;br /&gt;
In this section, you will make a web page that displays the weather forecast using AJAX requests to a weather server.  You should complete this section ''without'' using JavaScript libraries like jQuery.&lt;br /&gt;
&lt;br /&gt;
# Make an empty HTML document; name it '''weather.html'''&lt;br /&gt;
#: Refer to the [[HTML and CSS]] guide for the skeleton of an HTML document&lt;br /&gt;
# Define a function in JavaScript; call it '''fetchWeather()'''.  You may write your JavaScript in an embedded script in your head tag.&lt;br /&gt;
# Inside your '''fetchWeather()''' function, make an AJAX request to the weather server.&lt;br /&gt;
#: We have a server that outputs the current weather in JSON format.  The format is documented in the [[#JSON Structure]] section below.&lt;br /&gt;
#: '''URL:''' http://cloud.sffc1.com/wustl/weather_json.php&lt;br /&gt;
#: We kindly thank Yahoo Weather for providing us with up-to-date weather information.&lt;br /&gt;
#* '''Note:''' You normally cannot perform AJAX requests cross-domain.  We have set the &amp;lt;code&amp;gt;Access-Control-Allow-Origin&amp;lt;/code&amp;gt; header on our server to allow requests from your EC2 instances.&lt;br /&gt;
# In your callback, process the JSON and use JavaScript to manipulate the HTML DOM to display the following information on your page:&lt;br /&gt;
#* Location&lt;br /&gt;
#** City, in a &amp;lt;nowiki&amp;gt;&amp;lt;strong&amp;gt;&amp;lt;/nowiki&amp;gt; tag&lt;br /&gt;
#** State, not in any tag&lt;br /&gt;
#* Humidity&lt;br /&gt;
#* Current Temperature&lt;br /&gt;
#* Image for Tomorrow's Forecast (see [[#Weather Condition Images]] below for more information)&lt;br /&gt;
#* Image for the Day After Tomorrow's Forecast&lt;br /&gt;
# Finally, bind '''fetchWeather()''' to the DOMContentReady event so that your weather widget is automatically initialized when the page is loaded:&lt;br /&gt;
#: &amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;document.addEventListener(&amp;quot;DOMContentReady&amp;quot;, fetchWeather, false);&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Use the following HTML:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;weather&amp;quot; id=&amp;quot;weatherWidget&amp;quot;&amp;gt;&lt;br /&gt;
	&amp;lt;div class=&amp;quot;weather-loc&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
	&amp;lt;div class=&amp;quot;weather-humidity&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
	&amp;lt;div class=&amp;quot;weather-temp&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
	&amp;lt;img class=&amp;quot;weather-tomorrow&amp;quot; /&amp;gt;&lt;br /&gt;
	&amp;lt;img class=&amp;quot;weather-dayaftertomorrow&amp;quot; /&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Include the CSS file from here: http://cloud.sffc1.com/wustl/weather.css&lt;br /&gt;
&lt;br /&gt;
When everything is working, the weather widget should look something like this:&lt;br /&gt;
&lt;br /&gt;
[[File:WeatherWidget.png]]&lt;br /&gt;
&lt;br /&gt;
'''Important:''' The widget in this section needs to work in only Firefox and Chrome.  It does '''''not''''' need to work Internet Explorer.&lt;br /&gt;
&lt;br /&gt;
==== Tips ====&lt;br /&gt;
&lt;br /&gt;
===== JSON Structure =====&lt;br /&gt;
&lt;br /&gt;
The JSON from our server looks like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
   &amp;quot;updated&amp;quot;: &amp;quot;Thu, 11 Oct 2012 5:54 pm CDT&amp;quot;,&lt;br /&gt;
   &amp;quot;location&amp;quot;: {&lt;br /&gt;
      &amp;quot;city&amp;quot;: &amp;quot;St. Louis&amp;quot;,&lt;br /&gt;
      &amp;quot;state&amp;quot;: &amp;quot;MO&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;wind&amp;quot;: {&lt;br /&gt;
      &amp;quot;chill&amp;quot;: &amp;quot;62&amp;quot;,&lt;br /&gt;
      &amp;quot;direction&amp;quot;: &amp;quot;150&amp;quot;,&lt;br /&gt;
      &amp;quot;speed&amp;quot;: &amp;quot;3 mph&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;atmosphere&amp;quot;: {&lt;br /&gt;
      &amp;quot;humidity&amp;quot;: &amp;quot;50&amp;quot;,&lt;br /&gt;
      &amp;quot;visibility&amp;quot;: &amp;quot;10&amp;quot;,&lt;br /&gt;
      &amp;quot;pressure&amp;quot;: &amp;quot;30.12 in&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;current&amp;quot;: {&lt;br /&gt;
      &amp;quot;code&amp;quot;: &amp;quot;28&amp;quot;,&lt;br /&gt;
      &amp;quot;text&amp;quot;: &amp;quot;Mostly Cloudy&amp;quot;,&lt;br /&gt;
      &amp;quot;temp&amp;quot;: &amp;quot;62°F&amp;quot;,&lt;br /&gt;
      &amp;quot;date&amp;quot;: &amp;quot;Thu, 11 Oct 2012 5:54 pm CDT&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;tomorrow&amp;quot;: {&lt;br /&gt;
      &amp;quot;code&amp;quot;: &amp;quot;29&amp;quot;,&lt;br /&gt;
      &amp;quot;text&amp;quot;: &amp;quot;Clouds Early/Clearing Late&amp;quot;,&lt;br /&gt;
      &amp;quot;low&amp;quot;: &amp;quot;45°F&amp;quot;,&lt;br /&gt;
      &amp;quot;high&amp;quot;: &amp;quot;61°F&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;dayafter&amp;quot;: {&lt;br /&gt;
      &amp;quot;code&amp;quot;: &amp;quot;30&amp;quot;,&lt;br /&gt;
      &amp;quot;text&amp;quot;: &amp;quot;Partly Cloudy&amp;quot;,&lt;br /&gt;
      &amp;quot;low&amp;quot;: &amp;quot;53°F&amp;quot;,&lt;br /&gt;
      &amp;quot;high&amp;quot;: &amp;quot;65°F&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;credit&amp;quot;: &amp;quot;http://us.rd.yahoo.com/dailynews/rss/weather/St._Louis__MO/*http://weather.yahoo.com/forecast/USMO0170_f.html&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Weather Condition Images =====&lt;br /&gt;
&lt;br /&gt;
Each day's forecast has a code.  There are images associated with these codes.&lt;br /&gt;
&lt;br /&gt;
You can get images from here: &amp;lt;nowiki&amp;gt;http://us.i1.yimg.com/us.yimg.com/i/us/nws/weather/gr/&amp;lt;/nowiki&amp;gt;'''##'''&amp;lt;nowiki&amp;gt;ds.png&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Replace the '''##''' with the forecast code.  For example, for code 32, the URL would be: http://us.i1.yimg.com/us.yimg.com/i/us/nws/weather/gr/32ds.png&lt;br /&gt;
&lt;br /&gt;
=== jQuery Dialogs ===&lt;br /&gt;
&lt;br /&gt;
Helpful Resource: [http://docs.jquery.com/Main_Page jQuery Documentation] ... Some additional tips: [[jQuery]]&lt;br /&gt;
&lt;br /&gt;
Create a simple page using jQuery dialogs.&lt;br /&gt;
&lt;br /&gt;
* Create a page that has the words &amp;quot;Google&amp;quot; and &amp;quot;Yahoo&amp;quot;.&lt;br /&gt;
* When the user clicks the &amp;quot;Google&amp;quot; text, open a jQuery dialog window with one jQuery dialog button.  If the button is pressed, display the Google logo image (the image can be stored on your web server) on the web page, and if the dialog is closed any other way, do nothing.&lt;br /&gt;
* When the user clicks the &amp;quot;Yahoo&amp;quot; text, open a jQuery dialog window with one jQuery dialog button.  If the button is pressed, display the Yahoo logo image (the image can be stored on your web server) on the web page, and if the dialog is closed any other way, do nothing.&lt;br /&gt;
* Initially there should be no image on the page (i.e., the img should be hidden with the CSS display attribute).  After one of the two images is displayed, if the user clicks on the image, a jQuery dialog box should be opened with one dialog button, and if the button is pressed then the image should be hidden again.  Otherwise, do nothing.&lt;br /&gt;
&lt;br /&gt;
== Group Project ==&lt;br /&gt;
&lt;br /&gt;
You will work in pairs on this project.&lt;br /&gt;
&lt;br /&gt;
'''Important Reminder:''' frequently commit your work to your subversion repository as a backup!&lt;br /&gt;
&lt;br /&gt;
I forgot if I already mentioned this, but '''start early on this project!''' It will take longer than you think, I promise!&lt;br /&gt;
&lt;br /&gt;
=== Calendar ===&lt;br /&gt;
&lt;br /&gt;
Build a simple calendar that allows users to add and remove events dynamically.&lt;br /&gt;
&lt;br /&gt;
You will use JavaScript to process user interactions at the web browser, without ever refreshing the browser after the initial web page load.  You may use a JavaScript library of your choice, including jQuery.  (No extra credit will be given for ''not'' using a JavaScript library.)&lt;br /&gt;
&lt;br /&gt;
Your application should utilize AJAX to run server-side PHP scripts that query your database to save and retrieve information, including user accounts and events.&lt;br /&gt;
&lt;br /&gt;
==== Examples ====&lt;br /&gt;
&lt;br /&gt;
* https://calendar.google.com/&lt;br /&gt;
* http://www.zoho.com/calendar/&lt;br /&gt;
&lt;br /&gt;
==== Requirements ====&lt;br /&gt;
&lt;br /&gt;
* Support a month-by-month view of the calendar.&lt;br /&gt;
*: Show one month at a time, with buttons to move forward or backward.&lt;br /&gt;
*: There should be no limit to how far forward or backward the user can go.&lt;br /&gt;
* Users can register and log in to the website.&lt;br /&gt;
*: You may leverage your MySQL project code and database from last week to get started.&lt;br /&gt;
*: You may alternatively use OpenID for user authentication.  Note that you will still need a Users table in order associate calendar events with a certain OpenID.&lt;br /&gt;
* Unregistered users should see no events on the calendar.&lt;br /&gt;
* Registered users can add events.&lt;br /&gt;
*: All events should have a date and time, but do not need to have a duration.&lt;br /&gt;
*: You do ''not'' need to support recurring events (where you add an event that repeats, for example, every monday).&lt;br /&gt;
* Registered users see only events that they have added.&lt;br /&gt;
* Registered users can delete their events, but not the events of others.&lt;br /&gt;
* All user and event data should be kept in a database.&lt;br /&gt;
* At no time should the main page need to be reloaded.&lt;br /&gt;
*: User registration, user authentication, event addition, and event deletion should all be handled by JavaScript and AJAX requests to your server.&lt;br /&gt;
* Your page needs to work in the versions of Firefox and Chrome installed on the lab computers.&lt;br /&gt;
&lt;br /&gt;
'''Tip:''' Run your database schema by a TA before implementing it.&lt;br /&gt;
&lt;br /&gt;
==== Calendar Helper Library ====&lt;br /&gt;
&lt;br /&gt;
To help you get started with your calendar, we have written some JavaScript helper functions.  The code is available at:&lt;br /&gt;
* Full Version (for you to refer): http://cloud.sffc1.com/wustl/calendar.js&lt;br /&gt;
* Minified Version (to include in your pages): http://cloud.sffc1.com/wustl/calendar.min.js&lt;br /&gt;
&lt;br /&gt;
For example, this is how you would make a button to load the next month and show alerts containing all the days in the weeks contained by that month.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
// For our purposes, we can keep the current month in a variable in the global scope&lt;br /&gt;
var currentMonth = new Month(2012, 9); // October 2012&lt;br /&gt;
&lt;br /&gt;
// Change the month when the &amp;quot;next&amp;quot; button is pressed&lt;br /&gt;
document.getElementById(&amp;quot;next_month_btn&amp;quot;).addEventListener(&amp;quot;click&amp;quot;, function(event){&lt;br /&gt;
	currentMonth = currentMonth.nextMonth(); // Previous month would be currentMonth.prevMonth()&lt;br /&gt;
	updateCalendar(); // Whenever the month is updated, we'll need to re-render the calendar in HTML&lt;br /&gt;
	alert(&amp;quot;The new month is &amp;quot;+currentMonth.month+&amp;quot; &amp;quot;+currentMonth.year);&lt;br /&gt;
}, false);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
// This updateCalendar() function only alerts the dates in the currently specified month.  You need to write&lt;br /&gt;
// it to modify the DOM (optionally using jQuery) to display the days and weeks in the current month.&lt;br /&gt;
function updateCalendar(){&lt;br /&gt;
	var weeks = currentMonth.getWeeks();&lt;br /&gt;
	&lt;br /&gt;
	for(var w in weeks){&lt;br /&gt;
		var days = weeks[w].getDates();&lt;br /&gt;
		// days contains normal JavaScript Date objects.&lt;br /&gt;
		&lt;br /&gt;
		alert(&amp;quot;Week starting on &amp;quot;+days[0]);&lt;br /&gt;
		&lt;br /&gt;
		for(var d in days){&lt;br /&gt;
			// You can see console.log() output in your JavaScript debugging tool, like Firebug,&lt;br /&gt;
			// WebWit Inspector, or Dragonfly.&lt;br /&gt;
			console.log(days[d].toISOString());&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Important:''' JavaScript starts the months of a year, and the days of a week, at index 0.  This means that '''''in JavaScript, January is month 0, and December is month 11.'''''  Our calendar helper functions maintain this JavaScript convention.&lt;br /&gt;
&lt;br /&gt;
=== Web Security and Validation ===&lt;br /&gt;
&lt;br /&gt;
Your project needs to demonstrate that thought was put into web security and best practice.  For more information, see this week's Web Application Security guide: [[Web Application Security, Part 3]]&lt;br /&gt;
&lt;br /&gt;
In particular:&lt;br /&gt;
&lt;br /&gt;
* '''Your application needs to prevent XSS attacks.'''  The easiest way to prevent this is to continue sanitizing ''all'' of your output using '''htmlentities()'''.&lt;br /&gt;
* '''Perform precautionary measures to prevent session hijacking attacks.'''&lt;br /&gt;
*: You should specify your session cookie to be HTTP-Only.  However, for the means of this module, you need not test for user agent consistency.&lt;br /&gt;
* Validate your JavaScript code using [http://www.jshint.com/ JSHint]&lt;br /&gt;
&lt;br /&gt;
You should continue the practices that you have learned in past weeks:&lt;br /&gt;
&lt;br /&gt;
* Pass tokens in forms to prevent CSRF attacks&lt;br /&gt;
* Use prepared queries to prevent SQL Injection attacks&lt;br /&gt;
* If storing passwords in a database, always store them encrypted&lt;br /&gt;
* Your page should validate with no errors through the W3C validator.&lt;br /&gt;
&lt;br /&gt;
== Grading ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;font-size:2em; line-height:2em;&amp;quot;&amp;gt;'''Due Date: Monday, October 29th by 1pm (both individual and group)'''&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
!Assignment&lt;br /&gt;
!Points&lt;br /&gt;
|-&lt;br /&gt;
|Calculator&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
|Weather Widget&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|jQuery Dialogs&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
!colspan=&amp;quot;2&amp;quot;|Group Portion:&lt;br /&gt;
|-&lt;br /&gt;
|Calendar month view correct and Move between months (without page reload)&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|User authentication and registration (without page reload)&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Add events (new event shown in calendar without page reload)&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Events added are private and other users cannot see them&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
|Delete events (event removed from calendar without page reload)&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
|-&lt;br /&gt;
|Safe from XSS and Session Hijacking&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|-&lt;br /&gt;
|Validation, CSRF, Salted Passwords, Safe SQL Queries, JSHint&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Creative Portion&lt;br /&gt;
|2&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Total: 10 Points&lt;br /&gt;
&lt;br /&gt;
You must get written permission at least one day before the due date for your creative portion.  Failure to get written permission will result in one point maximum.  You will be asked to provide proof of approval.&lt;br /&gt;
Send permission requests to Marc.&lt;br /&gt;
&lt;br /&gt;
[[Category:Module 4]]&lt;br /&gt;
[[Category:Modules]]&lt;/div&gt;</summary>
		<author><name>Marc</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=Module_6&amp;diff=805</id>
		<title>Module 6</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=Module_6&amp;diff=805"/>
		<updated>2012-10-14T04:03:45Z</updated>

		<summary type="html">&lt;p&gt;Marc: /* Grading */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In Module 4, you will learn about JavaScript, the prevailing client-side language, and AJAX, a method for performing asynchronous updates to a web page (without refreshing the page).&lt;br /&gt;
&lt;br /&gt;
This article contains your assignments for Module 4.&lt;br /&gt;
&lt;br /&gt;
== Individual Assignments ==&lt;br /&gt;
&lt;br /&gt;
=== JavaScript Calculator ===&lt;br /&gt;
&lt;br /&gt;
In Module 2, you made a calculator using PHP.  Now you will be making one using JavaScript.&lt;br /&gt;
&lt;br /&gt;
Read the JavaScript guide first: [[Javascript and AJAX]]&lt;br /&gt;
&lt;br /&gt;
* The web page should have two input fields and a radio button group for the operation, with the 4 basic math operations represented (add,subtract,multiply,divide).&lt;br /&gt;
* The javascript should monitor all three fields and display the current result whenever the user changes any value in any field, without refreshing the page.&lt;br /&gt;
* The calculator should be completely self-contained; i.e., you should not be making any requests to any other server-side or client-side scripts or web pages after the initial page load.&lt;br /&gt;
&lt;br /&gt;
'''Tip:''' You can embed JavaScript code into an HTML document like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;
// your code here&lt;br /&gt;
&amp;lt;/script&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Tip:''' If your code isn't working the way you expect, use a JavaScript error console.  In Chrome, for example, press Ctrl-Shift-I (or Cmd-Option-I) to open the WebKit inspector.&lt;br /&gt;
&lt;br /&gt;
=== Weather Widget ===&lt;br /&gt;
&lt;br /&gt;
In this section, you will make a web page that displays the weather forecast using AJAX requests to a weather server.  You should complete this section ''without'' using JavaScript libraries like jQuery.&lt;br /&gt;
&lt;br /&gt;
# Make an empty HTML document; name it '''weather.html'''&lt;br /&gt;
#: Refer to the [[HTML and CSS]] guide for the skeleton of an HTML document&lt;br /&gt;
# Define a function in JavaScript; call it '''fetchWeather()'''.  You may write your JavaScript in an embedded script in your head tag.&lt;br /&gt;
# Inside your '''fetchWeather()''' function, make an AJAX request to the weather server.&lt;br /&gt;
#: We have a server that outputs the current weather in JSON format.  The format is documented in the [[#JSON Structure]] section below.&lt;br /&gt;
#: '''URL:''' http://cloud.sffc1.com/wustl/weather_json.php&lt;br /&gt;
#: We kindly thank Yahoo Weather for providing us with up-to-date weather information.&lt;br /&gt;
#* '''Note:''' You normally cannot perform AJAX requests cross-domain.  We have set the &amp;lt;code&amp;gt;Access-Control-Allow-Origin&amp;lt;/code&amp;gt; header on our server to allow requests from your EC2 instances.&lt;br /&gt;
# In your callback, process the JSON and use JavaScript to manipulate the HTML DOM to display the following information on your page:&lt;br /&gt;
#* Location&lt;br /&gt;
#** City, in a &amp;lt;nowiki&amp;gt;&amp;lt;strong&amp;gt;&amp;lt;/nowiki&amp;gt; tag&lt;br /&gt;
#** State, not in any tag&lt;br /&gt;
#* Humidity&lt;br /&gt;
#* Current Temperature&lt;br /&gt;
#* Image for Tomorrow's Forecast (see [[#Weather Condition Images]] below for more information)&lt;br /&gt;
#* Image for the Day After Tomorrow's Forecast&lt;br /&gt;
# Finally, bind '''fetchWeather()''' to the DOMContentReady event so that your weather widget is automatically initialized when the page is loaded:&lt;br /&gt;
#: &amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;document.addEventListener(&amp;quot;DOMContentReady&amp;quot;, fetchWeather, false);&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Use the following HTML:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;weather&amp;quot; id=&amp;quot;weatherWidget&amp;quot;&amp;gt;&lt;br /&gt;
	&amp;lt;div class=&amp;quot;weather-loc&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
	&amp;lt;div class=&amp;quot;weather-humidity&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
	&amp;lt;div class=&amp;quot;weather-temp&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
	&amp;lt;img class=&amp;quot;weather-tomorrow&amp;quot; /&amp;gt;&lt;br /&gt;
	&amp;lt;img class=&amp;quot;weather-dayaftertomorrow&amp;quot; /&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Include the CSS file from here: http://cloud.sffc1.com/wustl/weather.css&lt;br /&gt;
&lt;br /&gt;
When everything is working, the weather widget should look something like this:&lt;br /&gt;
&lt;br /&gt;
[[File:WeatherWidget.png]]&lt;br /&gt;
&lt;br /&gt;
'''Important:''' The widget in this section needs to work in only Firefox and Chrome.  It does '''''not''''' need to work Internet Explorer.&lt;br /&gt;
&lt;br /&gt;
==== Tips ====&lt;br /&gt;
&lt;br /&gt;
===== JSON Structure =====&lt;br /&gt;
&lt;br /&gt;
The JSON from our server looks like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
   &amp;quot;updated&amp;quot;: &amp;quot;Thu, 11 Oct 2012 5:54 pm CDT&amp;quot;,&lt;br /&gt;
   &amp;quot;location&amp;quot;: {&lt;br /&gt;
      &amp;quot;city&amp;quot;: &amp;quot;St. Louis&amp;quot;,&lt;br /&gt;
      &amp;quot;state&amp;quot;: &amp;quot;MO&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;wind&amp;quot;: {&lt;br /&gt;
      &amp;quot;chill&amp;quot;: &amp;quot;62&amp;quot;,&lt;br /&gt;
      &amp;quot;direction&amp;quot;: &amp;quot;150&amp;quot;,&lt;br /&gt;
      &amp;quot;speed&amp;quot;: &amp;quot;3 mph&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;atmosphere&amp;quot;: {&lt;br /&gt;
      &amp;quot;humidity&amp;quot;: &amp;quot;50&amp;quot;,&lt;br /&gt;
      &amp;quot;visibility&amp;quot;: &amp;quot;10&amp;quot;,&lt;br /&gt;
      &amp;quot;pressure&amp;quot;: &amp;quot;30.12 in&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;current&amp;quot;: {&lt;br /&gt;
      &amp;quot;code&amp;quot;: &amp;quot;28&amp;quot;,&lt;br /&gt;
      &amp;quot;text&amp;quot;: &amp;quot;Mostly Cloudy&amp;quot;,&lt;br /&gt;
      &amp;quot;temp&amp;quot;: &amp;quot;62°F&amp;quot;,&lt;br /&gt;
      &amp;quot;date&amp;quot;: &amp;quot;Thu, 11 Oct 2012 5:54 pm CDT&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;tomorrow&amp;quot;: {&lt;br /&gt;
      &amp;quot;code&amp;quot;: &amp;quot;29&amp;quot;,&lt;br /&gt;
      &amp;quot;text&amp;quot;: &amp;quot;Clouds Early/Clearing Late&amp;quot;,&lt;br /&gt;
      &amp;quot;low&amp;quot;: &amp;quot;45°F&amp;quot;,&lt;br /&gt;
      &amp;quot;high&amp;quot;: &amp;quot;61°F&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;dayafter&amp;quot;: {&lt;br /&gt;
      &amp;quot;code&amp;quot;: &amp;quot;30&amp;quot;,&lt;br /&gt;
      &amp;quot;text&amp;quot;: &amp;quot;Partly Cloudy&amp;quot;,&lt;br /&gt;
      &amp;quot;low&amp;quot;: &amp;quot;53°F&amp;quot;,&lt;br /&gt;
      &amp;quot;high&amp;quot;: &amp;quot;65°F&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;credit&amp;quot;: &amp;quot;http://us.rd.yahoo.com/dailynews/rss/weather/St._Louis__MO/*http://weather.yahoo.com/forecast/USMO0170_f.html&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Weather Condition Images =====&lt;br /&gt;
&lt;br /&gt;
Each day's forecast has a code.  There are images associated with these codes.&lt;br /&gt;
&lt;br /&gt;
You can get images from here: &amp;lt;nowiki&amp;gt;http://us.i1.yimg.com/us.yimg.com/i/us/nws/weather/gr/&amp;lt;/nowiki&amp;gt;'''##'''&amp;lt;nowiki&amp;gt;ds.png&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Replace the '''##''' with the forecast code.  For example, for code 32, the URL would be: http://us.i1.yimg.com/us.yimg.com/i/us/nws/weather/gr/32ds.png&lt;br /&gt;
&lt;br /&gt;
=== jQuery Dialogs ===&lt;br /&gt;
&lt;br /&gt;
Helpful Resource: [http://docs.jquery.com/Main_Page jQuery Documentation] ... Some additional tips: [[jQuery]]&lt;br /&gt;
&lt;br /&gt;
Create a simple page using jQuery dialogs.&lt;br /&gt;
&lt;br /&gt;
* Create a page that has the words &amp;quot;Google&amp;quot; and &amp;quot;Yahoo&amp;quot;.&lt;br /&gt;
* When the user clicks the &amp;quot;Google&amp;quot; text, open a jQuery dialog window with one jQuery dialog button.  If the button is pressed, display the Google logo image (the image can be stored on your web server) on the web page, and if the dialog is closed any other way, do nothing.&lt;br /&gt;
* When the user clicks the &amp;quot;Yahoo&amp;quot; text, open a jQuery dialog window with one jQuery dialog button.  If the button is pressed, display the Yahoo logo image (the image can be stored on your web server) on the web page, and if the dialog is closed any other way, do nothing.&lt;br /&gt;
* Initially there should be no image on the page (i.e., the img should be hidden with the CSS display attribute).  After one of the two images is displayed, if the user clicks on the image, a jQuery dialog box should be opened with one dialog button, and if the button is pressed then the image should be hidden again.  Otherwise, do nothing.&lt;br /&gt;
&lt;br /&gt;
== Group Project ==&lt;br /&gt;
&lt;br /&gt;
You will work in pairs on this project.&lt;br /&gt;
&lt;br /&gt;
'''Important Reminder:''' frequently commit your work to your subversion repository as a backup!&lt;br /&gt;
&lt;br /&gt;
I forgot if I already mentioned this, but '''start early on this project!''' It will take longer than you think, I promise!&lt;br /&gt;
&lt;br /&gt;
=== Calendar ===&lt;br /&gt;
&lt;br /&gt;
Build a simple calendar that allows users to add and remove events dynamically.&lt;br /&gt;
&lt;br /&gt;
You will use JavaScript to process user interactions at the web browser, without ever refreshing the browser after the initial web page load.  You may use a JavaScript library of your choice, including jQuery.  (No extra credit will be given for ''not'' using a JavaScript library.)&lt;br /&gt;
&lt;br /&gt;
Your application should utilize AJAX to run server-side PHP scripts that query your database to save and retrieve information, including user accounts and events.&lt;br /&gt;
&lt;br /&gt;
==== Examples ====&lt;br /&gt;
&lt;br /&gt;
* https://calendar.google.com/&lt;br /&gt;
* http://www.zoho.com/calendar/&lt;br /&gt;
&lt;br /&gt;
==== Requirements ====&lt;br /&gt;
&lt;br /&gt;
* Support a month-by-month view of the calendar.&lt;br /&gt;
*: Show one month at a time, with buttons to move forward or backward.&lt;br /&gt;
*: There should be no limit to how far forward or backward the user can go.&lt;br /&gt;
* Users can register and log in to the website.&lt;br /&gt;
*: You may leverage your MySQL project code and database from last week to get started.&lt;br /&gt;
*: You may alternatively use OpenID for user authentication.  Note that you will still need a Users table in order associate calendar events with a certain OpenID.&lt;br /&gt;
* Unregistered users should see no events on the calendar.&lt;br /&gt;
* Registered users can add events.&lt;br /&gt;
*: All events should have a date and time, but do not need to have a duration.&lt;br /&gt;
*: You do ''not'' need to support recurring events (where you add an event that repeats, for example, every monday).&lt;br /&gt;
* Registered users see only events that they have added.&lt;br /&gt;
* Registered users can delete their events, but not the events of others.&lt;br /&gt;
* All user and event data should be kept in a database.&lt;br /&gt;
* At no time should the main page need to be reloaded.&lt;br /&gt;
*: User registration, user authentication, event addition, and event deletion should all be handled by JavaScript and AJAX requests to your server.&lt;br /&gt;
* Your page needs to work in the versions of Firefox and Chrome installed on the lab computers.&lt;br /&gt;
&lt;br /&gt;
'''Tip:''' Run your database schema by a TA before implementing it.&lt;br /&gt;
&lt;br /&gt;
==== Calendar Helper Library ====&lt;br /&gt;
&lt;br /&gt;
To help you get started with your calendar, we have written some JavaScript helper functions.  The code is available at:&lt;br /&gt;
* Full Version (for you to refer): http://cloud.sffc1.com/wustl/calendar.js&lt;br /&gt;
* Minified Version (to include in your pages): http://cloud.sffc1.com/wustl/calendar.min.js&lt;br /&gt;
&lt;br /&gt;
For example, this is how you would make a button to load the next month and show alerts containing all the days in the weeks contained by that month.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
// For our purposes, we can keep the current month in a variable in the global scope&lt;br /&gt;
var currentMonth = new Month(2012, 9); // October 2012&lt;br /&gt;
&lt;br /&gt;
// Change the month when the &amp;quot;next&amp;quot; button is pressed&lt;br /&gt;
document.getElementById(&amp;quot;next_month_btn&amp;quot;).addEventListener(&amp;quot;click&amp;quot;, function(event){&lt;br /&gt;
	currentMonth = currentMonth.nextMonth(); // Previous month would be currentMonth.prevMonth()&lt;br /&gt;
	updateCalendar(); // Whenever the month is updated, we'll need to re-render the calendar in HTML&lt;br /&gt;
	alert(&amp;quot;The new month is &amp;quot;+currentMonth.month+&amp;quot; &amp;quot;+currentMonth.year);&lt;br /&gt;
}, false);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
// This updateCalendar() function only alerts the dates in the currently specified month.  You need to write&lt;br /&gt;
// it to modify the DOM (optionally using jQuery) to display the days and weeks in the current month.&lt;br /&gt;
function updateCalendar(){&lt;br /&gt;
	var weeks = currentMonth.getWeeks();&lt;br /&gt;
	&lt;br /&gt;
	for(var w in weeks){&lt;br /&gt;
		var days = weeks[w].getDates();&lt;br /&gt;
		// days contains normal JavaScript Date objects.&lt;br /&gt;
		&lt;br /&gt;
		alert(&amp;quot;Week starting on &amp;quot;+days[0]);&lt;br /&gt;
		&lt;br /&gt;
		for(var d in days){&lt;br /&gt;
			// You can see console.log() output in your JavaScript debugging tool, like Firebug,&lt;br /&gt;
			// WebWit Inspector, or Dragonfly.&lt;br /&gt;
			console.log(days[d].toISOString());&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Important:''' JavaScript starts the months of a year, and the days of a week, at index 0.  This means that '''''in JavaScript, January is month 0, and December is month 11.'''''  Our calendar helper functions maintain this JavaScript convention.&lt;br /&gt;
&lt;br /&gt;
=== Web Security and Validation ===&lt;br /&gt;
&lt;br /&gt;
Your project needs to demonstrate that thought was put into web security and best practice.  For more information, see this week's Web Application Security guide: [[Web Application Security, Part 3]]&lt;br /&gt;
&lt;br /&gt;
In particular:&lt;br /&gt;
&lt;br /&gt;
* '''Your application needs to prevent XSS attacks.'''  The easiest way to prevent this is to continue sanitizing ''all'' of your output using '''htmlentities()'''.&lt;br /&gt;
* '''Perform precautionary measures to prevent session hijacking attacks.'''&lt;br /&gt;
*: You should specify your session cookie to be HTTP-Only.  However, for the means of this module, you need not test for user agent consistency.&lt;br /&gt;
* Validate your JavaScript code using [http://www.jshint.com/ JSHint]&lt;br /&gt;
&lt;br /&gt;
You should continue the practices that you have learned in past weeks:&lt;br /&gt;
&lt;br /&gt;
* Pass tokens in forms to prevent CSRF attacks&lt;br /&gt;
* Use prepared queries to prevent SQL Injection attacks&lt;br /&gt;
* If storing passwords in a database, always store them encrypted&lt;br /&gt;
* Your page should validate with no errors through the W3C validator.&lt;br /&gt;
&lt;br /&gt;
== Grading ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;font-size:2em; line-height:2em;&amp;quot;&amp;gt;'''Due Date: _____ (both individual and group)'''&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
!Assignment&lt;br /&gt;
!Points&lt;br /&gt;
|-&lt;br /&gt;
|Calculator&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
|Weather Widget&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|jQuery Dialogs&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
!colspan=&amp;quot;2&amp;quot;|Group Portion:&lt;br /&gt;
|-&lt;br /&gt;
|Calendar month view correct and Move between months (without page reload)&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|User authentication and registration (without page reload)&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Add events (new event shown in calendar without page reload)&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Events added are private and other users cannot see them&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
|Delete events (event removed from calendar without page reload)&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
|-&lt;br /&gt;
|Safe from XSS and Session Hijacking&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|-&lt;br /&gt;
|Validation, CSRF, Salted Passwords, Safe SQL Queries, JSHint&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Creative Portion&lt;br /&gt;
|2&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Total: 10 Points&lt;br /&gt;
&lt;br /&gt;
You must get written permission at least one day before the due date for your creative portion.  Failure to get written permission will result in one point maximum.  You will be asked to provide proof of approval.&lt;br /&gt;
Send permission requests to Marc.&lt;br /&gt;
&lt;br /&gt;
[[Category:Module 4]]&lt;br /&gt;
[[Category:Modules]]&lt;/div&gt;</summary>
		<author><name>Marc</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=Module_6&amp;diff=804</id>
		<title>Module 6</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=Module_6&amp;diff=804"/>
		<updated>2012-10-14T04:03:01Z</updated>

		<summary type="html">&lt;p&gt;Marc: /* Grading */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In Module 4, you will learn about JavaScript, the prevailing client-side language, and AJAX, a method for performing asynchronous updates to a web page (without refreshing the page).&lt;br /&gt;
&lt;br /&gt;
This article contains your assignments for Module 4.&lt;br /&gt;
&lt;br /&gt;
== Individual Assignments ==&lt;br /&gt;
&lt;br /&gt;
=== JavaScript Calculator ===&lt;br /&gt;
&lt;br /&gt;
In Module 2, you made a calculator using PHP.  Now you will be making one using JavaScript.&lt;br /&gt;
&lt;br /&gt;
Read the JavaScript guide first: [[Javascript and AJAX]]&lt;br /&gt;
&lt;br /&gt;
* The web page should have two input fields and a radio button group for the operation, with the 4 basic math operations represented (add,subtract,multiply,divide).&lt;br /&gt;
* The javascript should monitor all three fields and display the current result whenever the user changes any value in any field, without refreshing the page.&lt;br /&gt;
* The calculator should be completely self-contained; i.e., you should not be making any requests to any other server-side or client-side scripts or web pages after the initial page load.&lt;br /&gt;
&lt;br /&gt;
'''Tip:''' You can embed JavaScript code into an HTML document like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;
// your code here&lt;br /&gt;
&amp;lt;/script&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Tip:''' If your code isn't working the way you expect, use a JavaScript error console.  In Chrome, for example, press Ctrl-Shift-I (or Cmd-Option-I) to open the WebKit inspector.&lt;br /&gt;
&lt;br /&gt;
=== Weather Widget ===&lt;br /&gt;
&lt;br /&gt;
In this section, you will make a web page that displays the weather forecast using AJAX requests to a weather server.  You should complete this section ''without'' using JavaScript libraries like jQuery.&lt;br /&gt;
&lt;br /&gt;
# Make an empty HTML document; name it '''weather.html'''&lt;br /&gt;
#: Refer to the [[HTML and CSS]] guide for the skeleton of an HTML document&lt;br /&gt;
# Define a function in JavaScript; call it '''fetchWeather()'''.  You may write your JavaScript in an embedded script in your head tag.&lt;br /&gt;
# Inside your '''fetchWeather()''' function, make an AJAX request to the weather server.&lt;br /&gt;
#: We have a server that outputs the current weather in JSON format.  The format is documented in the [[#JSON Structure]] section below.&lt;br /&gt;
#: '''URL:''' http://cloud.sffc1.com/wustl/weather_json.php&lt;br /&gt;
#: We kindly thank Yahoo Weather for providing us with up-to-date weather information.&lt;br /&gt;
#* '''Note:''' You normally cannot perform AJAX requests cross-domain.  We have set the &amp;lt;code&amp;gt;Access-Control-Allow-Origin&amp;lt;/code&amp;gt; header on our server to allow requests from your EC2 instances.&lt;br /&gt;
# In your callback, process the JSON and use JavaScript to manipulate the HTML DOM to display the following information on your page:&lt;br /&gt;
#* Location&lt;br /&gt;
#** City, in a &amp;lt;nowiki&amp;gt;&amp;lt;strong&amp;gt;&amp;lt;/nowiki&amp;gt; tag&lt;br /&gt;
#** State, not in any tag&lt;br /&gt;
#* Humidity&lt;br /&gt;
#* Current Temperature&lt;br /&gt;
#* Image for Tomorrow's Forecast (see [[#Weather Condition Images]] below for more information)&lt;br /&gt;
#* Image for the Day After Tomorrow's Forecast&lt;br /&gt;
# Finally, bind '''fetchWeather()''' to the DOMContentReady event so that your weather widget is automatically initialized when the page is loaded:&lt;br /&gt;
#: &amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;document.addEventListener(&amp;quot;DOMContentReady&amp;quot;, fetchWeather, false);&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Use the following HTML:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;weather&amp;quot; id=&amp;quot;weatherWidget&amp;quot;&amp;gt;&lt;br /&gt;
	&amp;lt;div class=&amp;quot;weather-loc&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
	&amp;lt;div class=&amp;quot;weather-humidity&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
	&amp;lt;div class=&amp;quot;weather-temp&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
	&amp;lt;img class=&amp;quot;weather-tomorrow&amp;quot; /&amp;gt;&lt;br /&gt;
	&amp;lt;img class=&amp;quot;weather-dayaftertomorrow&amp;quot; /&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Include the CSS file from here: http://cloud.sffc1.com/wustl/weather.css&lt;br /&gt;
&lt;br /&gt;
When everything is working, the weather widget should look something like this:&lt;br /&gt;
&lt;br /&gt;
[[File:WeatherWidget.png]]&lt;br /&gt;
&lt;br /&gt;
'''Important:''' The widget in this section needs to work in only Firefox and Chrome.  It does '''''not''''' need to work Internet Explorer.&lt;br /&gt;
&lt;br /&gt;
==== Tips ====&lt;br /&gt;
&lt;br /&gt;
===== JSON Structure =====&lt;br /&gt;
&lt;br /&gt;
The JSON from our server looks like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
   &amp;quot;updated&amp;quot;: &amp;quot;Thu, 11 Oct 2012 5:54 pm CDT&amp;quot;,&lt;br /&gt;
   &amp;quot;location&amp;quot;: {&lt;br /&gt;
      &amp;quot;city&amp;quot;: &amp;quot;St. Louis&amp;quot;,&lt;br /&gt;
      &amp;quot;state&amp;quot;: &amp;quot;MO&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;wind&amp;quot;: {&lt;br /&gt;
      &amp;quot;chill&amp;quot;: &amp;quot;62&amp;quot;,&lt;br /&gt;
      &amp;quot;direction&amp;quot;: &amp;quot;150&amp;quot;,&lt;br /&gt;
      &amp;quot;speed&amp;quot;: &amp;quot;3 mph&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;atmosphere&amp;quot;: {&lt;br /&gt;
      &amp;quot;humidity&amp;quot;: &amp;quot;50&amp;quot;,&lt;br /&gt;
      &amp;quot;visibility&amp;quot;: &amp;quot;10&amp;quot;,&lt;br /&gt;
      &amp;quot;pressure&amp;quot;: &amp;quot;30.12 in&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;current&amp;quot;: {&lt;br /&gt;
      &amp;quot;code&amp;quot;: &amp;quot;28&amp;quot;,&lt;br /&gt;
      &amp;quot;text&amp;quot;: &amp;quot;Mostly Cloudy&amp;quot;,&lt;br /&gt;
      &amp;quot;temp&amp;quot;: &amp;quot;62°F&amp;quot;,&lt;br /&gt;
      &amp;quot;date&amp;quot;: &amp;quot;Thu, 11 Oct 2012 5:54 pm CDT&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;tomorrow&amp;quot;: {&lt;br /&gt;
      &amp;quot;code&amp;quot;: &amp;quot;29&amp;quot;,&lt;br /&gt;
      &amp;quot;text&amp;quot;: &amp;quot;Clouds Early/Clearing Late&amp;quot;,&lt;br /&gt;
      &amp;quot;low&amp;quot;: &amp;quot;45°F&amp;quot;,&lt;br /&gt;
      &amp;quot;high&amp;quot;: &amp;quot;61°F&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;dayafter&amp;quot;: {&lt;br /&gt;
      &amp;quot;code&amp;quot;: &amp;quot;30&amp;quot;,&lt;br /&gt;
      &amp;quot;text&amp;quot;: &amp;quot;Partly Cloudy&amp;quot;,&lt;br /&gt;
      &amp;quot;low&amp;quot;: &amp;quot;53°F&amp;quot;,&lt;br /&gt;
      &amp;quot;high&amp;quot;: &amp;quot;65°F&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;credit&amp;quot;: &amp;quot;http://us.rd.yahoo.com/dailynews/rss/weather/St._Louis__MO/*http://weather.yahoo.com/forecast/USMO0170_f.html&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Weather Condition Images =====&lt;br /&gt;
&lt;br /&gt;
Each day's forecast has a code.  There are images associated with these codes.&lt;br /&gt;
&lt;br /&gt;
You can get images from here: &amp;lt;nowiki&amp;gt;http://us.i1.yimg.com/us.yimg.com/i/us/nws/weather/gr/&amp;lt;/nowiki&amp;gt;'''##'''&amp;lt;nowiki&amp;gt;ds.png&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Replace the '''##''' with the forecast code.  For example, for code 32, the URL would be: http://us.i1.yimg.com/us.yimg.com/i/us/nws/weather/gr/32ds.png&lt;br /&gt;
&lt;br /&gt;
=== jQuery Dialogs ===&lt;br /&gt;
&lt;br /&gt;
Helpful Resource: [http://docs.jquery.com/Main_Page jQuery Documentation] ... Some additional tips: [[jQuery]]&lt;br /&gt;
&lt;br /&gt;
Create a simple page using jQuery dialogs.&lt;br /&gt;
&lt;br /&gt;
* Create a page that has the words &amp;quot;Google&amp;quot; and &amp;quot;Yahoo&amp;quot;.&lt;br /&gt;
* When the user clicks the &amp;quot;Google&amp;quot; text, open a jQuery dialog window with one jQuery dialog button.  If the button is pressed, display the Google logo image (the image can be stored on your web server) on the web page, and if the dialog is closed any other way, do nothing.&lt;br /&gt;
* When the user clicks the &amp;quot;Yahoo&amp;quot; text, open a jQuery dialog window with one jQuery dialog button.  If the button is pressed, display the Yahoo logo image (the image can be stored on your web server) on the web page, and if the dialog is closed any other way, do nothing.&lt;br /&gt;
* Initially there should be no image on the page (i.e., the img should be hidden with the CSS display attribute).  After one of the two images is displayed, if the user clicks on the image, a jQuery dialog box should be opened with one dialog button, and if the button is pressed then the image should be hidden again.  Otherwise, do nothing.&lt;br /&gt;
&lt;br /&gt;
== Group Project ==&lt;br /&gt;
&lt;br /&gt;
You will work in pairs on this project.&lt;br /&gt;
&lt;br /&gt;
'''Important Reminder:''' frequently commit your work to your subversion repository as a backup!&lt;br /&gt;
&lt;br /&gt;
I forgot if I already mentioned this, but '''start early on this project!''' It will take longer than you think, I promise!&lt;br /&gt;
&lt;br /&gt;
=== Calendar ===&lt;br /&gt;
&lt;br /&gt;
Build a simple calendar that allows users to add and remove events dynamically.&lt;br /&gt;
&lt;br /&gt;
You will use JavaScript to process user interactions at the web browser, without ever refreshing the browser after the initial web page load.  You may use a JavaScript library of your choice, including jQuery.  (No extra credit will be given for ''not'' using a JavaScript library.)&lt;br /&gt;
&lt;br /&gt;
Your application should utilize AJAX to run server-side PHP scripts that query your database to save and retrieve information, including user accounts and events.&lt;br /&gt;
&lt;br /&gt;
==== Examples ====&lt;br /&gt;
&lt;br /&gt;
* https://calendar.google.com/&lt;br /&gt;
* http://www.zoho.com/calendar/&lt;br /&gt;
&lt;br /&gt;
==== Requirements ====&lt;br /&gt;
&lt;br /&gt;
* Support a month-by-month view of the calendar.&lt;br /&gt;
*: Show one month at a time, with buttons to move forward or backward.&lt;br /&gt;
*: There should be no limit to how far forward or backward the user can go.&lt;br /&gt;
* Users can register and log in to the website.&lt;br /&gt;
*: You may leverage your MySQL project code and database from last week to get started.&lt;br /&gt;
*: You may alternatively use OpenID for user authentication.  Note that you will still need a Users table in order associate calendar events with a certain OpenID.&lt;br /&gt;
* Unregistered users should see no events on the calendar.&lt;br /&gt;
* Registered users can add events.&lt;br /&gt;
*: All events should have a date and time, but do not need to have a duration.&lt;br /&gt;
*: You do ''not'' need to support recurring events (where you add an event that repeats, for example, every monday).&lt;br /&gt;
* Registered users see only events that they have added.&lt;br /&gt;
* Registered users can delete their events, but not the events of others.&lt;br /&gt;
* All user and event data should be kept in a database.&lt;br /&gt;
* At no time should the main page need to be reloaded.&lt;br /&gt;
*: User registration, user authentication, event addition, and event deletion should all be handled by JavaScript and AJAX requests to your server.&lt;br /&gt;
* Your page needs to work in the versions of Firefox and Chrome installed on the lab computers.&lt;br /&gt;
&lt;br /&gt;
'''Tip:''' Run your database schema by a TA before implementing it.&lt;br /&gt;
&lt;br /&gt;
==== Calendar Helper Library ====&lt;br /&gt;
&lt;br /&gt;
To help you get started with your calendar, we have written some JavaScript helper functions.  The code is available at:&lt;br /&gt;
* Full Version (for you to refer): http://cloud.sffc1.com/wustl/calendar.js&lt;br /&gt;
* Minified Version (to include in your pages): http://cloud.sffc1.com/wustl/calendar.min.js&lt;br /&gt;
&lt;br /&gt;
For example, this is how you would make a button to load the next month and show alerts containing all the days in the weeks contained by that month.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
// For our purposes, we can keep the current month in a variable in the global scope&lt;br /&gt;
var currentMonth = new Month(2012, 9); // October 2012&lt;br /&gt;
&lt;br /&gt;
// Change the month when the &amp;quot;next&amp;quot; button is pressed&lt;br /&gt;
document.getElementById(&amp;quot;next_month_btn&amp;quot;).addEventListener(&amp;quot;click&amp;quot;, function(event){&lt;br /&gt;
	currentMonth = currentMonth.nextMonth(); // Previous month would be currentMonth.prevMonth()&lt;br /&gt;
	updateCalendar(); // Whenever the month is updated, we'll need to re-render the calendar in HTML&lt;br /&gt;
	alert(&amp;quot;The new month is &amp;quot;+currentMonth.month+&amp;quot; &amp;quot;+currentMonth.year);&lt;br /&gt;
}, false);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
// This updateCalendar() function only alerts the dates in the currently specified month.  You need to write&lt;br /&gt;
// it to modify the DOM (optionally using jQuery) to display the days and weeks in the current month.&lt;br /&gt;
function updateCalendar(){&lt;br /&gt;
	var weeks = currentMonth.getWeeks();&lt;br /&gt;
	&lt;br /&gt;
	for(var w in weeks){&lt;br /&gt;
		var days = weeks[w].getDates();&lt;br /&gt;
		// days contains normal JavaScript Date objects.&lt;br /&gt;
		&lt;br /&gt;
		alert(&amp;quot;Week starting on &amp;quot;+days[0]);&lt;br /&gt;
		&lt;br /&gt;
		for(var d in days){&lt;br /&gt;
			// You can see console.log() output in your JavaScript debugging tool, like Firebug,&lt;br /&gt;
			// WebWit Inspector, or Dragonfly.&lt;br /&gt;
			console.log(days[d].toISOString());&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Important:''' JavaScript starts the months of a year, and the days of a week, at index 0.  This means that '''''in JavaScript, January is month 0, and December is month 11.'''''  Our calendar helper functions maintain this JavaScript convention.&lt;br /&gt;
&lt;br /&gt;
=== Web Security and Validation ===&lt;br /&gt;
&lt;br /&gt;
Your project needs to demonstrate that thought was put into web security and best practice.  For more information, see this week's Web Application Security guide: [[Web Application Security, Part 3]]&lt;br /&gt;
&lt;br /&gt;
In particular:&lt;br /&gt;
&lt;br /&gt;
* '''Your application needs to prevent XSS attacks.'''  The easiest way to prevent this is to continue sanitizing ''all'' of your output using '''htmlentities()'''.&lt;br /&gt;
* '''Perform precautionary measures to prevent session hijacking attacks.'''&lt;br /&gt;
*: You should specify your session cookie to be HTTP-Only.  However, for the means of this module, you need not test for user agent consistency.&lt;br /&gt;
* Validate your JavaScript code using [http://www.jshint.com/ JSHint]&lt;br /&gt;
&lt;br /&gt;
You should continue the practices that you have learned in past weeks:&lt;br /&gt;
&lt;br /&gt;
* Pass tokens in forms to prevent CSRF attacks&lt;br /&gt;
* Use prepared queries to prevent SQL Injection attacks&lt;br /&gt;
* If storing passwords in a database, always store them encrypted&lt;br /&gt;
* Your page should validate with no errors through the W3C validator.&lt;br /&gt;
&lt;br /&gt;
== Grading ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;font-size:2em; line-height:2em;&amp;quot;&amp;gt;'''Due Date: _____ (both individual and group)'''&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
!Assignment&lt;br /&gt;
!Points&lt;br /&gt;
|-&lt;br /&gt;
|Calculator&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
|Weather Widget&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|jQuery Dialogs&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
!colspan=&amp;quot;2&amp;quot;|Group Portion:&lt;br /&gt;
|-&lt;br /&gt;
|Calendar month view correct and Move between months (without page reload)&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|User authentication and registration (without page reload)&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Add events (new event shown in calendar without page reload)&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Events added are private and other users cannot see them&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
|Delete events (event removed from calendar without page reload)&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
|-&lt;br /&gt;
|Safe from XSS and Session Hijacking&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|-&lt;br /&gt;
|Validation, CSRF, Salted Passwords, Safe SQL Queries, JSHint&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Creative Portion&lt;br /&gt;
|2&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Total: 10 Points&lt;br /&gt;
&lt;br /&gt;
You must get written permission at least one day before the due date for your creative portion.  Failure to get written permission will result in one point maximum.  You will be asked to provide e-mail approval.&lt;br /&gt;
&lt;br /&gt;
[[Category:Module 4]]&lt;br /&gt;
[[Category:Modules]]&lt;/div&gt;</summary>
		<author><name>Marc</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=Module_6&amp;diff=803</id>
		<title>Module 6</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=Module_6&amp;diff=803"/>
		<updated>2012-10-14T04:00:33Z</updated>

		<summary type="html">&lt;p&gt;Marc: /* Grading */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In Module 4, you will learn about JavaScript, the prevailing client-side language, and AJAX, a method for performing asynchronous updates to a web page (without refreshing the page).&lt;br /&gt;
&lt;br /&gt;
This article contains your assignments for Module 4.&lt;br /&gt;
&lt;br /&gt;
== Individual Assignments ==&lt;br /&gt;
&lt;br /&gt;
=== JavaScript Calculator ===&lt;br /&gt;
&lt;br /&gt;
In Module 2, you made a calculator using PHP.  Now you will be making one using JavaScript.&lt;br /&gt;
&lt;br /&gt;
Read the JavaScript guide first: [[Javascript and AJAX]]&lt;br /&gt;
&lt;br /&gt;
* The web page should have two input fields and a radio button group for the operation, with the 4 basic math operations represented (add,subtract,multiply,divide).&lt;br /&gt;
* The javascript should monitor all three fields and display the current result whenever the user changes any value in any field, without refreshing the page.&lt;br /&gt;
* The calculator should be completely self-contained; i.e., you should not be making any requests to any other server-side or client-side scripts or web pages after the initial page load.&lt;br /&gt;
&lt;br /&gt;
'''Tip:''' You can embed JavaScript code into an HTML document like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;
// your code here&lt;br /&gt;
&amp;lt;/script&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Tip:''' If your code isn't working the way you expect, use a JavaScript error console.  In Chrome, for example, press Ctrl-Shift-I (or Cmd-Option-I) to open the WebKit inspector.&lt;br /&gt;
&lt;br /&gt;
=== Weather Widget ===&lt;br /&gt;
&lt;br /&gt;
In this section, you will make a web page that displays the weather forecast using AJAX requests to a weather server.  You should complete this section ''without'' using JavaScript libraries like jQuery.&lt;br /&gt;
&lt;br /&gt;
# Make an empty HTML document; name it '''weather.html'''&lt;br /&gt;
#: Refer to the [[HTML and CSS]] guide for the skeleton of an HTML document&lt;br /&gt;
# Define a function in JavaScript; call it '''fetchWeather()'''.  You may write your JavaScript in an embedded script in your head tag.&lt;br /&gt;
# Inside your '''fetchWeather()''' function, make an AJAX request to the weather server.&lt;br /&gt;
#: We have a server that outputs the current weather in JSON format.  The format is documented in the [[#JSON Structure]] section below.&lt;br /&gt;
#: '''URL:''' http://cloud.sffc1.com/wustl/weather_json.php&lt;br /&gt;
#: We kindly thank Yahoo Weather for providing us with up-to-date weather information.&lt;br /&gt;
#* '''Note:''' You normally cannot perform AJAX requests cross-domain.  We have set the &amp;lt;code&amp;gt;Access-Control-Allow-Origin&amp;lt;/code&amp;gt; header on our server to allow requests from your EC2 instances.&lt;br /&gt;
# In your callback, process the JSON and use JavaScript to manipulate the HTML DOM to display the following information on your page:&lt;br /&gt;
#* Location&lt;br /&gt;
#** City, in a &amp;lt;nowiki&amp;gt;&amp;lt;strong&amp;gt;&amp;lt;/nowiki&amp;gt; tag&lt;br /&gt;
#** State, not in any tag&lt;br /&gt;
#* Humidity&lt;br /&gt;
#* Current Temperature&lt;br /&gt;
#* Image for Tomorrow's Forecast (see [[#Weather Condition Images]] below for more information)&lt;br /&gt;
#* Image for the Day After Tomorrow's Forecast&lt;br /&gt;
# Finally, bind '''fetchWeather()''' to the DOMContentReady event so that your weather widget is automatically initialized when the page is loaded:&lt;br /&gt;
#: &amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;document.addEventListener(&amp;quot;DOMContentReady&amp;quot;, fetchWeather, false);&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Use the following HTML:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;weather&amp;quot; id=&amp;quot;weatherWidget&amp;quot;&amp;gt;&lt;br /&gt;
	&amp;lt;div class=&amp;quot;weather-loc&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
	&amp;lt;div class=&amp;quot;weather-humidity&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
	&amp;lt;div class=&amp;quot;weather-temp&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
	&amp;lt;img class=&amp;quot;weather-tomorrow&amp;quot; /&amp;gt;&lt;br /&gt;
	&amp;lt;img class=&amp;quot;weather-dayaftertomorrow&amp;quot; /&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Include the CSS file from here: http://cloud.sffc1.com/wustl/weather.css&lt;br /&gt;
&lt;br /&gt;
When everything is working, the weather widget should look something like this:&lt;br /&gt;
&lt;br /&gt;
[[File:WeatherWidget.png]]&lt;br /&gt;
&lt;br /&gt;
'''Important:''' The widget in this section needs to work in only Firefox and Chrome.  It does '''''not''''' need to work Internet Explorer.&lt;br /&gt;
&lt;br /&gt;
==== Tips ====&lt;br /&gt;
&lt;br /&gt;
===== JSON Structure =====&lt;br /&gt;
&lt;br /&gt;
The JSON from our server looks like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
   &amp;quot;updated&amp;quot;: &amp;quot;Thu, 11 Oct 2012 5:54 pm CDT&amp;quot;,&lt;br /&gt;
   &amp;quot;location&amp;quot;: {&lt;br /&gt;
      &amp;quot;city&amp;quot;: &amp;quot;St. Louis&amp;quot;,&lt;br /&gt;
      &amp;quot;state&amp;quot;: &amp;quot;MO&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;wind&amp;quot;: {&lt;br /&gt;
      &amp;quot;chill&amp;quot;: &amp;quot;62&amp;quot;,&lt;br /&gt;
      &amp;quot;direction&amp;quot;: &amp;quot;150&amp;quot;,&lt;br /&gt;
      &amp;quot;speed&amp;quot;: &amp;quot;3 mph&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;atmosphere&amp;quot;: {&lt;br /&gt;
      &amp;quot;humidity&amp;quot;: &amp;quot;50&amp;quot;,&lt;br /&gt;
      &amp;quot;visibility&amp;quot;: &amp;quot;10&amp;quot;,&lt;br /&gt;
      &amp;quot;pressure&amp;quot;: &amp;quot;30.12 in&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;current&amp;quot;: {&lt;br /&gt;
      &amp;quot;code&amp;quot;: &amp;quot;28&amp;quot;,&lt;br /&gt;
      &amp;quot;text&amp;quot;: &amp;quot;Mostly Cloudy&amp;quot;,&lt;br /&gt;
      &amp;quot;temp&amp;quot;: &amp;quot;62°F&amp;quot;,&lt;br /&gt;
      &amp;quot;date&amp;quot;: &amp;quot;Thu, 11 Oct 2012 5:54 pm CDT&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;tomorrow&amp;quot;: {&lt;br /&gt;
      &amp;quot;code&amp;quot;: &amp;quot;29&amp;quot;,&lt;br /&gt;
      &amp;quot;text&amp;quot;: &amp;quot;Clouds Early/Clearing Late&amp;quot;,&lt;br /&gt;
      &amp;quot;low&amp;quot;: &amp;quot;45°F&amp;quot;,&lt;br /&gt;
      &amp;quot;high&amp;quot;: &amp;quot;61°F&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;dayafter&amp;quot;: {&lt;br /&gt;
      &amp;quot;code&amp;quot;: &amp;quot;30&amp;quot;,&lt;br /&gt;
      &amp;quot;text&amp;quot;: &amp;quot;Partly Cloudy&amp;quot;,&lt;br /&gt;
      &amp;quot;low&amp;quot;: &amp;quot;53°F&amp;quot;,&lt;br /&gt;
      &amp;quot;high&amp;quot;: &amp;quot;65°F&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;credit&amp;quot;: &amp;quot;http://us.rd.yahoo.com/dailynews/rss/weather/St._Louis__MO/*http://weather.yahoo.com/forecast/USMO0170_f.html&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Weather Condition Images =====&lt;br /&gt;
&lt;br /&gt;
Each day's forecast has a code.  There are images associated with these codes.&lt;br /&gt;
&lt;br /&gt;
You can get images from here: &amp;lt;nowiki&amp;gt;http://us.i1.yimg.com/us.yimg.com/i/us/nws/weather/gr/&amp;lt;/nowiki&amp;gt;'''##'''&amp;lt;nowiki&amp;gt;ds.png&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Replace the '''##''' with the forecast code.  For example, for code 32, the URL would be: http://us.i1.yimg.com/us.yimg.com/i/us/nws/weather/gr/32ds.png&lt;br /&gt;
&lt;br /&gt;
=== jQuery Dialogs ===&lt;br /&gt;
&lt;br /&gt;
Helpful Resource: [http://docs.jquery.com/Main_Page jQuery Documentation] ... Some additional tips: [[jQuery]]&lt;br /&gt;
&lt;br /&gt;
Create a simple page using jQuery dialogs.&lt;br /&gt;
&lt;br /&gt;
* Create a page that has the words &amp;quot;Google&amp;quot; and &amp;quot;Yahoo&amp;quot;.&lt;br /&gt;
* When the user clicks the &amp;quot;Google&amp;quot; text, open a jQuery dialog window with one jQuery dialog button.  If the button is pressed, display the Google logo image (the image can be stored on your web server) on the web page, and if the dialog is closed any other way, do nothing.&lt;br /&gt;
* When the user clicks the &amp;quot;Yahoo&amp;quot; text, open a jQuery dialog window with one jQuery dialog button.  If the button is pressed, display the Yahoo logo image (the image can be stored on your web server) on the web page, and if the dialog is closed any other way, do nothing.&lt;br /&gt;
* Initially there should be no image on the page (i.e., the img should be hidden with the CSS display attribute).  After one of the two images is displayed, if the user clicks on the image, a jQuery dialog box should be opened with one dialog button, and if the button is pressed then the image should be hidden again.  Otherwise, do nothing.&lt;br /&gt;
&lt;br /&gt;
== Group Project ==&lt;br /&gt;
&lt;br /&gt;
You will work in pairs on this project.&lt;br /&gt;
&lt;br /&gt;
'''Important Reminder:''' frequently commit your work to your subversion repository as a backup!&lt;br /&gt;
&lt;br /&gt;
I forgot if I already mentioned this, but '''start early on this project!''' It will take longer than you think, I promise!&lt;br /&gt;
&lt;br /&gt;
=== Calendar ===&lt;br /&gt;
&lt;br /&gt;
Build a simple calendar that allows users to add and remove events dynamically.&lt;br /&gt;
&lt;br /&gt;
You will use JavaScript to process user interactions at the web browser, without ever refreshing the browser after the initial web page load.  You may use a JavaScript library of your choice, including jQuery.  (No extra credit will be given for ''not'' using a JavaScript library.)&lt;br /&gt;
&lt;br /&gt;
Your application should utilize AJAX to run server-side PHP scripts that query your database to save and retrieve information, including user accounts and events.&lt;br /&gt;
&lt;br /&gt;
==== Examples ====&lt;br /&gt;
&lt;br /&gt;
* https://calendar.google.com/&lt;br /&gt;
* http://www.zoho.com/calendar/&lt;br /&gt;
&lt;br /&gt;
==== Requirements ====&lt;br /&gt;
&lt;br /&gt;
* Support a month-by-month view of the calendar.&lt;br /&gt;
*: Show one month at a time, with buttons to move forward or backward.&lt;br /&gt;
*: There should be no limit to how far forward or backward the user can go.&lt;br /&gt;
* Users can register and log in to the website.&lt;br /&gt;
*: You may leverage your MySQL project code and database from last week to get started.&lt;br /&gt;
*: You may alternatively use OpenID for user authentication.  Note that you will still need a Users table in order associate calendar events with a certain OpenID.&lt;br /&gt;
* Unregistered users should see no events on the calendar.&lt;br /&gt;
* Registered users can add events.&lt;br /&gt;
*: All events should have a date and time, but do not need to have a duration.&lt;br /&gt;
*: You do ''not'' need to support recurring events (where you add an event that repeats, for example, every monday).&lt;br /&gt;
* Registered users see only events that they have added.&lt;br /&gt;
* Registered users can delete their events, but not the events of others.&lt;br /&gt;
* All user and event data should be kept in a database.&lt;br /&gt;
* At no time should the main page need to be reloaded.&lt;br /&gt;
*: User registration, user authentication, event addition, and event deletion should all be handled by JavaScript and AJAX requests to your server.&lt;br /&gt;
* Your page needs to work in the versions of Firefox and Chrome installed on the lab computers.&lt;br /&gt;
&lt;br /&gt;
'''Tip:''' Run your database schema by a TA before implementing it.&lt;br /&gt;
&lt;br /&gt;
==== Calendar Helper Library ====&lt;br /&gt;
&lt;br /&gt;
To help you get started with your calendar, we have written some JavaScript helper functions.  The code is available at:&lt;br /&gt;
* Full Version (for you to refer): http://cloud.sffc1.com/wustl/calendar.js&lt;br /&gt;
* Minified Version (to include in your pages): http://cloud.sffc1.com/wustl/calendar.min.js&lt;br /&gt;
&lt;br /&gt;
For example, this is how you would make a button to load the next month and show alerts containing all the days in the weeks contained by that month.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
// For our purposes, we can keep the current month in a variable in the global scope&lt;br /&gt;
var currentMonth = new Month(2012, 9); // October 2012&lt;br /&gt;
&lt;br /&gt;
// Change the month when the &amp;quot;next&amp;quot; button is pressed&lt;br /&gt;
document.getElementById(&amp;quot;next_month_btn&amp;quot;).addEventListener(&amp;quot;click&amp;quot;, function(event){&lt;br /&gt;
	currentMonth = currentMonth.nextMonth(); // Previous month would be currentMonth.prevMonth()&lt;br /&gt;
	updateCalendar(); // Whenever the month is updated, we'll need to re-render the calendar in HTML&lt;br /&gt;
	alert(&amp;quot;The new month is &amp;quot;+currentMonth.month+&amp;quot; &amp;quot;+currentMonth.year);&lt;br /&gt;
}, false);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
// This updateCalendar() function only alerts the dates in the currently specified month.  You need to write&lt;br /&gt;
// it to modify the DOM (optionally using jQuery) to display the days and weeks in the current month.&lt;br /&gt;
function updateCalendar(){&lt;br /&gt;
	var weeks = currentMonth.getWeeks();&lt;br /&gt;
	&lt;br /&gt;
	for(var w in weeks){&lt;br /&gt;
		var days = weeks[w].getDates();&lt;br /&gt;
		// days contains normal JavaScript Date objects.&lt;br /&gt;
		&lt;br /&gt;
		alert(&amp;quot;Week starting on &amp;quot;+days[0]);&lt;br /&gt;
		&lt;br /&gt;
		for(var d in days){&lt;br /&gt;
			// You can see console.log() output in your JavaScript debugging tool, like Firebug,&lt;br /&gt;
			// WebWit Inspector, or Dragonfly.&lt;br /&gt;
			console.log(days[d].toISOString());&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Important:''' JavaScript starts the months of a year, and the days of a week, at index 0.  This means that '''''in JavaScript, January is month 0, and December is month 11.'''''  Our calendar helper functions maintain this JavaScript convention.&lt;br /&gt;
&lt;br /&gt;
=== Web Security and Validation ===&lt;br /&gt;
&lt;br /&gt;
Your project needs to demonstrate that thought was put into web security and best practice.  For more information, see this week's Web Application Security guide: [[Web Application Security, Part 3]]&lt;br /&gt;
&lt;br /&gt;
In particular:&lt;br /&gt;
&lt;br /&gt;
* '''Your application needs to prevent XSS attacks.'''  The easiest way to prevent this is to continue sanitizing ''all'' of your output using '''htmlentities()'''.&lt;br /&gt;
* '''Perform precautionary measures to prevent session hijacking attacks.'''&lt;br /&gt;
*: You should specify your session cookie to be HTTP-Only.  However, for the means of this module, you need not test for user agent consistency.&lt;br /&gt;
* Validate your JavaScript code using [http://www.jshint.com/ JSHint]&lt;br /&gt;
&lt;br /&gt;
You should continue the practices that you have learned in past weeks:&lt;br /&gt;
&lt;br /&gt;
* Pass tokens in forms to prevent CSRF attacks&lt;br /&gt;
* Use prepared queries to prevent SQL Injection attacks&lt;br /&gt;
* If storing passwords in a database, always store them encrypted&lt;br /&gt;
* Your page should validate with no errors through the W3C validator.&lt;br /&gt;
&lt;br /&gt;
== Grading ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;font-size:2em; line-height:2em;&amp;quot;&amp;gt;'''Due Date: _____ (both individual and group)'''&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
!Assignment&lt;br /&gt;
!Points&lt;br /&gt;
|-&lt;br /&gt;
|Calculator&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
|Weather Widget&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|jQuery Dialogs&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
!colspan=&amp;quot;2&amp;quot;|Group Portion:&lt;br /&gt;
|-&lt;br /&gt;
|Calendar month view correct and Move between months (without page reload)&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|User authentication and registration (without page reload)&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Add events (new event shown in calendar without page reload)&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Events added are private and other users cannot see them&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
|Delete events (event removed from calendar without page reload)&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
|-&lt;br /&gt;
|Safe from XSS and Session Hijacking&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|-&lt;br /&gt;
|Validation, CSRF, Salted Passwords, Safe SQL Queries, JSHint&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Creative Portion&lt;br /&gt;
|2&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Total: 10 Points&lt;br /&gt;
&lt;br /&gt;
You must get written permission for your creative portion.  Failure to get written permission will result in one point maximum.  &lt;br /&gt;
&lt;br /&gt;
[[Category:Module 4]]&lt;br /&gt;
[[Category:Modules]]&lt;/div&gt;</summary>
		<author><name>Marc</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=Module_6&amp;diff=802</id>
		<title>Module 6</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=Module_6&amp;diff=802"/>
		<updated>2012-10-14T03:59:56Z</updated>

		<summary type="html">&lt;p&gt;Marc: /* Grading */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In Module 4, you will learn about JavaScript, the prevailing client-side language, and AJAX, a method for performing asynchronous updates to a web page (without refreshing the page).&lt;br /&gt;
&lt;br /&gt;
This article contains your assignments for Module 4.&lt;br /&gt;
&lt;br /&gt;
== Individual Assignments ==&lt;br /&gt;
&lt;br /&gt;
=== JavaScript Calculator ===&lt;br /&gt;
&lt;br /&gt;
In Module 2, you made a calculator using PHP.  Now you will be making one using JavaScript.&lt;br /&gt;
&lt;br /&gt;
Read the JavaScript guide first: [[Javascript and AJAX]]&lt;br /&gt;
&lt;br /&gt;
* The web page should have two input fields and a radio button group for the operation, with the 4 basic math operations represented (add,subtract,multiply,divide).&lt;br /&gt;
* The javascript should monitor all three fields and display the current result whenever the user changes any value in any field, without refreshing the page.&lt;br /&gt;
* The calculator should be completely self-contained; i.e., you should not be making any requests to any other server-side or client-side scripts or web pages after the initial page load.&lt;br /&gt;
&lt;br /&gt;
'''Tip:''' You can embed JavaScript code into an HTML document like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;
// your code here&lt;br /&gt;
&amp;lt;/script&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Tip:''' If your code isn't working the way you expect, use a JavaScript error console.  In Chrome, for example, press Ctrl-Shift-I (or Cmd-Option-I) to open the WebKit inspector.&lt;br /&gt;
&lt;br /&gt;
=== Weather Widget ===&lt;br /&gt;
&lt;br /&gt;
In this section, you will make a web page that displays the weather forecast using AJAX requests to a weather server.  You should complete this section ''without'' using JavaScript libraries like jQuery.&lt;br /&gt;
&lt;br /&gt;
# Make an empty HTML document; name it '''weather.html'''&lt;br /&gt;
#: Refer to the [[HTML and CSS]] guide for the skeleton of an HTML document&lt;br /&gt;
# Define a function in JavaScript; call it '''fetchWeather()'''.  You may write your JavaScript in an embedded script in your head tag.&lt;br /&gt;
# Inside your '''fetchWeather()''' function, make an AJAX request to the weather server.&lt;br /&gt;
#: We have a server that outputs the current weather in JSON format.  The format is documented in the [[#JSON Structure]] section below.&lt;br /&gt;
#: '''URL:''' http://cloud.sffc1.com/wustl/weather_json.php&lt;br /&gt;
#: We kindly thank Yahoo Weather for providing us with up-to-date weather information.&lt;br /&gt;
#* '''Note:''' You normally cannot perform AJAX requests cross-domain.  We have set the &amp;lt;code&amp;gt;Access-Control-Allow-Origin&amp;lt;/code&amp;gt; header on our server to allow requests from your EC2 instances.&lt;br /&gt;
# In your callback, process the JSON and use JavaScript to manipulate the HTML DOM to display the following information on your page:&lt;br /&gt;
#* Location&lt;br /&gt;
#** City, in a &amp;lt;nowiki&amp;gt;&amp;lt;strong&amp;gt;&amp;lt;/nowiki&amp;gt; tag&lt;br /&gt;
#** State, not in any tag&lt;br /&gt;
#* Humidity&lt;br /&gt;
#* Current Temperature&lt;br /&gt;
#* Image for Tomorrow's Forecast (see [[#Weather Condition Images]] below for more information)&lt;br /&gt;
#* Image for the Day After Tomorrow's Forecast&lt;br /&gt;
# Finally, bind '''fetchWeather()''' to the DOMContentReady event so that your weather widget is automatically initialized when the page is loaded:&lt;br /&gt;
#: &amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;document.addEventListener(&amp;quot;DOMContentReady&amp;quot;, fetchWeather, false);&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Use the following HTML:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;weather&amp;quot; id=&amp;quot;weatherWidget&amp;quot;&amp;gt;&lt;br /&gt;
	&amp;lt;div class=&amp;quot;weather-loc&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
	&amp;lt;div class=&amp;quot;weather-humidity&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
	&amp;lt;div class=&amp;quot;weather-temp&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
	&amp;lt;img class=&amp;quot;weather-tomorrow&amp;quot; /&amp;gt;&lt;br /&gt;
	&amp;lt;img class=&amp;quot;weather-dayaftertomorrow&amp;quot; /&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Include the CSS file from here: http://cloud.sffc1.com/wustl/weather.css&lt;br /&gt;
&lt;br /&gt;
When everything is working, the weather widget should look something like this:&lt;br /&gt;
&lt;br /&gt;
[[File:WeatherWidget.png]]&lt;br /&gt;
&lt;br /&gt;
'''Important:''' The widget in this section needs to work in only Firefox and Chrome.  It does '''''not''''' need to work Internet Explorer.&lt;br /&gt;
&lt;br /&gt;
==== Tips ====&lt;br /&gt;
&lt;br /&gt;
===== JSON Structure =====&lt;br /&gt;
&lt;br /&gt;
The JSON from our server looks like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
   &amp;quot;updated&amp;quot;: &amp;quot;Thu, 11 Oct 2012 5:54 pm CDT&amp;quot;,&lt;br /&gt;
   &amp;quot;location&amp;quot;: {&lt;br /&gt;
      &amp;quot;city&amp;quot;: &amp;quot;St. Louis&amp;quot;,&lt;br /&gt;
      &amp;quot;state&amp;quot;: &amp;quot;MO&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;wind&amp;quot;: {&lt;br /&gt;
      &amp;quot;chill&amp;quot;: &amp;quot;62&amp;quot;,&lt;br /&gt;
      &amp;quot;direction&amp;quot;: &amp;quot;150&amp;quot;,&lt;br /&gt;
      &amp;quot;speed&amp;quot;: &amp;quot;3 mph&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;atmosphere&amp;quot;: {&lt;br /&gt;
      &amp;quot;humidity&amp;quot;: &amp;quot;50&amp;quot;,&lt;br /&gt;
      &amp;quot;visibility&amp;quot;: &amp;quot;10&amp;quot;,&lt;br /&gt;
      &amp;quot;pressure&amp;quot;: &amp;quot;30.12 in&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;current&amp;quot;: {&lt;br /&gt;
      &amp;quot;code&amp;quot;: &amp;quot;28&amp;quot;,&lt;br /&gt;
      &amp;quot;text&amp;quot;: &amp;quot;Mostly Cloudy&amp;quot;,&lt;br /&gt;
      &amp;quot;temp&amp;quot;: &amp;quot;62°F&amp;quot;,&lt;br /&gt;
      &amp;quot;date&amp;quot;: &amp;quot;Thu, 11 Oct 2012 5:54 pm CDT&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;tomorrow&amp;quot;: {&lt;br /&gt;
      &amp;quot;code&amp;quot;: &amp;quot;29&amp;quot;,&lt;br /&gt;
      &amp;quot;text&amp;quot;: &amp;quot;Clouds Early/Clearing Late&amp;quot;,&lt;br /&gt;
      &amp;quot;low&amp;quot;: &amp;quot;45°F&amp;quot;,&lt;br /&gt;
      &amp;quot;high&amp;quot;: &amp;quot;61°F&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;dayafter&amp;quot;: {&lt;br /&gt;
      &amp;quot;code&amp;quot;: &amp;quot;30&amp;quot;,&lt;br /&gt;
      &amp;quot;text&amp;quot;: &amp;quot;Partly Cloudy&amp;quot;,&lt;br /&gt;
      &amp;quot;low&amp;quot;: &amp;quot;53°F&amp;quot;,&lt;br /&gt;
      &amp;quot;high&amp;quot;: &amp;quot;65°F&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;credit&amp;quot;: &amp;quot;http://us.rd.yahoo.com/dailynews/rss/weather/St._Louis__MO/*http://weather.yahoo.com/forecast/USMO0170_f.html&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Weather Condition Images =====&lt;br /&gt;
&lt;br /&gt;
Each day's forecast has a code.  There are images associated with these codes.&lt;br /&gt;
&lt;br /&gt;
You can get images from here: &amp;lt;nowiki&amp;gt;http://us.i1.yimg.com/us.yimg.com/i/us/nws/weather/gr/&amp;lt;/nowiki&amp;gt;'''##'''&amp;lt;nowiki&amp;gt;ds.png&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Replace the '''##''' with the forecast code.  For example, for code 32, the URL would be: http://us.i1.yimg.com/us.yimg.com/i/us/nws/weather/gr/32ds.png&lt;br /&gt;
&lt;br /&gt;
=== jQuery Dialogs ===&lt;br /&gt;
&lt;br /&gt;
Helpful Resource: [http://docs.jquery.com/Main_Page jQuery Documentation] ... Some additional tips: [[jQuery]]&lt;br /&gt;
&lt;br /&gt;
Create a simple page using jQuery dialogs.&lt;br /&gt;
&lt;br /&gt;
* Create a page that has the words &amp;quot;Google&amp;quot; and &amp;quot;Yahoo&amp;quot;.&lt;br /&gt;
* When the user clicks the &amp;quot;Google&amp;quot; text, open a jQuery dialog window with one jQuery dialog button.  If the button is pressed, display the Google logo image (the image can be stored on your web server) on the web page, and if the dialog is closed any other way, do nothing.&lt;br /&gt;
* When the user clicks the &amp;quot;Yahoo&amp;quot; text, open a jQuery dialog window with one jQuery dialog button.  If the button is pressed, display the Yahoo logo image (the image can be stored on your web server) on the web page, and if the dialog is closed any other way, do nothing.&lt;br /&gt;
* Initially there should be no image on the page (i.e., the img should be hidden with the CSS display attribute).  After one of the two images is displayed, if the user clicks on the image, a jQuery dialog box should be opened with one dialog button, and if the button is pressed then the image should be hidden again.  Otherwise, do nothing.&lt;br /&gt;
&lt;br /&gt;
== Group Project ==&lt;br /&gt;
&lt;br /&gt;
You will work in pairs on this project.&lt;br /&gt;
&lt;br /&gt;
'''Important Reminder:''' frequently commit your work to your subversion repository as a backup!&lt;br /&gt;
&lt;br /&gt;
I forgot if I already mentioned this, but '''start early on this project!''' It will take longer than you think, I promise!&lt;br /&gt;
&lt;br /&gt;
=== Calendar ===&lt;br /&gt;
&lt;br /&gt;
Build a simple calendar that allows users to add and remove events dynamically.&lt;br /&gt;
&lt;br /&gt;
You will use JavaScript to process user interactions at the web browser, without ever refreshing the browser after the initial web page load.  You may use a JavaScript library of your choice, including jQuery.  (No extra credit will be given for ''not'' using a JavaScript library.)&lt;br /&gt;
&lt;br /&gt;
Your application should utilize AJAX to run server-side PHP scripts that query your database to save and retrieve information, including user accounts and events.&lt;br /&gt;
&lt;br /&gt;
==== Examples ====&lt;br /&gt;
&lt;br /&gt;
* https://calendar.google.com/&lt;br /&gt;
* http://www.zoho.com/calendar/&lt;br /&gt;
&lt;br /&gt;
==== Requirements ====&lt;br /&gt;
&lt;br /&gt;
* Support a month-by-month view of the calendar.&lt;br /&gt;
*: Show one month at a time, with buttons to move forward or backward.&lt;br /&gt;
*: There should be no limit to how far forward or backward the user can go.&lt;br /&gt;
* Users can register and log in to the website.&lt;br /&gt;
*: You may leverage your MySQL project code and database from last week to get started.&lt;br /&gt;
*: You may alternatively use OpenID for user authentication.  Note that you will still need a Users table in order associate calendar events with a certain OpenID.&lt;br /&gt;
* Unregistered users should see no events on the calendar.&lt;br /&gt;
* Registered users can add events.&lt;br /&gt;
*: All events should have a date and time, but do not need to have a duration.&lt;br /&gt;
*: You do ''not'' need to support recurring events (where you add an event that repeats, for example, every monday).&lt;br /&gt;
* Registered users see only events that they have added.&lt;br /&gt;
* Registered users can delete their events, but not the events of others.&lt;br /&gt;
* All user and event data should be kept in a database.&lt;br /&gt;
* At no time should the main page need to be reloaded.&lt;br /&gt;
*: User registration, user authentication, event addition, and event deletion should all be handled by JavaScript and AJAX requests to your server.&lt;br /&gt;
* Your page needs to work in the versions of Firefox and Chrome installed on the lab computers.&lt;br /&gt;
&lt;br /&gt;
'''Tip:''' Run your database schema by a TA before implementing it.&lt;br /&gt;
&lt;br /&gt;
==== Calendar Helper Library ====&lt;br /&gt;
&lt;br /&gt;
To help you get started with your calendar, we have written some JavaScript helper functions.  The code is available at:&lt;br /&gt;
* Full Version (for you to refer): http://cloud.sffc1.com/wustl/calendar.js&lt;br /&gt;
* Minified Version (to include in your pages): http://cloud.sffc1.com/wustl/calendar.min.js&lt;br /&gt;
&lt;br /&gt;
For example, this is how you would make a button to load the next month and show alerts containing all the days in the weeks contained by that month.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
// For our purposes, we can keep the current month in a variable in the global scope&lt;br /&gt;
var currentMonth = new Month(2012, 9); // October 2012&lt;br /&gt;
&lt;br /&gt;
// Change the month when the &amp;quot;next&amp;quot; button is pressed&lt;br /&gt;
document.getElementById(&amp;quot;next_month_btn&amp;quot;).addEventListener(&amp;quot;click&amp;quot;, function(event){&lt;br /&gt;
	currentMonth = currentMonth.nextMonth(); // Previous month would be currentMonth.prevMonth()&lt;br /&gt;
	updateCalendar(); // Whenever the month is updated, we'll need to re-render the calendar in HTML&lt;br /&gt;
	alert(&amp;quot;The new month is &amp;quot;+currentMonth.month+&amp;quot; &amp;quot;+currentMonth.year);&lt;br /&gt;
}, false);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
// This updateCalendar() function only alerts the dates in the currently specified month.  You need to write&lt;br /&gt;
// it to modify the DOM (optionally using jQuery) to display the days and weeks in the current month.&lt;br /&gt;
function updateCalendar(){&lt;br /&gt;
	var weeks = currentMonth.getWeeks();&lt;br /&gt;
	&lt;br /&gt;
	for(var w in weeks){&lt;br /&gt;
		var days = weeks[w].getDates();&lt;br /&gt;
		// days contains normal JavaScript Date objects.&lt;br /&gt;
		&lt;br /&gt;
		alert(&amp;quot;Week starting on &amp;quot;+days[0]);&lt;br /&gt;
		&lt;br /&gt;
		for(var d in days){&lt;br /&gt;
			// You can see console.log() output in your JavaScript debugging tool, like Firebug,&lt;br /&gt;
			// WebWit Inspector, or Dragonfly.&lt;br /&gt;
			console.log(days[d].toISOString());&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Important:''' JavaScript starts the months of a year, and the days of a week, at index 0.  This means that '''''in JavaScript, January is month 0, and December is month 11.'''''  Our calendar helper functions maintain this JavaScript convention.&lt;br /&gt;
&lt;br /&gt;
=== Web Security and Validation ===&lt;br /&gt;
&lt;br /&gt;
Your project needs to demonstrate that thought was put into web security and best practice.  For more information, see this week's Web Application Security guide: [[Web Application Security, Part 3]]&lt;br /&gt;
&lt;br /&gt;
In particular:&lt;br /&gt;
&lt;br /&gt;
* '''Your application needs to prevent XSS attacks.'''  The easiest way to prevent this is to continue sanitizing ''all'' of your output using '''htmlentities()'''.&lt;br /&gt;
* '''Perform precautionary measures to prevent session hijacking attacks.'''&lt;br /&gt;
*: You should specify your session cookie to be HTTP-Only.  However, for the means of this module, you need not test for user agent consistency.&lt;br /&gt;
* Validate your JavaScript code using [http://www.jshint.com/ JSHint]&lt;br /&gt;
&lt;br /&gt;
You should continue the practices that you have learned in past weeks:&lt;br /&gt;
&lt;br /&gt;
* Pass tokens in forms to prevent CSRF attacks&lt;br /&gt;
* Use prepared queries to prevent SQL Injection attacks&lt;br /&gt;
* If storing passwords in a database, always store them encrypted&lt;br /&gt;
* Your page should validate with no errors through the W3C validator.&lt;br /&gt;
&lt;br /&gt;
== Grading ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;font-size:2em; line-height:2em;&amp;quot;&amp;gt;'''Due Date: _____ (both individual and group)'''&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
!Assignment&lt;br /&gt;
!Points&lt;br /&gt;
|-&lt;br /&gt;
|Calculator&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
|Weather Widget&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|jQuery Dialogs&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
!colspan=&amp;quot;2&amp;quot;|Group Portion:&lt;br /&gt;
|-&lt;br /&gt;
|Calendar month view correct and Move between months (without page reload)&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|User authentication and registration (without page reload)&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Add events (new event shown in calendar without page reload)&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Events added are private and other users cannot see them&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
|Delete events (event removed from calendar without page reload)&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
|-&lt;br /&gt;
|Safe from XSS and Session Hijacking&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|-&lt;br /&gt;
|Validation, CSRF, Salted Passwords, Safe SQL Queries, JSHint&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Creative Portion&lt;br /&gt;
|2&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Total: 10 Points&lt;br /&gt;
&lt;br /&gt;
You must get written permission for the creative portion.  Failure to get written permission will result in one point maximum.  &lt;br /&gt;
&lt;br /&gt;
[[Category:Module 4]]&lt;br /&gt;
[[Category:Modules]]&lt;/div&gt;</summary>
		<author><name>Marc</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=Module_6&amp;diff=801</id>
		<title>Module 6</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=Module_6&amp;diff=801"/>
		<updated>2012-10-14T03:59:47Z</updated>

		<summary type="html">&lt;p&gt;Marc: /* Grading */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In Module 4, you will learn about JavaScript, the prevailing client-side language, and AJAX, a method for performing asynchronous updates to a web page (without refreshing the page).&lt;br /&gt;
&lt;br /&gt;
This article contains your assignments for Module 4.&lt;br /&gt;
&lt;br /&gt;
== Individual Assignments ==&lt;br /&gt;
&lt;br /&gt;
=== JavaScript Calculator ===&lt;br /&gt;
&lt;br /&gt;
In Module 2, you made a calculator using PHP.  Now you will be making one using JavaScript.&lt;br /&gt;
&lt;br /&gt;
Read the JavaScript guide first: [[Javascript and AJAX]]&lt;br /&gt;
&lt;br /&gt;
* The web page should have two input fields and a radio button group for the operation, with the 4 basic math operations represented (add,subtract,multiply,divide).&lt;br /&gt;
* The javascript should monitor all three fields and display the current result whenever the user changes any value in any field, without refreshing the page.&lt;br /&gt;
* The calculator should be completely self-contained; i.e., you should not be making any requests to any other server-side or client-side scripts or web pages after the initial page load.&lt;br /&gt;
&lt;br /&gt;
'''Tip:''' You can embed JavaScript code into an HTML document like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;
// your code here&lt;br /&gt;
&amp;lt;/script&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Tip:''' If your code isn't working the way you expect, use a JavaScript error console.  In Chrome, for example, press Ctrl-Shift-I (or Cmd-Option-I) to open the WebKit inspector.&lt;br /&gt;
&lt;br /&gt;
=== Weather Widget ===&lt;br /&gt;
&lt;br /&gt;
In this section, you will make a web page that displays the weather forecast using AJAX requests to a weather server.  You should complete this section ''without'' using JavaScript libraries like jQuery.&lt;br /&gt;
&lt;br /&gt;
# Make an empty HTML document; name it '''weather.html'''&lt;br /&gt;
#: Refer to the [[HTML and CSS]] guide for the skeleton of an HTML document&lt;br /&gt;
# Define a function in JavaScript; call it '''fetchWeather()'''.  You may write your JavaScript in an embedded script in your head tag.&lt;br /&gt;
# Inside your '''fetchWeather()''' function, make an AJAX request to the weather server.&lt;br /&gt;
#: We have a server that outputs the current weather in JSON format.  The format is documented in the [[#JSON Structure]] section below.&lt;br /&gt;
#: '''URL:''' http://cloud.sffc1.com/wustl/weather_json.php&lt;br /&gt;
#: We kindly thank Yahoo Weather for providing us with up-to-date weather information.&lt;br /&gt;
#* '''Note:''' You normally cannot perform AJAX requests cross-domain.  We have set the &amp;lt;code&amp;gt;Access-Control-Allow-Origin&amp;lt;/code&amp;gt; header on our server to allow requests from your EC2 instances.&lt;br /&gt;
# In your callback, process the JSON and use JavaScript to manipulate the HTML DOM to display the following information on your page:&lt;br /&gt;
#* Location&lt;br /&gt;
#** City, in a &amp;lt;nowiki&amp;gt;&amp;lt;strong&amp;gt;&amp;lt;/nowiki&amp;gt; tag&lt;br /&gt;
#** State, not in any tag&lt;br /&gt;
#* Humidity&lt;br /&gt;
#* Current Temperature&lt;br /&gt;
#* Image for Tomorrow's Forecast (see [[#Weather Condition Images]] below for more information)&lt;br /&gt;
#* Image for the Day After Tomorrow's Forecast&lt;br /&gt;
# Finally, bind '''fetchWeather()''' to the DOMContentReady event so that your weather widget is automatically initialized when the page is loaded:&lt;br /&gt;
#: &amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;document.addEventListener(&amp;quot;DOMContentReady&amp;quot;, fetchWeather, false);&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Use the following HTML:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;weather&amp;quot; id=&amp;quot;weatherWidget&amp;quot;&amp;gt;&lt;br /&gt;
	&amp;lt;div class=&amp;quot;weather-loc&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
	&amp;lt;div class=&amp;quot;weather-humidity&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
	&amp;lt;div class=&amp;quot;weather-temp&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
	&amp;lt;img class=&amp;quot;weather-tomorrow&amp;quot; /&amp;gt;&lt;br /&gt;
	&amp;lt;img class=&amp;quot;weather-dayaftertomorrow&amp;quot; /&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Include the CSS file from here: http://cloud.sffc1.com/wustl/weather.css&lt;br /&gt;
&lt;br /&gt;
When everything is working, the weather widget should look something like this:&lt;br /&gt;
&lt;br /&gt;
[[File:WeatherWidget.png]]&lt;br /&gt;
&lt;br /&gt;
'''Important:''' The widget in this section needs to work in only Firefox and Chrome.  It does '''''not''''' need to work Internet Explorer.&lt;br /&gt;
&lt;br /&gt;
==== Tips ====&lt;br /&gt;
&lt;br /&gt;
===== JSON Structure =====&lt;br /&gt;
&lt;br /&gt;
The JSON from our server looks like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
   &amp;quot;updated&amp;quot;: &amp;quot;Thu, 11 Oct 2012 5:54 pm CDT&amp;quot;,&lt;br /&gt;
   &amp;quot;location&amp;quot;: {&lt;br /&gt;
      &amp;quot;city&amp;quot;: &amp;quot;St. Louis&amp;quot;,&lt;br /&gt;
      &amp;quot;state&amp;quot;: &amp;quot;MO&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;wind&amp;quot;: {&lt;br /&gt;
      &amp;quot;chill&amp;quot;: &amp;quot;62&amp;quot;,&lt;br /&gt;
      &amp;quot;direction&amp;quot;: &amp;quot;150&amp;quot;,&lt;br /&gt;
      &amp;quot;speed&amp;quot;: &amp;quot;3 mph&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;atmosphere&amp;quot;: {&lt;br /&gt;
      &amp;quot;humidity&amp;quot;: &amp;quot;50&amp;quot;,&lt;br /&gt;
      &amp;quot;visibility&amp;quot;: &amp;quot;10&amp;quot;,&lt;br /&gt;
      &amp;quot;pressure&amp;quot;: &amp;quot;30.12 in&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;current&amp;quot;: {&lt;br /&gt;
      &amp;quot;code&amp;quot;: &amp;quot;28&amp;quot;,&lt;br /&gt;
      &amp;quot;text&amp;quot;: &amp;quot;Mostly Cloudy&amp;quot;,&lt;br /&gt;
      &amp;quot;temp&amp;quot;: &amp;quot;62°F&amp;quot;,&lt;br /&gt;
      &amp;quot;date&amp;quot;: &amp;quot;Thu, 11 Oct 2012 5:54 pm CDT&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;tomorrow&amp;quot;: {&lt;br /&gt;
      &amp;quot;code&amp;quot;: &amp;quot;29&amp;quot;,&lt;br /&gt;
      &amp;quot;text&amp;quot;: &amp;quot;Clouds Early/Clearing Late&amp;quot;,&lt;br /&gt;
      &amp;quot;low&amp;quot;: &amp;quot;45°F&amp;quot;,&lt;br /&gt;
      &amp;quot;high&amp;quot;: &amp;quot;61°F&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;dayafter&amp;quot;: {&lt;br /&gt;
      &amp;quot;code&amp;quot;: &amp;quot;30&amp;quot;,&lt;br /&gt;
      &amp;quot;text&amp;quot;: &amp;quot;Partly Cloudy&amp;quot;,&lt;br /&gt;
      &amp;quot;low&amp;quot;: &amp;quot;53°F&amp;quot;,&lt;br /&gt;
      &amp;quot;high&amp;quot;: &amp;quot;65°F&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;credit&amp;quot;: &amp;quot;http://us.rd.yahoo.com/dailynews/rss/weather/St._Louis__MO/*http://weather.yahoo.com/forecast/USMO0170_f.html&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Weather Condition Images =====&lt;br /&gt;
&lt;br /&gt;
Each day's forecast has a code.  There are images associated with these codes.&lt;br /&gt;
&lt;br /&gt;
You can get images from here: &amp;lt;nowiki&amp;gt;http://us.i1.yimg.com/us.yimg.com/i/us/nws/weather/gr/&amp;lt;/nowiki&amp;gt;'''##'''&amp;lt;nowiki&amp;gt;ds.png&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Replace the '''##''' with the forecast code.  For example, for code 32, the URL would be: http://us.i1.yimg.com/us.yimg.com/i/us/nws/weather/gr/32ds.png&lt;br /&gt;
&lt;br /&gt;
=== jQuery Dialogs ===&lt;br /&gt;
&lt;br /&gt;
Helpful Resource: [http://docs.jquery.com/Main_Page jQuery Documentation] ... Some additional tips: [[jQuery]]&lt;br /&gt;
&lt;br /&gt;
Create a simple page using jQuery dialogs.&lt;br /&gt;
&lt;br /&gt;
* Create a page that has the words &amp;quot;Google&amp;quot; and &amp;quot;Yahoo&amp;quot;.&lt;br /&gt;
* When the user clicks the &amp;quot;Google&amp;quot; text, open a jQuery dialog window with one jQuery dialog button.  If the button is pressed, display the Google logo image (the image can be stored on your web server) on the web page, and if the dialog is closed any other way, do nothing.&lt;br /&gt;
* When the user clicks the &amp;quot;Yahoo&amp;quot; text, open a jQuery dialog window with one jQuery dialog button.  If the button is pressed, display the Yahoo logo image (the image can be stored on your web server) on the web page, and if the dialog is closed any other way, do nothing.&lt;br /&gt;
* Initially there should be no image on the page (i.e., the img should be hidden with the CSS display attribute).  After one of the two images is displayed, if the user clicks on the image, a jQuery dialog box should be opened with one dialog button, and if the button is pressed then the image should be hidden again.  Otherwise, do nothing.&lt;br /&gt;
&lt;br /&gt;
== Group Project ==&lt;br /&gt;
&lt;br /&gt;
You will work in pairs on this project.&lt;br /&gt;
&lt;br /&gt;
'''Important Reminder:''' frequently commit your work to your subversion repository as a backup!&lt;br /&gt;
&lt;br /&gt;
I forgot if I already mentioned this, but '''start early on this project!''' It will take longer than you think, I promise!&lt;br /&gt;
&lt;br /&gt;
=== Calendar ===&lt;br /&gt;
&lt;br /&gt;
Build a simple calendar that allows users to add and remove events dynamically.&lt;br /&gt;
&lt;br /&gt;
You will use JavaScript to process user interactions at the web browser, without ever refreshing the browser after the initial web page load.  You may use a JavaScript library of your choice, including jQuery.  (No extra credit will be given for ''not'' using a JavaScript library.)&lt;br /&gt;
&lt;br /&gt;
Your application should utilize AJAX to run server-side PHP scripts that query your database to save and retrieve information, including user accounts and events.&lt;br /&gt;
&lt;br /&gt;
==== Examples ====&lt;br /&gt;
&lt;br /&gt;
* https://calendar.google.com/&lt;br /&gt;
* http://www.zoho.com/calendar/&lt;br /&gt;
&lt;br /&gt;
==== Requirements ====&lt;br /&gt;
&lt;br /&gt;
* Support a month-by-month view of the calendar.&lt;br /&gt;
*: Show one month at a time, with buttons to move forward or backward.&lt;br /&gt;
*: There should be no limit to how far forward or backward the user can go.&lt;br /&gt;
* Users can register and log in to the website.&lt;br /&gt;
*: You may leverage your MySQL project code and database from last week to get started.&lt;br /&gt;
*: You may alternatively use OpenID for user authentication.  Note that you will still need a Users table in order associate calendar events with a certain OpenID.&lt;br /&gt;
* Unregistered users should see no events on the calendar.&lt;br /&gt;
* Registered users can add events.&lt;br /&gt;
*: All events should have a date and time, but do not need to have a duration.&lt;br /&gt;
*: You do ''not'' need to support recurring events (where you add an event that repeats, for example, every monday).&lt;br /&gt;
* Registered users see only events that they have added.&lt;br /&gt;
* Registered users can delete their events, but not the events of others.&lt;br /&gt;
* All user and event data should be kept in a database.&lt;br /&gt;
* At no time should the main page need to be reloaded.&lt;br /&gt;
*: User registration, user authentication, event addition, and event deletion should all be handled by JavaScript and AJAX requests to your server.&lt;br /&gt;
* Your page needs to work in the versions of Firefox and Chrome installed on the lab computers.&lt;br /&gt;
&lt;br /&gt;
'''Tip:''' Run your database schema by a TA before implementing it.&lt;br /&gt;
&lt;br /&gt;
==== Calendar Helper Library ====&lt;br /&gt;
&lt;br /&gt;
To help you get started with your calendar, we have written some JavaScript helper functions.  The code is available at:&lt;br /&gt;
* Full Version (for you to refer): http://cloud.sffc1.com/wustl/calendar.js&lt;br /&gt;
* Minified Version (to include in your pages): http://cloud.sffc1.com/wustl/calendar.min.js&lt;br /&gt;
&lt;br /&gt;
For example, this is how you would make a button to load the next month and show alerts containing all the days in the weeks contained by that month.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
// For our purposes, we can keep the current month in a variable in the global scope&lt;br /&gt;
var currentMonth = new Month(2012, 9); // October 2012&lt;br /&gt;
&lt;br /&gt;
// Change the month when the &amp;quot;next&amp;quot; button is pressed&lt;br /&gt;
document.getElementById(&amp;quot;next_month_btn&amp;quot;).addEventListener(&amp;quot;click&amp;quot;, function(event){&lt;br /&gt;
	currentMonth = currentMonth.nextMonth(); // Previous month would be currentMonth.prevMonth()&lt;br /&gt;
	updateCalendar(); // Whenever the month is updated, we'll need to re-render the calendar in HTML&lt;br /&gt;
	alert(&amp;quot;The new month is &amp;quot;+currentMonth.month+&amp;quot; &amp;quot;+currentMonth.year);&lt;br /&gt;
}, false);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
// This updateCalendar() function only alerts the dates in the currently specified month.  You need to write&lt;br /&gt;
// it to modify the DOM (optionally using jQuery) to display the days and weeks in the current month.&lt;br /&gt;
function updateCalendar(){&lt;br /&gt;
	var weeks = currentMonth.getWeeks();&lt;br /&gt;
	&lt;br /&gt;
	for(var w in weeks){&lt;br /&gt;
		var days = weeks[w].getDates();&lt;br /&gt;
		// days contains normal JavaScript Date objects.&lt;br /&gt;
		&lt;br /&gt;
		alert(&amp;quot;Week starting on &amp;quot;+days[0]);&lt;br /&gt;
		&lt;br /&gt;
		for(var d in days){&lt;br /&gt;
			// You can see console.log() output in your JavaScript debugging tool, like Firebug,&lt;br /&gt;
			// WebWit Inspector, or Dragonfly.&lt;br /&gt;
			console.log(days[d].toISOString());&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Important:''' JavaScript starts the months of a year, and the days of a week, at index 0.  This means that '''''in JavaScript, January is month 0, and December is month 11.'''''  Our calendar helper functions maintain this JavaScript convention.&lt;br /&gt;
&lt;br /&gt;
=== Web Security and Validation ===&lt;br /&gt;
&lt;br /&gt;
Your project needs to demonstrate that thought was put into web security and best practice.  For more information, see this week's Web Application Security guide: [[Web Application Security, Part 3]]&lt;br /&gt;
&lt;br /&gt;
In particular:&lt;br /&gt;
&lt;br /&gt;
* '''Your application needs to prevent XSS attacks.'''  The easiest way to prevent this is to continue sanitizing ''all'' of your output using '''htmlentities()'''.&lt;br /&gt;
* '''Perform precautionary measures to prevent session hijacking attacks.'''&lt;br /&gt;
*: You should specify your session cookie to be HTTP-Only.  However, for the means of this module, you need not test for user agent consistency.&lt;br /&gt;
* Validate your JavaScript code using [http://www.jshint.com/ JSHint]&lt;br /&gt;
&lt;br /&gt;
You should continue the practices that you have learned in past weeks:&lt;br /&gt;
&lt;br /&gt;
* Pass tokens in forms to prevent CSRF attacks&lt;br /&gt;
* Use prepared queries to prevent SQL Injection attacks&lt;br /&gt;
* If storing passwords in a database, always store them encrypted&lt;br /&gt;
* Your page should validate with no errors through the W3C validator.&lt;br /&gt;
&lt;br /&gt;
== Grading ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;font-size:2em; line-height:2em;&amp;quot;&amp;gt;'''Due Date: _____ (both individual and group)'''&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
!Assignment&lt;br /&gt;
!Points&lt;br /&gt;
|-&lt;br /&gt;
|Calculator&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
|Weather Widget&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|jQuery Dialogs&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
!colspan=&amp;quot;2&amp;quot;|Group Portion:&lt;br /&gt;
|-&lt;br /&gt;
|Calendar month view correct and Move between months (without page reload)&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|User authentication and registration (without page reload)&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Add events (new event shown in calendar without page reload)&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Events added are private and other users cannot see them&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
|Delete events (event removed from calendar without page reload)&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
|-&lt;br /&gt;
|Safe from XSS and Session Hijacking&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|-&lt;br /&gt;
|Validation, CSRF, Salted Passwords, Safe SQL Queries, JSHint&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Creative Portion&lt;br /&gt;
|2&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Total: 10 Points&lt;br /&gt;
You must get written permission for the creative portion.  Failure to get written permission will result in one point maximum.  &lt;br /&gt;
&lt;br /&gt;
[[Category:Module 4]]&lt;br /&gt;
[[Category:Modules]]&lt;/div&gt;</summary>
		<author><name>Marc</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=Module_6&amp;diff=800</id>
		<title>Module 6</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=Module_6&amp;diff=800"/>
		<updated>2012-10-14T03:59:38Z</updated>

		<summary type="html">&lt;p&gt;Marc: /* Grading */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In Module 4, you will learn about JavaScript, the prevailing client-side language, and AJAX, a method for performing asynchronous updates to a web page (without refreshing the page).&lt;br /&gt;
&lt;br /&gt;
This article contains your assignments for Module 4.&lt;br /&gt;
&lt;br /&gt;
== Individual Assignments ==&lt;br /&gt;
&lt;br /&gt;
=== JavaScript Calculator ===&lt;br /&gt;
&lt;br /&gt;
In Module 2, you made a calculator using PHP.  Now you will be making one using JavaScript.&lt;br /&gt;
&lt;br /&gt;
Read the JavaScript guide first: [[Javascript and AJAX]]&lt;br /&gt;
&lt;br /&gt;
* The web page should have two input fields and a radio button group for the operation, with the 4 basic math operations represented (add,subtract,multiply,divide).&lt;br /&gt;
* The javascript should monitor all three fields and display the current result whenever the user changes any value in any field, without refreshing the page.&lt;br /&gt;
* The calculator should be completely self-contained; i.e., you should not be making any requests to any other server-side or client-side scripts or web pages after the initial page load.&lt;br /&gt;
&lt;br /&gt;
'''Tip:''' You can embed JavaScript code into an HTML document like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;
// your code here&lt;br /&gt;
&amp;lt;/script&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Tip:''' If your code isn't working the way you expect, use a JavaScript error console.  In Chrome, for example, press Ctrl-Shift-I (or Cmd-Option-I) to open the WebKit inspector.&lt;br /&gt;
&lt;br /&gt;
=== Weather Widget ===&lt;br /&gt;
&lt;br /&gt;
In this section, you will make a web page that displays the weather forecast using AJAX requests to a weather server.  You should complete this section ''without'' using JavaScript libraries like jQuery.&lt;br /&gt;
&lt;br /&gt;
# Make an empty HTML document; name it '''weather.html'''&lt;br /&gt;
#: Refer to the [[HTML and CSS]] guide for the skeleton of an HTML document&lt;br /&gt;
# Define a function in JavaScript; call it '''fetchWeather()'''.  You may write your JavaScript in an embedded script in your head tag.&lt;br /&gt;
# Inside your '''fetchWeather()''' function, make an AJAX request to the weather server.&lt;br /&gt;
#: We have a server that outputs the current weather in JSON format.  The format is documented in the [[#JSON Structure]] section below.&lt;br /&gt;
#: '''URL:''' http://cloud.sffc1.com/wustl/weather_json.php&lt;br /&gt;
#: We kindly thank Yahoo Weather for providing us with up-to-date weather information.&lt;br /&gt;
#* '''Note:''' You normally cannot perform AJAX requests cross-domain.  We have set the &amp;lt;code&amp;gt;Access-Control-Allow-Origin&amp;lt;/code&amp;gt; header on our server to allow requests from your EC2 instances.&lt;br /&gt;
# In your callback, process the JSON and use JavaScript to manipulate the HTML DOM to display the following information on your page:&lt;br /&gt;
#* Location&lt;br /&gt;
#** City, in a &amp;lt;nowiki&amp;gt;&amp;lt;strong&amp;gt;&amp;lt;/nowiki&amp;gt; tag&lt;br /&gt;
#** State, not in any tag&lt;br /&gt;
#* Humidity&lt;br /&gt;
#* Current Temperature&lt;br /&gt;
#* Image for Tomorrow's Forecast (see [[#Weather Condition Images]] below for more information)&lt;br /&gt;
#* Image for the Day After Tomorrow's Forecast&lt;br /&gt;
# Finally, bind '''fetchWeather()''' to the DOMContentReady event so that your weather widget is automatically initialized when the page is loaded:&lt;br /&gt;
#: &amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;document.addEventListener(&amp;quot;DOMContentReady&amp;quot;, fetchWeather, false);&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Use the following HTML:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;weather&amp;quot; id=&amp;quot;weatherWidget&amp;quot;&amp;gt;&lt;br /&gt;
	&amp;lt;div class=&amp;quot;weather-loc&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
	&amp;lt;div class=&amp;quot;weather-humidity&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
	&amp;lt;div class=&amp;quot;weather-temp&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
	&amp;lt;img class=&amp;quot;weather-tomorrow&amp;quot; /&amp;gt;&lt;br /&gt;
	&amp;lt;img class=&amp;quot;weather-dayaftertomorrow&amp;quot; /&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Include the CSS file from here: http://cloud.sffc1.com/wustl/weather.css&lt;br /&gt;
&lt;br /&gt;
When everything is working, the weather widget should look something like this:&lt;br /&gt;
&lt;br /&gt;
[[File:WeatherWidget.png]]&lt;br /&gt;
&lt;br /&gt;
'''Important:''' The widget in this section needs to work in only Firefox and Chrome.  It does '''''not''''' need to work Internet Explorer.&lt;br /&gt;
&lt;br /&gt;
==== Tips ====&lt;br /&gt;
&lt;br /&gt;
===== JSON Structure =====&lt;br /&gt;
&lt;br /&gt;
The JSON from our server looks like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
   &amp;quot;updated&amp;quot;: &amp;quot;Thu, 11 Oct 2012 5:54 pm CDT&amp;quot;,&lt;br /&gt;
   &amp;quot;location&amp;quot;: {&lt;br /&gt;
      &amp;quot;city&amp;quot;: &amp;quot;St. Louis&amp;quot;,&lt;br /&gt;
      &amp;quot;state&amp;quot;: &amp;quot;MO&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;wind&amp;quot;: {&lt;br /&gt;
      &amp;quot;chill&amp;quot;: &amp;quot;62&amp;quot;,&lt;br /&gt;
      &amp;quot;direction&amp;quot;: &amp;quot;150&amp;quot;,&lt;br /&gt;
      &amp;quot;speed&amp;quot;: &amp;quot;3 mph&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;atmosphere&amp;quot;: {&lt;br /&gt;
      &amp;quot;humidity&amp;quot;: &amp;quot;50&amp;quot;,&lt;br /&gt;
      &amp;quot;visibility&amp;quot;: &amp;quot;10&amp;quot;,&lt;br /&gt;
      &amp;quot;pressure&amp;quot;: &amp;quot;30.12 in&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;current&amp;quot;: {&lt;br /&gt;
      &amp;quot;code&amp;quot;: &amp;quot;28&amp;quot;,&lt;br /&gt;
      &amp;quot;text&amp;quot;: &amp;quot;Mostly Cloudy&amp;quot;,&lt;br /&gt;
      &amp;quot;temp&amp;quot;: &amp;quot;62°F&amp;quot;,&lt;br /&gt;
      &amp;quot;date&amp;quot;: &amp;quot;Thu, 11 Oct 2012 5:54 pm CDT&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;tomorrow&amp;quot;: {&lt;br /&gt;
      &amp;quot;code&amp;quot;: &amp;quot;29&amp;quot;,&lt;br /&gt;
      &amp;quot;text&amp;quot;: &amp;quot;Clouds Early/Clearing Late&amp;quot;,&lt;br /&gt;
      &amp;quot;low&amp;quot;: &amp;quot;45°F&amp;quot;,&lt;br /&gt;
      &amp;quot;high&amp;quot;: &amp;quot;61°F&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;dayafter&amp;quot;: {&lt;br /&gt;
      &amp;quot;code&amp;quot;: &amp;quot;30&amp;quot;,&lt;br /&gt;
      &amp;quot;text&amp;quot;: &amp;quot;Partly Cloudy&amp;quot;,&lt;br /&gt;
      &amp;quot;low&amp;quot;: &amp;quot;53°F&amp;quot;,&lt;br /&gt;
      &amp;quot;high&amp;quot;: &amp;quot;65°F&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;credit&amp;quot;: &amp;quot;http://us.rd.yahoo.com/dailynews/rss/weather/St._Louis__MO/*http://weather.yahoo.com/forecast/USMO0170_f.html&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Weather Condition Images =====&lt;br /&gt;
&lt;br /&gt;
Each day's forecast has a code.  There are images associated with these codes.&lt;br /&gt;
&lt;br /&gt;
You can get images from here: &amp;lt;nowiki&amp;gt;http://us.i1.yimg.com/us.yimg.com/i/us/nws/weather/gr/&amp;lt;/nowiki&amp;gt;'''##'''&amp;lt;nowiki&amp;gt;ds.png&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Replace the '''##''' with the forecast code.  For example, for code 32, the URL would be: http://us.i1.yimg.com/us.yimg.com/i/us/nws/weather/gr/32ds.png&lt;br /&gt;
&lt;br /&gt;
=== jQuery Dialogs ===&lt;br /&gt;
&lt;br /&gt;
Helpful Resource: [http://docs.jquery.com/Main_Page jQuery Documentation] ... Some additional tips: [[jQuery]]&lt;br /&gt;
&lt;br /&gt;
Create a simple page using jQuery dialogs.&lt;br /&gt;
&lt;br /&gt;
* Create a page that has the words &amp;quot;Google&amp;quot; and &amp;quot;Yahoo&amp;quot;.&lt;br /&gt;
* When the user clicks the &amp;quot;Google&amp;quot; text, open a jQuery dialog window with one jQuery dialog button.  If the button is pressed, display the Google logo image (the image can be stored on your web server) on the web page, and if the dialog is closed any other way, do nothing.&lt;br /&gt;
* When the user clicks the &amp;quot;Yahoo&amp;quot; text, open a jQuery dialog window with one jQuery dialog button.  If the button is pressed, display the Yahoo logo image (the image can be stored on your web server) on the web page, and if the dialog is closed any other way, do nothing.&lt;br /&gt;
* Initially there should be no image on the page (i.e., the img should be hidden with the CSS display attribute).  After one of the two images is displayed, if the user clicks on the image, a jQuery dialog box should be opened with one dialog button, and if the button is pressed then the image should be hidden again.  Otherwise, do nothing.&lt;br /&gt;
&lt;br /&gt;
== Group Project ==&lt;br /&gt;
&lt;br /&gt;
You will work in pairs on this project.&lt;br /&gt;
&lt;br /&gt;
'''Important Reminder:''' frequently commit your work to your subversion repository as a backup!&lt;br /&gt;
&lt;br /&gt;
I forgot if I already mentioned this, but '''start early on this project!''' It will take longer than you think, I promise!&lt;br /&gt;
&lt;br /&gt;
=== Calendar ===&lt;br /&gt;
&lt;br /&gt;
Build a simple calendar that allows users to add and remove events dynamically.&lt;br /&gt;
&lt;br /&gt;
You will use JavaScript to process user interactions at the web browser, without ever refreshing the browser after the initial web page load.  You may use a JavaScript library of your choice, including jQuery.  (No extra credit will be given for ''not'' using a JavaScript library.)&lt;br /&gt;
&lt;br /&gt;
Your application should utilize AJAX to run server-side PHP scripts that query your database to save and retrieve information, including user accounts and events.&lt;br /&gt;
&lt;br /&gt;
==== Examples ====&lt;br /&gt;
&lt;br /&gt;
* https://calendar.google.com/&lt;br /&gt;
* http://www.zoho.com/calendar/&lt;br /&gt;
&lt;br /&gt;
==== Requirements ====&lt;br /&gt;
&lt;br /&gt;
* Support a month-by-month view of the calendar.&lt;br /&gt;
*: Show one month at a time, with buttons to move forward or backward.&lt;br /&gt;
*: There should be no limit to how far forward or backward the user can go.&lt;br /&gt;
* Users can register and log in to the website.&lt;br /&gt;
*: You may leverage your MySQL project code and database from last week to get started.&lt;br /&gt;
*: You may alternatively use OpenID for user authentication.  Note that you will still need a Users table in order associate calendar events with a certain OpenID.&lt;br /&gt;
* Unregistered users should see no events on the calendar.&lt;br /&gt;
* Registered users can add events.&lt;br /&gt;
*: All events should have a date and time, but do not need to have a duration.&lt;br /&gt;
*: You do ''not'' need to support recurring events (where you add an event that repeats, for example, every monday).&lt;br /&gt;
* Registered users see only events that they have added.&lt;br /&gt;
* Registered users can delete their events, but not the events of others.&lt;br /&gt;
* All user and event data should be kept in a database.&lt;br /&gt;
* At no time should the main page need to be reloaded.&lt;br /&gt;
*: User registration, user authentication, event addition, and event deletion should all be handled by JavaScript and AJAX requests to your server.&lt;br /&gt;
* Your page needs to work in the versions of Firefox and Chrome installed on the lab computers.&lt;br /&gt;
&lt;br /&gt;
'''Tip:''' Run your database schema by a TA before implementing it.&lt;br /&gt;
&lt;br /&gt;
==== Calendar Helper Library ====&lt;br /&gt;
&lt;br /&gt;
To help you get started with your calendar, we have written some JavaScript helper functions.  The code is available at:&lt;br /&gt;
* Full Version (for you to refer): http://cloud.sffc1.com/wustl/calendar.js&lt;br /&gt;
* Minified Version (to include in your pages): http://cloud.sffc1.com/wustl/calendar.min.js&lt;br /&gt;
&lt;br /&gt;
For example, this is how you would make a button to load the next month and show alerts containing all the days in the weeks contained by that month.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
// For our purposes, we can keep the current month in a variable in the global scope&lt;br /&gt;
var currentMonth = new Month(2012, 9); // October 2012&lt;br /&gt;
&lt;br /&gt;
// Change the month when the &amp;quot;next&amp;quot; button is pressed&lt;br /&gt;
document.getElementById(&amp;quot;next_month_btn&amp;quot;).addEventListener(&amp;quot;click&amp;quot;, function(event){&lt;br /&gt;
	currentMonth = currentMonth.nextMonth(); // Previous month would be currentMonth.prevMonth()&lt;br /&gt;
	updateCalendar(); // Whenever the month is updated, we'll need to re-render the calendar in HTML&lt;br /&gt;
	alert(&amp;quot;The new month is &amp;quot;+currentMonth.month+&amp;quot; &amp;quot;+currentMonth.year);&lt;br /&gt;
}, false);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
// This updateCalendar() function only alerts the dates in the currently specified month.  You need to write&lt;br /&gt;
// it to modify the DOM (optionally using jQuery) to display the days and weeks in the current month.&lt;br /&gt;
function updateCalendar(){&lt;br /&gt;
	var weeks = currentMonth.getWeeks();&lt;br /&gt;
	&lt;br /&gt;
	for(var w in weeks){&lt;br /&gt;
		var days = weeks[w].getDates();&lt;br /&gt;
		// days contains normal JavaScript Date objects.&lt;br /&gt;
		&lt;br /&gt;
		alert(&amp;quot;Week starting on &amp;quot;+days[0]);&lt;br /&gt;
		&lt;br /&gt;
		for(var d in days){&lt;br /&gt;
			// You can see console.log() output in your JavaScript debugging tool, like Firebug,&lt;br /&gt;
			// WebWit Inspector, or Dragonfly.&lt;br /&gt;
			console.log(days[d].toISOString());&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Important:''' JavaScript starts the months of a year, and the days of a week, at index 0.  This means that '''''in JavaScript, January is month 0, and December is month 11.'''''  Our calendar helper functions maintain this JavaScript convention.&lt;br /&gt;
&lt;br /&gt;
=== Web Security and Validation ===&lt;br /&gt;
&lt;br /&gt;
Your project needs to demonstrate that thought was put into web security and best practice.  For more information, see this week's Web Application Security guide: [[Web Application Security, Part 3]]&lt;br /&gt;
&lt;br /&gt;
In particular:&lt;br /&gt;
&lt;br /&gt;
* '''Your application needs to prevent XSS attacks.'''  The easiest way to prevent this is to continue sanitizing ''all'' of your output using '''htmlentities()'''.&lt;br /&gt;
* '''Perform precautionary measures to prevent session hijacking attacks.'''&lt;br /&gt;
*: You should specify your session cookie to be HTTP-Only.  However, for the means of this module, you need not test for user agent consistency.&lt;br /&gt;
* Validate your JavaScript code using [http://www.jshint.com/ JSHint]&lt;br /&gt;
&lt;br /&gt;
You should continue the practices that you have learned in past weeks:&lt;br /&gt;
&lt;br /&gt;
* Pass tokens in forms to prevent CSRF attacks&lt;br /&gt;
* Use prepared queries to prevent SQL Injection attacks&lt;br /&gt;
* If storing passwords in a database, always store them encrypted&lt;br /&gt;
* Your page should validate with no errors through the W3C validator.&lt;br /&gt;
&lt;br /&gt;
== Grading ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;font-size:2em; line-height:2em;&amp;quot;&amp;gt;'''Due Date: _____ (both individual and group)'''&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
!Assignment&lt;br /&gt;
!Points&lt;br /&gt;
|-&lt;br /&gt;
|Calculator&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
|Weather Widget&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|jQuery Dialogs&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
!colspan=&amp;quot;2&amp;quot;|Group Portion:&lt;br /&gt;
|-&lt;br /&gt;
|Calendar month view correct and Move between months (without page reload)&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|User authentication and registration (without page reload)&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Add events (new event shown in calendar without page reload)&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Events added are private and other users cannot see them&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
|Delete events (event removed from calendar without page reload)&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
|-&lt;br /&gt;
|Safe from XSS and Session Hijacking&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|-&lt;br /&gt;
|Validation, CSRF, Salted Passwords, Safe SQL Queries, JSHint&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Creative Portion&lt;br /&gt;
|2&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Total: 10 Points&lt;br /&gt;
You must get written permission for the creative portion.  Failure to get written permission will result in one point maximum.  &lt;br /&gt;
&lt;br /&gt;
[[Category:Module 4]]&lt;br /&gt;
[[Category:Modules]]&lt;/div&gt;</summary>
		<author><name>Marc</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=Module_6&amp;diff=799</id>
		<title>Module 6</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=Module_6&amp;diff=799"/>
		<updated>2012-10-14T03:58:14Z</updated>

		<summary type="html">&lt;p&gt;Marc: /* Grading */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In Module 4, you will learn about JavaScript, the prevailing client-side language, and AJAX, a method for performing asynchronous updates to a web page (without refreshing the page).&lt;br /&gt;
&lt;br /&gt;
This article contains your assignments for Module 4.&lt;br /&gt;
&lt;br /&gt;
== Individual Assignments ==&lt;br /&gt;
&lt;br /&gt;
=== JavaScript Calculator ===&lt;br /&gt;
&lt;br /&gt;
In Module 2, you made a calculator using PHP.  Now you will be making one using JavaScript.&lt;br /&gt;
&lt;br /&gt;
Read the JavaScript guide first: [[Javascript and AJAX]]&lt;br /&gt;
&lt;br /&gt;
* The web page should have two input fields and a radio button group for the operation, with the 4 basic math operations represented (add,subtract,multiply,divide).&lt;br /&gt;
* The javascript should monitor all three fields and display the current result whenever the user changes any value in any field, without refreshing the page.&lt;br /&gt;
* The calculator should be completely self-contained; i.e., you should not be making any requests to any other server-side or client-side scripts or web pages after the initial page load.&lt;br /&gt;
&lt;br /&gt;
'''Tip:''' You can embed JavaScript code into an HTML document like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;
// your code here&lt;br /&gt;
&amp;lt;/script&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Tip:''' If your code isn't working the way you expect, use a JavaScript error console.  In Chrome, for example, press Ctrl-Shift-I (or Cmd-Option-I) to open the WebKit inspector.&lt;br /&gt;
&lt;br /&gt;
=== Weather Widget ===&lt;br /&gt;
&lt;br /&gt;
In this section, you will make a web page that displays the weather forecast using AJAX requests to a weather server.  You should complete this section ''without'' using JavaScript libraries like jQuery.&lt;br /&gt;
&lt;br /&gt;
# Make an empty HTML document; name it '''weather.html'''&lt;br /&gt;
#: Refer to the [[HTML and CSS]] guide for the skeleton of an HTML document&lt;br /&gt;
# Define a function in JavaScript; call it '''fetchWeather()'''.  You may write your JavaScript in an embedded script in your head tag.&lt;br /&gt;
# Inside your '''fetchWeather()''' function, make an AJAX request to the weather server.&lt;br /&gt;
#: We have a server that outputs the current weather in JSON format.  The format is documented in the [[#JSON Structure]] section below.&lt;br /&gt;
#: '''URL:''' http://cloud.sffc1.com/wustl/weather_json.php&lt;br /&gt;
#: We kindly thank Yahoo Weather for providing us with up-to-date weather information.&lt;br /&gt;
#* '''Note:''' You normally cannot perform AJAX requests cross-domain.  We have set the &amp;lt;code&amp;gt;Access-Control-Allow-Origin&amp;lt;/code&amp;gt; header on our server to allow requests from your EC2 instances.&lt;br /&gt;
# In your callback, process the JSON and use JavaScript to manipulate the HTML DOM to display the following information on your page:&lt;br /&gt;
#* Location&lt;br /&gt;
#** City, in a &amp;lt;nowiki&amp;gt;&amp;lt;strong&amp;gt;&amp;lt;/nowiki&amp;gt; tag&lt;br /&gt;
#** State, not in any tag&lt;br /&gt;
#* Humidity&lt;br /&gt;
#* Current Temperature&lt;br /&gt;
#* Image for Tomorrow's Forecast (see [[#Weather Condition Images]] below for more information)&lt;br /&gt;
#* Image for the Day After Tomorrow's Forecast&lt;br /&gt;
# Finally, bind '''fetchWeather()''' to the DOMContentReady event so that your weather widget is automatically initialized when the page is loaded:&lt;br /&gt;
#: &amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;document.addEventListener(&amp;quot;DOMContentReady&amp;quot;, fetchWeather, false);&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Use the following HTML:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;weather&amp;quot; id=&amp;quot;weatherWidget&amp;quot;&amp;gt;&lt;br /&gt;
	&amp;lt;div class=&amp;quot;weather-loc&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
	&amp;lt;div class=&amp;quot;weather-humidity&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
	&amp;lt;div class=&amp;quot;weather-temp&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
	&amp;lt;img class=&amp;quot;weather-tomorrow&amp;quot; /&amp;gt;&lt;br /&gt;
	&amp;lt;img class=&amp;quot;weather-dayaftertomorrow&amp;quot; /&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Include the CSS file from here: http://cloud.sffc1.com/wustl/weather.css&lt;br /&gt;
&lt;br /&gt;
When everything is working, the weather widget should look something like this:&lt;br /&gt;
&lt;br /&gt;
[[File:WeatherWidget.png]]&lt;br /&gt;
&lt;br /&gt;
'''Important:''' The widget in this section needs to work in only Firefox and Chrome.  It does '''''not''''' need to work Internet Explorer.&lt;br /&gt;
&lt;br /&gt;
==== Tips ====&lt;br /&gt;
&lt;br /&gt;
===== JSON Structure =====&lt;br /&gt;
&lt;br /&gt;
The JSON from our server looks like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
   &amp;quot;updated&amp;quot;: &amp;quot;Thu, 11 Oct 2012 5:54 pm CDT&amp;quot;,&lt;br /&gt;
   &amp;quot;location&amp;quot;: {&lt;br /&gt;
      &amp;quot;city&amp;quot;: &amp;quot;St. Louis&amp;quot;,&lt;br /&gt;
      &amp;quot;state&amp;quot;: &amp;quot;MO&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;wind&amp;quot;: {&lt;br /&gt;
      &amp;quot;chill&amp;quot;: &amp;quot;62&amp;quot;,&lt;br /&gt;
      &amp;quot;direction&amp;quot;: &amp;quot;150&amp;quot;,&lt;br /&gt;
      &amp;quot;speed&amp;quot;: &amp;quot;3 mph&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;atmosphere&amp;quot;: {&lt;br /&gt;
      &amp;quot;humidity&amp;quot;: &amp;quot;50&amp;quot;,&lt;br /&gt;
      &amp;quot;visibility&amp;quot;: &amp;quot;10&amp;quot;,&lt;br /&gt;
      &amp;quot;pressure&amp;quot;: &amp;quot;30.12 in&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;current&amp;quot;: {&lt;br /&gt;
      &amp;quot;code&amp;quot;: &amp;quot;28&amp;quot;,&lt;br /&gt;
      &amp;quot;text&amp;quot;: &amp;quot;Mostly Cloudy&amp;quot;,&lt;br /&gt;
      &amp;quot;temp&amp;quot;: &amp;quot;62°F&amp;quot;,&lt;br /&gt;
      &amp;quot;date&amp;quot;: &amp;quot;Thu, 11 Oct 2012 5:54 pm CDT&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;tomorrow&amp;quot;: {&lt;br /&gt;
      &amp;quot;code&amp;quot;: &amp;quot;29&amp;quot;,&lt;br /&gt;
      &amp;quot;text&amp;quot;: &amp;quot;Clouds Early/Clearing Late&amp;quot;,&lt;br /&gt;
      &amp;quot;low&amp;quot;: &amp;quot;45°F&amp;quot;,&lt;br /&gt;
      &amp;quot;high&amp;quot;: &amp;quot;61°F&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;dayafter&amp;quot;: {&lt;br /&gt;
      &amp;quot;code&amp;quot;: &amp;quot;30&amp;quot;,&lt;br /&gt;
      &amp;quot;text&amp;quot;: &amp;quot;Partly Cloudy&amp;quot;,&lt;br /&gt;
      &amp;quot;low&amp;quot;: &amp;quot;53°F&amp;quot;,&lt;br /&gt;
      &amp;quot;high&amp;quot;: &amp;quot;65°F&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;credit&amp;quot;: &amp;quot;http://us.rd.yahoo.com/dailynews/rss/weather/St._Louis__MO/*http://weather.yahoo.com/forecast/USMO0170_f.html&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Weather Condition Images =====&lt;br /&gt;
&lt;br /&gt;
Each day's forecast has a code.  There are images associated with these codes.&lt;br /&gt;
&lt;br /&gt;
You can get images from here: &amp;lt;nowiki&amp;gt;http://us.i1.yimg.com/us.yimg.com/i/us/nws/weather/gr/&amp;lt;/nowiki&amp;gt;'''##'''&amp;lt;nowiki&amp;gt;ds.png&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Replace the '''##''' with the forecast code.  For example, for code 32, the URL would be: http://us.i1.yimg.com/us.yimg.com/i/us/nws/weather/gr/32ds.png&lt;br /&gt;
&lt;br /&gt;
=== jQuery Dialogs ===&lt;br /&gt;
&lt;br /&gt;
Helpful Resource: [http://docs.jquery.com/Main_Page jQuery Documentation] ... Some additional tips: [[jQuery]]&lt;br /&gt;
&lt;br /&gt;
Create a simple page using jQuery dialogs.&lt;br /&gt;
&lt;br /&gt;
* Create a page that has the words &amp;quot;Google&amp;quot; and &amp;quot;Yahoo&amp;quot;.&lt;br /&gt;
* When the user clicks the &amp;quot;Google&amp;quot; text, open a jQuery dialog window with one jQuery dialog button.  If the button is pressed, display the Google logo image (the image can be stored on your web server) on the web page, and if the dialog is closed any other way, do nothing.&lt;br /&gt;
* When the user clicks the &amp;quot;Yahoo&amp;quot; text, open a jQuery dialog window with one jQuery dialog button.  If the button is pressed, display the Yahoo logo image (the image can be stored on your web server) on the web page, and if the dialog is closed any other way, do nothing.&lt;br /&gt;
* Initially there should be no image on the page (i.e., the img should be hidden with the CSS display attribute).  After one of the two images is displayed, if the user clicks on the image, a jQuery dialog box should be opened with one dialog button, and if the button is pressed then the image should be hidden again.  Otherwise, do nothing.&lt;br /&gt;
&lt;br /&gt;
== Group Project ==&lt;br /&gt;
&lt;br /&gt;
You will work in pairs on this project.&lt;br /&gt;
&lt;br /&gt;
'''Important Reminder:''' frequently commit your work to your subversion repository as a backup!&lt;br /&gt;
&lt;br /&gt;
I forgot if I already mentioned this, but '''start early on this project!''' It will take longer than you think, I promise!&lt;br /&gt;
&lt;br /&gt;
=== Calendar ===&lt;br /&gt;
&lt;br /&gt;
Build a simple calendar that allows users to add and remove events dynamically.&lt;br /&gt;
&lt;br /&gt;
You will use JavaScript to process user interactions at the web browser, without ever refreshing the browser after the initial web page load.  You may use a JavaScript library of your choice, including jQuery.  (No extra credit will be given for ''not'' using a JavaScript library.)&lt;br /&gt;
&lt;br /&gt;
Your application should utilize AJAX to run server-side PHP scripts that query your database to save and retrieve information, including user accounts and events.&lt;br /&gt;
&lt;br /&gt;
==== Examples ====&lt;br /&gt;
&lt;br /&gt;
* https://calendar.google.com/&lt;br /&gt;
* http://www.zoho.com/calendar/&lt;br /&gt;
&lt;br /&gt;
==== Requirements ====&lt;br /&gt;
&lt;br /&gt;
* Support a month-by-month view of the calendar.&lt;br /&gt;
*: Show one month at a time, with buttons to move forward or backward.&lt;br /&gt;
*: There should be no limit to how far forward or backward the user can go.&lt;br /&gt;
* Users can register and log in to the website.&lt;br /&gt;
*: You may leverage your MySQL project code and database from last week to get started.&lt;br /&gt;
*: You may alternatively use OpenID for user authentication.  Note that you will still need a Users table in order associate calendar events with a certain OpenID.&lt;br /&gt;
* Unregistered users should see no events on the calendar.&lt;br /&gt;
* Registered users can add events.&lt;br /&gt;
*: All events should have a date and time, but do not need to have a duration.&lt;br /&gt;
*: You do ''not'' need to support recurring events (where you add an event that repeats, for example, every monday).&lt;br /&gt;
* Registered users see only events that they have added.&lt;br /&gt;
* Registered users can delete their events, but not the events of others.&lt;br /&gt;
* All user and event data should be kept in a database.&lt;br /&gt;
* At no time should the main page need to be reloaded.&lt;br /&gt;
*: User registration, user authentication, event addition, and event deletion should all be handled by JavaScript and AJAX requests to your server.&lt;br /&gt;
* Your page needs to work in the versions of Firefox and Chrome installed on the lab computers.&lt;br /&gt;
&lt;br /&gt;
'''Tip:''' Run your database schema by a TA before implementing it.&lt;br /&gt;
&lt;br /&gt;
==== Calendar Helper Library ====&lt;br /&gt;
&lt;br /&gt;
To help you get started with your calendar, we have written some JavaScript helper functions.  The code is available at:&lt;br /&gt;
* Full Version (for you to refer): http://cloud.sffc1.com/wustl/calendar.js&lt;br /&gt;
* Minified Version (to include in your pages): http://cloud.sffc1.com/wustl/calendar.min.js&lt;br /&gt;
&lt;br /&gt;
For example, this is how you would make a button to load the next month and show alerts containing all the days in the weeks contained by that month.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
// For our purposes, we can keep the current month in a variable in the global scope&lt;br /&gt;
var currentMonth = new Month(2012, 9); // October 2012&lt;br /&gt;
&lt;br /&gt;
// Change the month when the &amp;quot;next&amp;quot; button is pressed&lt;br /&gt;
document.getElementById(&amp;quot;next_month_btn&amp;quot;).addEventListener(&amp;quot;click&amp;quot;, function(event){&lt;br /&gt;
	currentMonth = currentMonth.nextMonth(); // Previous month would be currentMonth.prevMonth()&lt;br /&gt;
	updateCalendar(); // Whenever the month is updated, we'll need to re-render the calendar in HTML&lt;br /&gt;
	alert(&amp;quot;The new month is &amp;quot;+currentMonth.month+&amp;quot; &amp;quot;+currentMonth.year);&lt;br /&gt;
}, false);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
// This updateCalendar() function only alerts the dates in the currently specified month.  You need to write&lt;br /&gt;
// it to modify the DOM (optionally using jQuery) to display the days and weeks in the current month.&lt;br /&gt;
function updateCalendar(){&lt;br /&gt;
	var weeks = currentMonth.getWeeks();&lt;br /&gt;
	&lt;br /&gt;
	for(var w in weeks){&lt;br /&gt;
		var days = weeks[w].getDates();&lt;br /&gt;
		// days contains normal JavaScript Date objects.&lt;br /&gt;
		&lt;br /&gt;
		alert(&amp;quot;Week starting on &amp;quot;+days[0]);&lt;br /&gt;
		&lt;br /&gt;
		for(var d in days){&lt;br /&gt;
			// You can see console.log() output in your JavaScript debugging tool, like Firebug,&lt;br /&gt;
			// WebWit Inspector, or Dragonfly.&lt;br /&gt;
			console.log(days[d].toISOString());&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Important:''' JavaScript starts the months of a year, and the days of a week, at index 0.  This means that '''''in JavaScript, January is month 0, and December is month 11.'''''  Our calendar helper functions maintain this JavaScript convention.&lt;br /&gt;
&lt;br /&gt;
=== Web Security and Validation ===&lt;br /&gt;
&lt;br /&gt;
Your project needs to demonstrate that thought was put into web security and best practice.  For more information, see this week's Web Application Security guide: [[Web Application Security, Part 3]]&lt;br /&gt;
&lt;br /&gt;
In particular:&lt;br /&gt;
&lt;br /&gt;
* '''Your application needs to prevent XSS attacks.'''  The easiest way to prevent this is to continue sanitizing ''all'' of your output using '''htmlentities()'''.&lt;br /&gt;
* '''Perform precautionary measures to prevent session hijacking attacks.'''&lt;br /&gt;
*: You should specify your session cookie to be HTTP-Only.  However, for the means of this module, you need not test for user agent consistency.&lt;br /&gt;
* Validate your JavaScript code using [http://www.jshint.com/ JSHint]&lt;br /&gt;
&lt;br /&gt;
You should continue the practices that you have learned in past weeks:&lt;br /&gt;
&lt;br /&gt;
* Pass tokens in forms to prevent CSRF attacks&lt;br /&gt;
* Use prepared queries to prevent SQL Injection attacks&lt;br /&gt;
* If storing passwords in a database, always store them encrypted&lt;br /&gt;
* Your page should validate with no errors through the W3C validator.&lt;br /&gt;
&lt;br /&gt;
== Grading ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;font-size:2em; line-height:2em;&amp;quot;&amp;gt;'''Due Date: _____ (both individual and group)'''&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
!Assignment&lt;br /&gt;
!Points&lt;br /&gt;
|-&lt;br /&gt;
|Calculator&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
|Weather Widget&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|jQuery Dialogs&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
!colspan=&amp;quot;2&amp;quot;|Group Portion:&lt;br /&gt;
|-&lt;br /&gt;
|Calendar month view correct and Move between months (without page reload)&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|User authentication and registration (without page reload)&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Add events (new event shown in calendar without page reload)&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Events added are private and other users cannot see them&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
|Delete events (event removed from calendar without page reload)&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
|-&lt;br /&gt;
|Safe from XSS and Session Hijacking&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|-&lt;br /&gt;
|Validation, CSRF, Salted Passwords, Safe SQL Queries, JSHint&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Creative Portion&lt;br /&gt;
|2&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
[[Category:Module 4]]&lt;br /&gt;
[[Category:Modules]]&lt;/div&gt;</summary>
		<author><name>Marc</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=Module_6&amp;diff=798</id>
		<title>Module 6</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=Module_6&amp;diff=798"/>
		<updated>2012-10-14T03:58:03Z</updated>

		<summary type="html">&lt;p&gt;Marc: /* Grading */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In Module 4, you will learn about JavaScript, the prevailing client-side language, and AJAX, a method for performing asynchronous updates to a web page (without refreshing the page).&lt;br /&gt;
&lt;br /&gt;
This article contains your assignments for Module 4.&lt;br /&gt;
&lt;br /&gt;
== Individual Assignments ==&lt;br /&gt;
&lt;br /&gt;
=== JavaScript Calculator ===&lt;br /&gt;
&lt;br /&gt;
In Module 2, you made a calculator using PHP.  Now you will be making one using JavaScript.&lt;br /&gt;
&lt;br /&gt;
Read the JavaScript guide first: [[Javascript and AJAX]]&lt;br /&gt;
&lt;br /&gt;
* The web page should have two input fields and a radio button group for the operation, with the 4 basic math operations represented (add,subtract,multiply,divide).&lt;br /&gt;
* The javascript should monitor all three fields and display the current result whenever the user changes any value in any field, without refreshing the page.&lt;br /&gt;
* The calculator should be completely self-contained; i.e., you should not be making any requests to any other server-side or client-side scripts or web pages after the initial page load.&lt;br /&gt;
&lt;br /&gt;
'''Tip:''' You can embed JavaScript code into an HTML document like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;
// your code here&lt;br /&gt;
&amp;lt;/script&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Tip:''' If your code isn't working the way you expect, use a JavaScript error console.  In Chrome, for example, press Ctrl-Shift-I (or Cmd-Option-I) to open the WebKit inspector.&lt;br /&gt;
&lt;br /&gt;
=== Weather Widget ===&lt;br /&gt;
&lt;br /&gt;
In this section, you will make a web page that displays the weather forecast using AJAX requests to a weather server.  You should complete this section ''without'' using JavaScript libraries like jQuery.&lt;br /&gt;
&lt;br /&gt;
# Make an empty HTML document; name it '''weather.html'''&lt;br /&gt;
#: Refer to the [[HTML and CSS]] guide for the skeleton of an HTML document&lt;br /&gt;
# Define a function in JavaScript; call it '''fetchWeather()'''.  You may write your JavaScript in an embedded script in your head tag.&lt;br /&gt;
# Inside your '''fetchWeather()''' function, make an AJAX request to the weather server.&lt;br /&gt;
#: We have a server that outputs the current weather in JSON format.  The format is documented in the [[#JSON Structure]] section below.&lt;br /&gt;
#: '''URL:''' http://cloud.sffc1.com/wustl/weather_json.php&lt;br /&gt;
#: We kindly thank Yahoo Weather for providing us with up-to-date weather information.&lt;br /&gt;
#* '''Note:''' You normally cannot perform AJAX requests cross-domain.  We have set the &amp;lt;code&amp;gt;Access-Control-Allow-Origin&amp;lt;/code&amp;gt; header on our server to allow requests from your EC2 instances.&lt;br /&gt;
# In your callback, process the JSON and use JavaScript to manipulate the HTML DOM to display the following information on your page:&lt;br /&gt;
#* Location&lt;br /&gt;
#** City, in a &amp;lt;nowiki&amp;gt;&amp;lt;strong&amp;gt;&amp;lt;/nowiki&amp;gt; tag&lt;br /&gt;
#** State, not in any tag&lt;br /&gt;
#* Humidity&lt;br /&gt;
#* Current Temperature&lt;br /&gt;
#* Image for Tomorrow's Forecast (see [[#Weather Condition Images]] below for more information)&lt;br /&gt;
#* Image for the Day After Tomorrow's Forecast&lt;br /&gt;
# Finally, bind '''fetchWeather()''' to the DOMContentReady event so that your weather widget is automatically initialized when the page is loaded:&lt;br /&gt;
#: &amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;document.addEventListener(&amp;quot;DOMContentReady&amp;quot;, fetchWeather, false);&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Use the following HTML:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;weather&amp;quot; id=&amp;quot;weatherWidget&amp;quot;&amp;gt;&lt;br /&gt;
	&amp;lt;div class=&amp;quot;weather-loc&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
	&amp;lt;div class=&amp;quot;weather-humidity&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
	&amp;lt;div class=&amp;quot;weather-temp&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
	&amp;lt;img class=&amp;quot;weather-tomorrow&amp;quot; /&amp;gt;&lt;br /&gt;
	&amp;lt;img class=&amp;quot;weather-dayaftertomorrow&amp;quot; /&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Include the CSS file from here: http://cloud.sffc1.com/wustl/weather.css&lt;br /&gt;
&lt;br /&gt;
When everything is working, the weather widget should look something like this:&lt;br /&gt;
&lt;br /&gt;
[[File:WeatherWidget.png]]&lt;br /&gt;
&lt;br /&gt;
'''Important:''' The widget in this section needs to work in only Firefox and Chrome.  It does '''''not''''' need to work Internet Explorer.&lt;br /&gt;
&lt;br /&gt;
==== Tips ====&lt;br /&gt;
&lt;br /&gt;
===== JSON Structure =====&lt;br /&gt;
&lt;br /&gt;
The JSON from our server looks like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
   &amp;quot;updated&amp;quot;: &amp;quot;Thu, 11 Oct 2012 5:54 pm CDT&amp;quot;,&lt;br /&gt;
   &amp;quot;location&amp;quot;: {&lt;br /&gt;
      &amp;quot;city&amp;quot;: &amp;quot;St. Louis&amp;quot;,&lt;br /&gt;
      &amp;quot;state&amp;quot;: &amp;quot;MO&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;wind&amp;quot;: {&lt;br /&gt;
      &amp;quot;chill&amp;quot;: &amp;quot;62&amp;quot;,&lt;br /&gt;
      &amp;quot;direction&amp;quot;: &amp;quot;150&amp;quot;,&lt;br /&gt;
      &amp;quot;speed&amp;quot;: &amp;quot;3 mph&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;atmosphere&amp;quot;: {&lt;br /&gt;
      &amp;quot;humidity&amp;quot;: &amp;quot;50&amp;quot;,&lt;br /&gt;
      &amp;quot;visibility&amp;quot;: &amp;quot;10&amp;quot;,&lt;br /&gt;
      &amp;quot;pressure&amp;quot;: &amp;quot;30.12 in&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;current&amp;quot;: {&lt;br /&gt;
      &amp;quot;code&amp;quot;: &amp;quot;28&amp;quot;,&lt;br /&gt;
      &amp;quot;text&amp;quot;: &amp;quot;Mostly Cloudy&amp;quot;,&lt;br /&gt;
      &amp;quot;temp&amp;quot;: &amp;quot;62°F&amp;quot;,&lt;br /&gt;
      &amp;quot;date&amp;quot;: &amp;quot;Thu, 11 Oct 2012 5:54 pm CDT&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;tomorrow&amp;quot;: {&lt;br /&gt;
      &amp;quot;code&amp;quot;: &amp;quot;29&amp;quot;,&lt;br /&gt;
      &amp;quot;text&amp;quot;: &amp;quot;Clouds Early/Clearing Late&amp;quot;,&lt;br /&gt;
      &amp;quot;low&amp;quot;: &amp;quot;45°F&amp;quot;,&lt;br /&gt;
      &amp;quot;high&amp;quot;: &amp;quot;61°F&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;dayafter&amp;quot;: {&lt;br /&gt;
      &amp;quot;code&amp;quot;: &amp;quot;30&amp;quot;,&lt;br /&gt;
      &amp;quot;text&amp;quot;: &amp;quot;Partly Cloudy&amp;quot;,&lt;br /&gt;
      &amp;quot;low&amp;quot;: &amp;quot;53°F&amp;quot;,&lt;br /&gt;
      &amp;quot;high&amp;quot;: &amp;quot;65°F&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;credit&amp;quot;: &amp;quot;http://us.rd.yahoo.com/dailynews/rss/weather/St._Louis__MO/*http://weather.yahoo.com/forecast/USMO0170_f.html&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Weather Condition Images =====&lt;br /&gt;
&lt;br /&gt;
Each day's forecast has a code.  There are images associated with these codes.&lt;br /&gt;
&lt;br /&gt;
You can get images from here: &amp;lt;nowiki&amp;gt;http://us.i1.yimg.com/us.yimg.com/i/us/nws/weather/gr/&amp;lt;/nowiki&amp;gt;'''##'''&amp;lt;nowiki&amp;gt;ds.png&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Replace the '''##''' with the forecast code.  For example, for code 32, the URL would be: http://us.i1.yimg.com/us.yimg.com/i/us/nws/weather/gr/32ds.png&lt;br /&gt;
&lt;br /&gt;
=== jQuery Dialogs ===&lt;br /&gt;
&lt;br /&gt;
Helpful Resource: [http://docs.jquery.com/Main_Page jQuery Documentation] ... Some additional tips: [[jQuery]]&lt;br /&gt;
&lt;br /&gt;
Create a simple page using jQuery dialogs.&lt;br /&gt;
&lt;br /&gt;
* Create a page that has the words &amp;quot;Google&amp;quot; and &amp;quot;Yahoo&amp;quot;.&lt;br /&gt;
* When the user clicks the &amp;quot;Google&amp;quot; text, open a jQuery dialog window with one jQuery dialog button.  If the button is pressed, display the Google logo image (the image can be stored on your web server) on the web page, and if the dialog is closed any other way, do nothing.&lt;br /&gt;
* When the user clicks the &amp;quot;Yahoo&amp;quot; text, open a jQuery dialog window with one jQuery dialog button.  If the button is pressed, display the Yahoo logo image (the image can be stored on your web server) on the web page, and if the dialog is closed any other way, do nothing.&lt;br /&gt;
* Initially there should be no image on the page (i.e., the img should be hidden with the CSS display attribute).  After one of the two images is displayed, if the user clicks on the image, a jQuery dialog box should be opened with one dialog button, and if the button is pressed then the image should be hidden again.  Otherwise, do nothing.&lt;br /&gt;
&lt;br /&gt;
== Group Project ==&lt;br /&gt;
&lt;br /&gt;
You will work in pairs on this project.&lt;br /&gt;
&lt;br /&gt;
'''Important Reminder:''' frequently commit your work to your subversion repository as a backup!&lt;br /&gt;
&lt;br /&gt;
I forgot if I already mentioned this, but '''start early on this project!''' It will take longer than you think, I promise!&lt;br /&gt;
&lt;br /&gt;
=== Calendar ===&lt;br /&gt;
&lt;br /&gt;
Build a simple calendar that allows users to add and remove events dynamically.&lt;br /&gt;
&lt;br /&gt;
You will use JavaScript to process user interactions at the web browser, without ever refreshing the browser after the initial web page load.  You may use a JavaScript library of your choice, including jQuery.  (No extra credit will be given for ''not'' using a JavaScript library.)&lt;br /&gt;
&lt;br /&gt;
Your application should utilize AJAX to run server-side PHP scripts that query your database to save and retrieve information, including user accounts and events.&lt;br /&gt;
&lt;br /&gt;
==== Examples ====&lt;br /&gt;
&lt;br /&gt;
* https://calendar.google.com/&lt;br /&gt;
* http://www.zoho.com/calendar/&lt;br /&gt;
&lt;br /&gt;
==== Requirements ====&lt;br /&gt;
&lt;br /&gt;
* Support a month-by-month view of the calendar.&lt;br /&gt;
*: Show one month at a time, with buttons to move forward or backward.&lt;br /&gt;
*: There should be no limit to how far forward or backward the user can go.&lt;br /&gt;
* Users can register and log in to the website.&lt;br /&gt;
*: You may leverage your MySQL project code and database from last week to get started.&lt;br /&gt;
*: You may alternatively use OpenID for user authentication.  Note that you will still need a Users table in order associate calendar events with a certain OpenID.&lt;br /&gt;
* Unregistered users should see no events on the calendar.&lt;br /&gt;
* Registered users can add events.&lt;br /&gt;
*: All events should have a date and time, but do not need to have a duration.&lt;br /&gt;
*: You do ''not'' need to support recurring events (where you add an event that repeats, for example, every monday).&lt;br /&gt;
* Registered users see only events that they have added.&lt;br /&gt;
* Registered users can delete their events, but not the events of others.&lt;br /&gt;
* All user and event data should be kept in a database.&lt;br /&gt;
* At no time should the main page need to be reloaded.&lt;br /&gt;
*: User registration, user authentication, event addition, and event deletion should all be handled by JavaScript and AJAX requests to your server.&lt;br /&gt;
* Your page needs to work in the versions of Firefox and Chrome installed on the lab computers.&lt;br /&gt;
&lt;br /&gt;
'''Tip:''' Run your database schema by a TA before implementing it.&lt;br /&gt;
&lt;br /&gt;
==== Calendar Helper Library ====&lt;br /&gt;
&lt;br /&gt;
To help you get started with your calendar, we have written some JavaScript helper functions.  The code is available at:&lt;br /&gt;
* Full Version (for you to refer): http://cloud.sffc1.com/wustl/calendar.js&lt;br /&gt;
* Minified Version (to include in your pages): http://cloud.sffc1.com/wustl/calendar.min.js&lt;br /&gt;
&lt;br /&gt;
For example, this is how you would make a button to load the next month and show alerts containing all the days in the weeks contained by that month.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
// For our purposes, we can keep the current month in a variable in the global scope&lt;br /&gt;
var currentMonth = new Month(2012, 9); // October 2012&lt;br /&gt;
&lt;br /&gt;
// Change the month when the &amp;quot;next&amp;quot; button is pressed&lt;br /&gt;
document.getElementById(&amp;quot;next_month_btn&amp;quot;).addEventListener(&amp;quot;click&amp;quot;, function(event){&lt;br /&gt;
	currentMonth = currentMonth.nextMonth(); // Previous month would be currentMonth.prevMonth()&lt;br /&gt;
	updateCalendar(); // Whenever the month is updated, we'll need to re-render the calendar in HTML&lt;br /&gt;
	alert(&amp;quot;The new month is &amp;quot;+currentMonth.month+&amp;quot; &amp;quot;+currentMonth.year);&lt;br /&gt;
}, false);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
// This updateCalendar() function only alerts the dates in the currently specified month.  You need to write&lt;br /&gt;
// it to modify the DOM (optionally using jQuery) to display the days and weeks in the current month.&lt;br /&gt;
function updateCalendar(){&lt;br /&gt;
	var weeks = currentMonth.getWeeks();&lt;br /&gt;
	&lt;br /&gt;
	for(var w in weeks){&lt;br /&gt;
		var days = weeks[w].getDates();&lt;br /&gt;
		// days contains normal JavaScript Date objects.&lt;br /&gt;
		&lt;br /&gt;
		alert(&amp;quot;Week starting on &amp;quot;+days[0]);&lt;br /&gt;
		&lt;br /&gt;
		for(var d in days){&lt;br /&gt;
			// You can see console.log() output in your JavaScript debugging tool, like Firebug,&lt;br /&gt;
			// WebWit Inspector, or Dragonfly.&lt;br /&gt;
			console.log(days[d].toISOString());&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Important:''' JavaScript starts the months of a year, and the days of a week, at index 0.  This means that '''''in JavaScript, January is month 0, and December is month 11.'''''  Our calendar helper functions maintain this JavaScript convention.&lt;br /&gt;
&lt;br /&gt;
=== Web Security and Validation ===&lt;br /&gt;
&lt;br /&gt;
Your project needs to demonstrate that thought was put into web security and best practice.  For more information, see this week's Web Application Security guide: [[Web Application Security, Part 3]]&lt;br /&gt;
&lt;br /&gt;
In particular:&lt;br /&gt;
&lt;br /&gt;
* '''Your application needs to prevent XSS attacks.'''  The easiest way to prevent this is to continue sanitizing ''all'' of your output using '''htmlentities()'''.&lt;br /&gt;
* '''Perform precautionary measures to prevent session hijacking attacks.'''&lt;br /&gt;
*: You should specify your session cookie to be HTTP-Only.  However, for the means of this module, you need not test for user agent consistency.&lt;br /&gt;
* Validate your JavaScript code using [http://www.jshint.com/ JSHint]&lt;br /&gt;
&lt;br /&gt;
You should continue the practices that you have learned in past weeks:&lt;br /&gt;
&lt;br /&gt;
* Pass tokens in forms to prevent CSRF attacks&lt;br /&gt;
* Use prepared queries to prevent SQL Injection attacks&lt;br /&gt;
* If storing passwords in a database, always store them encrypted&lt;br /&gt;
* Your page should validate with no errors through the W3C validator.&lt;br /&gt;
&lt;br /&gt;
== Grading ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;font-size:2em; line-height:2em;&amp;quot;&amp;gt;'''Due Date: _____ (both individual and group)'''&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
!Assignment&lt;br /&gt;
!Points&lt;br /&gt;
|-&lt;br /&gt;
|Calculator&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
|Weather Widget&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|jQuery Dialogs&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
!colspan=&amp;quot;2&amp;quot;|Group Portion:&lt;br /&gt;
|-&lt;br /&gt;
|Calendar month view correct and Move between months (without page reload)&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|User authentication and registration (without page reload)&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Add events Events (new event shown in calendar without page reload)&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Events added are private and other users cannot see them&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
|Delete events (event removed from calendar without page reload)&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
|-&lt;br /&gt;
|Safe from XSS and Session Hijacking&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|-&lt;br /&gt;
|Validation, CSRF, Salted Passwords, Safe SQL Queries, JSHint&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Creative Portion&lt;br /&gt;
|2&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
[[Category:Module 4]]&lt;br /&gt;
[[Category:Modules]]&lt;/div&gt;</summary>
		<author><name>Marc</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=Module_6&amp;diff=797</id>
		<title>Module 6</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=Module_6&amp;diff=797"/>
		<updated>2012-10-14T03:52:32Z</updated>

		<summary type="html">&lt;p&gt;Marc: /* Web Security and Validation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In Module 4, you will learn about JavaScript, the prevailing client-side language, and AJAX, a method for performing asynchronous updates to a web page (without refreshing the page).&lt;br /&gt;
&lt;br /&gt;
This article contains your assignments for Module 4.&lt;br /&gt;
&lt;br /&gt;
== Individual Assignments ==&lt;br /&gt;
&lt;br /&gt;
=== JavaScript Calculator ===&lt;br /&gt;
&lt;br /&gt;
In Module 2, you made a calculator using PHP.  Now you will be making one using JavaScript.&lt;br /&gt;
&lt;br /&gt;
Read the JavaScript guide first: [[Javascript and AJAX]]&lt;br /&gt;
&lt;br /&gt;
* The web page should have two input fields and a radio button group for the operation, with the 4 basic math operations represented (add,subtract,multiply,divide).&lt;br /&gt;
* The javascript should monitor all three fields and display the current result whenever the user changes any value in any field, without refreshing the page.&lt;br /&gt;
* The calculator should be completely self-contained; i.e., you should not be making any requests to any other server-side or client-side scripts or web pages after the initial page load.&lt;br /&gt;
&lt;br /&gt;
'''Tip:''' You can embed JavaScript code into an HTML document like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;
// your code here&lt;br /&gt;
&amp;lt;/script&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Tip:''' If your code isn't working the way you expect, use a JavaScript error console.  In Chrome, for example, press Ctrl-Shift-I (or Cmd-Option-I) to open the WebKit inspector.&lt;br /&gt;
&lt;br /&gt;
=== Weather Widget ===&lt;br /&gt;
&lt;br /&gt;
In this section, you will make a web page that displays the weather forecast using AJAX requests to a weather server.  You should complete this section ''without'' using JavaScript libraries like jQuery.&lt;br /&gt;
&lt;br /&gt;
# Make an empty HTML document; name it '''weather.html'''&lt;br /&gt;
#: Refer to the [[HTML and CSS]] guide for the skeleton of an HTML document&lt;br /&gt;
# Define a function in JavaScript; call it '''fetchWeather()'''.  You may write your JavaScript in an embedded script in your head tag.&lt;br /&gt;
# Inside your '''fetchWeather()''' function, make an AJAX request to the weather server.&lt;br /&gt;
#: We have a server that outputs the current weather in JSON format.  The format is documented in the [[#JSON Structure]] section below.&lt;br /&gt;
#: '''URL:''' http://cloud.sffc1.com/wustl/weather_json.php&lt;br /&gt;
#: We kindly thank Yahoo Weather for providing us with up-to-date weather information.&lt;br /&gt;
#* '''Note:''' You normally cannot perform AJAX requests cross-domain.  We have set the &amp;lt;code&amp;gt;Access-Control-Allow-Origin&amp;lt;/code&amp;gt; header on our server to allow requests from your EC2 instances.&lt;br /&gt;
# In your callback, process the JSON and use JavaScript to manipulate the HTML DOM to display the following information on your page:&lt;br /&gt;
#* Location&lt;br /&gt;
#** City, in a &amp;lt;nowiki&amp;gt;&amp;lt;strong&amp;gt;&amp;lt;/nowiki&amp;gt; tag&lt;br /&gt;
#** State, not in any tag&lt;br /&gt;
#* Humidity&lt;br /&gt;
#* Current Temperature&lt;br /&gt;
#* Image for Tomorrow's Forecast (see [[#Weather Condition Images]] below for more information)&lt;br /&gt;
#* Image for the Day After Tomorrow's Forecast&lt;br /&gt;
# Finally, bind '''fetchWeather()''' to the DOMContentReady event so that your weather widget is automatically initialized when the page is loaded:&lt;br /&gt;
#: &amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;document.addEventListener(&amp;quot;DOMContentReady&amp;quot;, fetchWeather, false);&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Use the following HTML:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;weather&amp;quot; id=&amp;quot;weatherWidget&amp;quot;&amp;gt;&lt;br /&gt;
	&amp;lt;div class=&amp;quot;weather-loc&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
	&amp;lt;div class=&amp;quot;weather-humidity&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
	&amp;lt;div class=&amp;quot;weather-temp&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
	&amp;lt;img class=&amp;quot;weather-tomorrow&amp;quot; /&amp;gt;&lt;br /&gt;
	&amp;lt;img class=&amp;quot;weather-dayaftertomorrow&amp;quot; /&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Include the CSS file from here: http://cloud.sffc1.com/wustl/weather.css&lt;br /&gt;
&lt;br /&gt;
When everything is working, the weather widget should look something like this:&lt;br /&gt;
&lt;br /&gt;
[[File:WeatherWidget.png]]&lt;br /&gt;
&lt;br /&gt;
'''Important:''' The widget in this section needs to work in only Firefox and Chrome.  It does '''''not''''' need to work Internet Explorer.&lt;br /&gt;
&lt;br /&gt;
==== Tips ====&lt;br /&gt;
&lt;br /&gt;
===== JSON Structure =====&lt;br /&gt;
&lt;br /&gt;
The JSON from our server looks like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
   &amp;quot;updated&amp;quot;: &amp;quot;Thu, 11 Oct 2012 5:54 pm CDT&amp;quot;,&lt;br /&gt;
   &amp;quot;location&amp;quot;: {&lt;br /&gt;
      &amp;quot;city&amp;quot;: &amp;quot;St. Louis&amp;quot;,&lt;br /&gt;
      &amp;quot;state&amp;quot;: &amp;quot;MO&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;wind&amp;quot;: {&lt;br /&gt;
      &amp;quot;chill&amp;quot;: &amp;quot;62&amp;quot;,&lt;br /&gt;
      &amp;quot;direction&amp;quot;: &amp;quot;150&amp;quot;,&lt;br /&gt;
      &amp;quot;speed&amp;quot;: &amp;quot;3 mph&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;atmosphere&amp;quot;: {&lt;br /&gt;
      &amp;quot;humidity&amp;quot;: &amp;quot;50&amp;quot;,&lt;br /&gt;
      &amp;quot;visibility&amp;quot;: &amp;quot;10&amp;quot;,&lt;br /&gt;
      &amp;quot;pressure&amp;quot;: &amp;quot;30.12 in&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;current&amp;quot;: {&lt;br /&gt;
      &amp;quot;code&amp;quot;: &amp;quot;28&amp;quot;,&lt;br /&gt;
      &amp;quot;text&amp;quot;: &amp;quot;Mostly Cloudy&amp;quot;,&lt;br /&gt;
      &amp;quot;temp&amp;quot;: &amp;quot;62°F&amp;quot;,&lt;br /&gt;
      &amp;quot;date&amp;quot;: &amp;quot;Thu, 11 Oct 2012 5:54 pm CDT&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;tomorrow&amp;quot;: {&lt;br /&gt;
      &amp;quot;code&amp;quot;: &amp;quot;29&amp;quot;,&lt;br /&gt;
      &amp;quot;text&amp;quot;: &amp;quot;Clouds Early/Clearing Late&amp;quot;,&lt;br /&gt;
      &amp;quot;low&amp;quot;: &amp;quot;45°F&amp;quot;,&lt;br /&gt;
      &amp;quot;high&amp;quot;: &amp;quot;61°F&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;dayafter&amp;quot;: {&lt;br /&gt;
      &amp;quot;code&amp;quot;: &amp;quot;30&amp;quot;,&lt;br /&gt;
      &amp;quot;text&amp;quot;: &amp;quot;Partly Cloudy&amp;quot;,&lt;br /&gt;
      &amp;quot;low&amp;quot;: &amp;quot;53°F&amp;quot;,&lt;br /&gt;
      &amp;quot;high&amp;quot;: &amp;quot;65°F&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;credit&amp;quot;: &amp;quot;http://us.rd.yahoo.com/dailynews/rss/weather/St._Louis__MO/*http://weather.yahoo.com/forecast/USMO0170_f.html&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Weather Condition Images =====&lt;br /&gt;
&lt;br /&gt;
Each day's forecast has a code.  There are images associated with these codes.&lt;br /&gt;
&lt;br /&gt;
You can get images from here: &amp;lt;nowiki&amp;gt;http://us.i1.yimg.com/us.yimg.com/i/us/nws/weather/gr/&amp;lt;/nowiki&amp;gt;'''##'''&amp;lt;nowiki&amp;gt;ds.png&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Replace the '''##''' with the forecast code.  For example, for code 32, the URL would be: http://us.i1.yimg.com/us.yimg.com/i/us/nws/weather/gr/32ds.png&lt;br /&gt;
&lt;br /&gt;
=== jQuery Dialogs ===&lt;br /&gt;
&lt;br /&gt;
Helpful Resource: [http://docs.jquery.com/Main_Page jQuery Documentation] ... Some additional tips: [[jQuery]]&lt;br /&gt;
&lt;br /&gt;
Create a simple page using jQuery dialogs.&lt;br /&gt;
&lt;br /&gt;
* Create a page that has the words &amp;quot;Google&amp;quot; and &amp;quot;Yahoo&amp;quot;.&lt;br /&gt;
* When the user clicks the &amp;quot;Google&amp;quot; text, open a jQuery dialog window with one jQuery dialog button.  If the button is pressed, display the Google logo image (the image can be stored on your web server) on the web page, and if the dialog is closed any other way, do nothing.&lt;br /&gt;
* When the user clicks the &amp;quot;Yahoo&amp;quot; text, open a jQuery dialog window with one jQuery dialog button.  If the button is pressed, display the Yahoo logo image (the image can be stored on your web server) on the web page, and if the dialog is closed any other way, do nothing.&lt;br /&gt;
* Initially there should be no image on the page (i.e., the img should be hidden with the CSS display attribute).  After one of the two images is displayed, if the user clicks on the image, a jQuery dialog box should be opened with one dialog button, and if the button is pressed then the image should be hidden again.  Otherwise, do nothing.&lt;br /&gt;
&lt;br /&gt;
== Group Project ==&lt;br /&gt;
&lt;br /&gt;
You will work in pairs on this project.&lt;br /&gt;
&lt;br /&gt;
'''Important Reminder:''' frequently commit your work to your subversion repository as a backup!&lt;br /&gt;
&lt;br /&gt;
I forgot if I already mentioned this, but '''start early on this project!''' It will take longer than you think, I promise!&lt;br /&gt;
&lt;br /&gt;
=== Calendar ===&lt;br /&gt;
&lt;br /&gt;
Build a simple calendar that allows users to add and remove events dynamically.&lt;br /&gt;
&lt;br /&gt;
You will use JavaScript to process user interactions at the web browser, without ever refreshing the browser after the initial web page load.  You may use a JavaScript library of your choice, including jQuery.  (No extra credit will be given for ''not'' using a JavaScript library.)&lt;br /&gt;
&lt;br /&gt;
Your application should utilize AJAX to run server-side PHP scripts that query your database to save and retrieve information, including user accounts and events.&lt;br /&gt;
&lt;br /&gt;
==== Examples ====&lt;br /&gt;
&lt;br /&gt;
* https://calendar.google.com/&lt;br /&gt;
* http://www.zoho.com/calendar/&lt;br /&gt;
&lt;br /&gt;
==== Requirements ====&lt;br /&gt;
&lt;br /&gt;
* Support a month-by-month view of the calendar.&lt;br /&gt;
*: Show one month at a time, with buttons to move forward or backward.&lt;br /&gt;
*: There should be no limit to how far forward or backward the user can go.&lt;br /&gt;
* Users can register and log in to the website.&lt;br /&gt;
*: You may leverage your MySQL project code and database from last week to get started.&lt;br /&gt;
*: You may alternatively use OpenID for user authentication.  Note that you will still need a Users table in order associate calendar events with a certain OpenID.&lt;br /&gt;
* Unregistered users should see no events on the calendar.&lt;br /&gt;
* Registered users can add events.&lt;br /&gt;
*: All events should have a date and time, but do not need to have a duration.&lt;br /&gt;
*: You do ''not'' need to support recurring events (where you add an event that repeats, for example, every monday).&lt;br /&gt;
* Registered users see only events that they have added.&lt;br /&gt;
* Registered users can delete their events, but not the events of others.&lt;br /&gt;
* All user and event data should be kept in a database.&lt;br /&gt;
* At no time should the main page need to be reloaded.&lt;br /&gt;
*: User registration, user authentication, event addition, and event deletion should all be handled by JavaScript and AJAX requests to your server.&lt;br /&gt;
* Your page needs to work in the versions of Firefox and Chrome installed on the lab computers.&lt;br /&gt;
&lt;br /&gt;
'''Tip:''' Run your database schema by a TA before implementing it.&lt;br /&gt;
&lt;br /&gt;
==== Calendar Helper Library ====&lt;br /&gt;
&lt;br /&gt;
To help you get started with your calendar, we have written some JavaScript helper functions.  The code is available at:&lt;br /&gt;
* Full Version (for you to refer): http://cloud.sffc1.com/wustl/calendar.js&lt;br /&gt;
* Minified Version (to include in your pages): http://cloud.sffc1.com/wustl/calendar.min.js&lt;br /&gt;
&lt;br /&gt;
For example, this is how you would make a button to load the next month and show alerts containing all the days in the weeks contained by that month.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
// For our purposes, we can keep the current month in a variable in the global scope&lt;br /&gt;
var currentMonth = new Month(2012, 9); // October 2012&lt;br /&gt;
&lt;br /&gt;
// Change the month when the &amp;quot;next&amp;quot; button is pressed&lt;br /&gt;
document.getElementById(&amp;quot;next_month_btn&amp;quot;).addEventListener(&amp;quot;click&amp;quot;, function(event){&lt;br /&gt;
	currentMonth = currentMonth.nextMonth(); // Previous month would be currentMonth.prevMonth()&lt;br /&gt;
	updateCalendar(); // Whenever the month is updated, we'll need to re-render the calendar in HTML&lt;br /&gt;
	alert(&amp;quot;The new month is &amp;quot;+currentMonth.month+&amp;quot; &amp;quot;+currentMonth.year);&lt;br /&gt;
}, false);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
// This updateCalendar() function only alerts the dates in the currently specified month.  You need to write&lt;br /&gt;
// it to modify the DOM (optionally using jQuery) to display the days and weeks in the current month.&lt;br /&gt;
function updateCalendar(){&lt;br /&gt;
	var weeks = currentMonth.getWeeks();&lt;br /&gt;
	&lt;br /&gt;
	for(var w in weeks){&lt;br /&gt;
		var days = weeks[w].getDates();&lt;br /&gt;
		// days contains normal JavaScript Date objects.&lt;br /&gt;
		&lt;br /&gt;
		alert(&amp;quot;Week starting on &amp;quot;+days[0]);&lt;br /&gt;
		&lt;br /&gt;
		for(var d in days){&lt;br /&gt;
			// You can see console.log() output in your JavaScript debugging tool, like Firebug,&lt;br /&gt;
			// WebWit Inspector, or Dragonfly.&lt;br /&gt;
			console.log(days[d].toISOString());&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Important:''' JavaScript starts the months of a year, and the days of a week, at index 0.  This means that '''''in JavaScript, January is month 0, and December is month 11.'''''  Our calendar helper functions maintain this JavaScript convention.&lt;br /&gt;
&lt;br /&gt;
=== Web Security and Validation ===&lt;br /&gt;
&lt;br /&gt;
Your project needs to demonstrate that thought was put into web security and best practice.  For more information, see this week's Web Application Security guide: [[Web Application Security, Part 3]]&lt;br /&gt;
&lt;br /&gt;
In particular:&lt;br /&gt;
&lt;br /&gt;
* '''Your application needs to prevent XSS attacks.'''  The easiest way to prevent this is to continue sanitizing ''all'' of your output using '''htmlentities()'''.&lt;br /&gt;
* '''Perform precautionary measures to prevent session hijacking attacks.'''&lt;br /&gt;
*: You should specify your session cookie to be HTTP-Only.  However, for the means of this module, you need not test for user agent consistency.&lt;br /&gt;
* Validate your JavaScript code using [http://www.jshint.com/ JSHint]&lt;br /&gt;
&lt;br /&gt;
You should continue the practices that you have learned in past weeks:&lt;br /&gt;
&lt;br /&gt;
* Pass tokens in forms to prevent CSRF attacks&lt;br /&gt;
* Use prepared queries to prevent SQL Injection attacks&lt;br /&gt;
* If storing passwords in a database, always store them encrypted&lt;br /&gt;
* Your page should validate with no errors through the W3C validator.&lt;br /&gt;
&lt;br /&gt;
== Grading ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;font-size:2em; line-height:2em;&amp;quot;&amp;gt;'''Due Date: _____ (both individual and group)'''&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
!Assignment&lt;br /&gt;
!Points&lt;br /&gt;
|-&lt;br /&gt;
|Calculator&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
|Weather Widget&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|jQuery Dialogs&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
!colspan=&amp;quot;2&amp;quot;|Group Portion:&lt;br /&gt;
|-&lt;br /&gt;
|Calendar month view correct and Move between months (without page reload)&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|User authentication and registration (without page reload)&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Add events Events (new event shown in calendar without page reload)&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
|Events added are private and other users cannot see them&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
|Delete events (event removed from calendar without page reload)&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|-&lt;br /&gt;
|Safe from XSS and Session Hijacking&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|-&lt;br /&gt;
|Validation, CSRF, Salted Passwords, Safe SQL Queries, JSHint&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Creative Portion&lt;br /&gt;
|2&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
[[Category:Module 4]]&lt;br /&gt;
[[Category:Modules]]&lt;/div&gt;</summary>
		<author><name>Marc</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=Module_6&amp;diff=796</id>
		<title>Module 6</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=Module_6&amp;diff=796"/>
		<updated>2012-10-14T03:52:08Z</updated>

		<summary type="html">&lt;p&gt;Marc: /* Grading */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In Module 4, you will learn about JavaScript, the prevailing client-side language, and AJAX, a method for performing asynchronous updates to a web page (without refreshing the page).&lt;br /&gt;
&lt;br /&gt;
This article contains your assignments for Module 4.&lt;br /&gt;
&lt;br /&gt;
== Individual Assignments ==&lt;br /&gt;
&lt;br /&gt;
=== JavaScript Calculator ===&lt;br /&gt;
&lt;br /&gt;
In Module 2, you made a calculator using PHP.  Now you will be making one using JavaScript.&lt;br /&gt;
&lt;br /&gt;
Read the JavaScript guide first: [[Javascript and AJAX]]&lt;br /&gt;
&lt;br /&gt;
* The web page should have two input fields and a radio button group for the operation, with the 4 basic math operations represented (add,subtract,multiply,divide).&lt;br /&gt;
* The javascript should monitor all three fields and display the current result whenever the user changes any value in any field, without refreshing the page.&lt;br /&gt;
* The calculator should be completely self-contained; i.e., you should not be making any requests to any other server-side or client-side scripts or web pages after the initial page load.&lt;br /&gt;
&lt;br /&gt;
'''Tip:''' You can embed JavaScript code into an HTML document like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;
// your code here&lt;br /&gt;
&amp;lt;/script&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Tip:''' If your code isn't working the way you expect, use a JavaScript error console.  In Chrome, for example, press Ctrl-Shift-I (or Cmd-Option-I) to open the WebKit inspector.&lt;br /&gt;
&lt;br /&gt;
=== Weather Widget ===&lt;br /&gt;
&lt;br /&gt;
In this section, you will make a web page that displays the weather forecast using AJAX requests to a weather server.  You should complete this section ''without'' using JavaScript libraries like jQuery.&lt;br /&gt;
&lt;br /&gt;
# Make an empty HTML document; name it '''weather.html'''&lt;br /&gt;
#: Refer to the [[HTML and CSS]] guide for the skeleton of an HTML document&lt;br /&gt;
# Define a function in JavaScript; call it '''fetchWeather()'''.  You may write your JavaScript in an embedded script in your head tag.&lt;br /&gt;
# Inside your '''fetchWeather()''' function, make an AJAX request to the weather server.&lt;br /&gt;
#: We have a server that outputs the current weather in JSON format.  The format is documented in the [[#JSON Structure]] section below.&lt;br /&gt;
#: '''URL:''' http://cloud.sffc1.com/wustl/weather_json.php&lt;br /&gt;
#: We kindly thank Yahoo Weather for providing us with up-to-date weather information.&lt;br /&gt;
#* '''Note:''' You normally cannot perform AJAX requests cross-domain.  We have set the &amp;lt;code&amp;gt;Access-Control-Allow-Origin&amp;lt;/code&amp;gt; header on our server to allow requests from your EC2 instances.&lt;br /&gt;
# In your callback, process the JSON and use JavaScript to manipulate the HTML DOM to display the following information on your page:&lt;br /&gt;
#* Location&lt;br /&gt;
#** City, in a &amp;lt;nowiki&amp;gt;&amp;lt;strong&amp;gt;&amp;lt;/nowiki&amp;gt; tag&lt;br /&gt;
#** State, not in any tag&lt;br /&gt;
#* Humidity&lt;br /&gt;
#* Current Temperature&lt;br /&gt;
#* Image for Tomorrow's Forecast (see [[#Weather Condition Images]] below for more information)&lt;br /&gt;
#* Image for the Day After Tomorrow's Forecast&lt;br /&gt;
# Finally, bind '''fetchWeather()''' to the DOMContentReady event so that your weather widget is automatically initialized when the page is loaded:&lt;br /&gt;
#: &amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;document.addEventListener(&amp;quot;DOMContentReady&amp;quot;, fetchWeather, false);&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Use the following HTML:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;weather&amp;quot; id=&amp;quot;weatherWidget&amp;quot;&amp;gt;&lt;br /&gt;
	&amp;lt;div class=&amp;quot;weather-loc&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
	&amp;lt;div class=&amp;quot;weather-humidity&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
	&amp;lt;div class=&amp;quot;weather-temp&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
	&amp;lt;img class=&amp;quot;weather-tomorrow&amp;quot; /&amp;gt;&lt;br /&gt;
	&amp;lt;img class=&amp;quot;weather-dayaftertomorrow&amp;quot; /&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Include the CSS file from here: http://cloud.sffc1.com/wustl/weather.css&lt;br /&gt;
&lt;br /&gt;
When everything is working, the weather widget should look something like this:&lt;br /&gt;
&lt;br /&gt;
[[File:WeatherWidget.png]]&lt;br /&gt;
&lt;br /&gt;
'''Important:''' The widget in this section needs to work in only Firefox and Chrome.  It does '''''not''''' need to work Internet Explorer.&lt;br /&gt;
&lt;br /&gt;
==== Tips ====&lt;br /&gt;
&lt;br /&gt;
===== JSON Structure =====&lt;br /&gt;
&lt;br /&gt;
The JSON from our server looks like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
   &amp;quot;updated&amp;quot;: &amp;quot;Thu, 11 Oct 2012 5:54 pm CDT&amp;quot;,&lt;br /&gt;
   &amp;quot;location&amp;quot;: {&lt;br /&gt;
      &amp;quot;city&amp;quot;: &amp;quot;St. Louis&amp;quot;,&lt;br /&gt;
      &amp;quot;state&amp;quot;: &amp;quot;MO&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;wind&amp;quot;: {&lt;br /&gt;
      &amp;quot;chill&amp;quot;: &amp;quot;62&amp;quot;,&lt;br /&gt;
      &amp;quot;direction&amp;quot;: &amp;quot;150&amp;quot;,&lt;br /&gt;
      &amp;quot;speed&amp;quot;: &amp;quot;3 mph&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;atmosphere&amp;quot;: {&lt;br /&gt;
      &amp;quot;humidity&amp;quot;: &amp;quot;50&amp;quot;,&lt;br /&gt;
      &amp;quot;visibility&amp;quot;: &amp;quot;10&amp;quot;,&lt;br /&gt;
      &amp;quot;pressure&amp;quot;: &amp;quot;30.12 in&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;current&amp;quot;: {&lt;br /&gt;
      &amp;quot;code&amp;quot;: &amp;quot;28&amp;quot;,&lt;br /&gt;
      &amp;quot;text&amp;quot;: &amp;quot;Mostly Cloudy&amp;quot;,&lt;br /&gt;
      &amp;quot;temp&amp;quot;: &amp;quot;62°F&amp;quot;,&lt;br /&gt;
      &amp;quot;date&amp;quot;: &amp;quot;Thu, 11 Oct 2012 5:54 pm CDT&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;tomorrow&amp;quot;: {&lt;br /&gt;
      &amp;quot;code&amp;quot;: &amp;quot;29&amp;quot;,&lt;br /&gt;
      &amp;quot;text&amp;quot;: &amp;quot;Clouds Early/Clearing Late&amp;quot;,&lt;br /&gt;
      &amp;quot;low&amp;quot;: &amp;quot;45°F&amp;quot;,&lt;br /&gt;
      &amp;quot;high&amp;quot;: &amp;quot;61°F&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;dayafter&amp;quot;: {&lt;br /&gt;
      &amp;quot;code&amp;quot;: &amp;quot;30&amp;quot;,&lt;br /&gt;
      &amp;quot;text&amp;quot;: &amp;quot;Partly Cloudy&amp;quot;,&lt;br /&gt;
      &amp;quot;low&amp;quot;: &amp;quot;53°F&amp;quot;,&lt;br /&gt;
      &amp;quot;high&amp;quot;: &amp;quot;65°F&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;credit&amp;quot;: &amp;quot;http://us.rd.yahoo.com/dailynews/rss/weather/St._Louis__MO/*http://weather.yahoo.com/forecast/USMO0170_f.html&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Weather Condition Images =====&lt;br /&gt;
&lt;br /&gt;
Each day's forecast has a code.  There are images associated with these codes.&lt;br /&gt;
&lt;br /&gt;
You can get images from here: &amp;lt;nowiki&amp;gt;http://us.i1.yimg.com/us.yimg.com/i/us/nws/weather/gr/&amp;lt;/nowiki&amp;gt;'''##'''&amp;lt;nowiki&amp;gt;ds.png&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Replace the '''##''' with the forecast code.  For example, for code 32, the URL would be: http://us.i1.yimg.com/us.yimg.com/i/us/nws/weather/gr/32ds.png&lt;br /&gt;
&lt;br /&gt;
=== jQuery Dialogs ===&lt;br /&gt;
&lt;br /&gt;
Helpful Resource: [http://docs.jquery.com/Main_Page jQuery Documentation] ... Some additional tips: [[jQuery]]&lt;br /&gt;
&lt;br /&gt;
Create a simple page using jQuery dialogs.&lt;br /&gt;
&lt;br /&gt;
* Create a page that has the words &amp;quot;Google&amp;quot; and &amp;quot;Yahoo&amp;quot;.&lt;br /&gt;
* When the user clicks the &amp;quot;Google&amp;quot; text, open a jQuery dialog window with one jQuery dialog button.  If the button is pressed, display the Google logo image (the image can be stored on your web server) on the web page, and if the dialog is closed any other way, do nothing.&lt;br /&gt;
* When the user clicks the &amp;quot;Yahoo&amp;quot; text, open a jQuery dialog window with one jQuery dialog button.  If the button is pressed, display the Yahoo logo image (the image can be stored on your web server) on the web page, and if the dialog is closed any other way, do nothing.&lt;br /&gt;
* Initially there should be no image on the page (i.e., the img should be hidden with the CSS display attribute).  After one of the two images is displayed, if the user clicks on the image, a jQuery dialog box should be opened with one dialog button, and if the button is pressed then the image should be hidden again.  Otherwise, do nothing.&lt;br /&gt;
&lt;br /&gt;
== Group Project ==&lt;br /&gt;
&lt;br /&gt;
You will work in pairs on this project.&lt;br /&gt;
&lt;br /&gt;
'''Important Reminder:''' frequently commit your work to your subversion repository as a backup!&lt;br /&gt;
&lt;br /&gt;
I forgot if I already mentioned this, but '''start early on this project!''' It will take longer than you think, I promise!&lt;br /&gt;
&lt;br /&gt;
=== Calendar ===&lt;br /&gt;
&lt;br /&gt;
Build a simple calendar that allows users to add and remove events dynamically.&lt;br /&gt;
&lt;br /&gt;
You will use JavaScript to process user interactions at the web browser, without ever refreshing the browser after the initial web page load.  You may use a JavaScript library of your choice, including jQuery.  (No extra credit will be given for ''not'' using a JavaScript library.)&lt;br /&gt;
&lt;br /&gt;
Your application should utilize AJAX to run server-side PHP scripts that query your database to save and retrieve information, including user accounts and events.&lt;br /&gt;
&lt;br /&gt;
==== Examples ====&lt;br /&gt;
&lt;br /&gt;
* https://calendar.google.com/&lt;br /&gt;
* http://www.zoho.com/calendar/&lt;br /&gt;
&lt;br /&gt;
==== Requirements ====&lt;br /&gt;
&lt;br /&gt;
* Support a month-by-month view of the calendar.&lt;br /&gt;
*: Show one month at a time, with buttons to move forward or backward.&lt;br /&gt;
*: There should be no limit to how far forward or backward the user can go.&lt;br /&gt;
* Users can register and log in to the website.&lt;br /&gt;
*: You may leverage your MySQL project code and database from last week to get started.&lt;br /&gt;
*: You may alternatively use OpenID for user authentication.  Note that you will still need a Users table in order associate calendar events with a certain OpenID.&lt;br /&gt;
* Unregistered users should see no events on the calendar.&lt;br /&gt;
* Registered users can add events.&lt;br /&gt;
*: All events should have a date and time, but do not need to have a duration.&lt;br /&gt;
*: You do ''not'' need to support recurring events (where you add an event that repeats, for example, every monday).&lt;br /&gt;
* Registered users see only events that they have added.&lt;br /&gt;
* Registered users can delete their events, but not the events of others.&lt;br /&gt;
* All user and event data should be kept in a database.&lt;br /&gt;
* At no time should the main page need to be reloaded.&lt;br /&gt;
*: User registration, user authentication, event addition, and event deletion should all be handled by JavaScript and AJAX requests to your server.&lt;br /&gt;
* Your page needs to work in the versions of Firefox and Chrome installed on the lab computers.&lt;br /&gt;
&lt;br /&gt;
'''Tip:''' Run your database schema by a TA before implementing it.&lt;br /&gt;
&lt;br /&gt;
==== Calendar Helper Library ====&lt;br /&gt;
&lt;br /&gt;
To help you get started with your calendar, we have written some JavaScript helper functions.  The code is available at:&lt;br /&gt;
* Full Version (for you to refer): http://cloud.sffc1.com/wustl/calendar.js&lt;br /&gt;
* Minified Version (to include in your pages): http://cloud.sffc1.com/wustl/calendar.min.js&lt;br /&gt;
&lt;br /&gt;
For example, this is how you would make a button to load the next month and show alerts containing all the days in the weeks contained by that month.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
// For our purposes, we can keep the current month in a variable in the global scope&lt;br /&gt;
var currentMonth = new Month(2012, 9); // October 2012&lt;br /&gt;
&lt;br /&gt;
// Change the month when the &amp;quot;next&amp;quot; button is pressed&lt;br /&gt;
document.getElementById(&amp;quot;next_month_btn&amp;quot;).addEventListener(&amp;quot;click&amp;quot;, function(event){&lt;br /&gt;
	currentMonth = currentMonth.nextMonth(); // Previous month would be currentMonth.prevMonth()&lt;br /&gt;
	updateCalendar(); // Whenever the month is updated, we'll need to re-render the calendar in HTML&lt;br /&gt;
	alert(&amp;quot;The new month is &amp;quot;+currentMonth.month+&amp;quot; &amp;quot;+currentMonth.year);&lt;br /&gt;
}, false);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
// This updateCalendar() function only alerts the dates in the currently specified month.  You need to write&lt;br /&gt;
// it to modify the DOM (optionally using jQuery) to display the days and weeks in the current month.&lt;br /&gt;
function updateCalendar(){&lt;br /&gt;
	var weeks = currentMonth.getWeeks();&lt;br /&gt;
	&lt;br /&gt;
	for(var w in weeks){&lt;br /&gt;
		var days = weeks[w].getDates();&lt;br /&gt;
		// days contains normal JavaScript Date objects.&lt;br /&gt;
		&lt;br /&gt;
		alert(&amp;quot;Week starting on &amp;quot;+days[0]);&lt;br /&gt;
		&lt;br /&gt;
		for(var d in days){&lt;br /&gt;
			// You can see console.log() output in your JavaScript debugging tool, like Firebug,&lt;br /&gt;
			// WebWit Inspector, or Dragonfly.&lt;br /&gt;
			console.log(days[d].toISOString());&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Important:''' JavaScript starts the months of a year, and the days of a week, at index 0.  This means that '''''in JavaScript, January is month 0, and December is month 11.'''''  Our calendar helper functions maintain this JavaScript convention.&lt;br /&gt;
&lt;br /&gt;
=== Web Security and Validation ===&lt;br /&gt;
&lt;br /&gt;
Your project needs to demonstrate that thought was put into web security and best practice.  For more information, see this week's Web Application Security guide: [[Web Application Security, Part 3]]&lt;br /&gt;
&lt;br /&gt;
In particular:&lt;br /&gt;
&lt;br /&gt;
* '''Your application needs to prevent XSS attacks.'''  The easiest way to prevent this is to continue sanitizing ''all'' of your output using '''htmlentities()'''.&lt;br /&gt;
* '''Perform precautionary measures to prevent session hijacking attacks.'''&lt;br /&gt;
*: You should specify your session cookie to be HTTP-Only.  However, for the means of this module, you need not test for user agent consistency.&lt;br /&gt;
* '''Extra Credit:''' Validate your JavaScript code using [http://www.jshint.com/ JSHint]&lt;br /&gt;
&lt;br /&gt;
You should continue the practices that you have learned in past weeks:&lt;br /&gt;
&lt;br /&gt;
* Pass tokens in forms to prevent CSRF attacks&lt;br /&gt;
* Use prepared queries to prevent SQL Injection attacks&lt;br /&gt;
* If storing passwords in a database, always store them encrypted&lt;br /&gt;
* Your page should validate with no errors through the W3C validator.&lt;br /&gt;
&lt;br /&gt;
== Grading ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;font-size:2em; line-height:2em;&amp;quot;&amp;gt;'''Due Date: _____ (both individual and group)'''&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
!Assignment&lt;br /&gt;
!Points&lt;br /&gt;
|-&lt;br /&gt;
|Calculator&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
|Weather Widget&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|jQuery Dialogs&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
!colspan=&amp;quot;2&amp;quot;|Group Portion:&lt;br /&gt;
|-&lt;br /&gt;
|Calendar month view correct and Move between months (without page reload)&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|User authentication and registration (without page reload)&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Add events Events (new event shown in calendar without page reload)&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
|Events added are private and other users cannot see them&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
|Delete events (event removed from calendar without page reload)&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|-&lt;br /&gt;
|Safe from XSS and Session Hijacking&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|-&lt;br /&gt;
|Validation, CSRF, Salted Passwords, Safe SQL Queries, JSHint&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Creative Portion&lt;br /&gt;
|2&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
[[Category:Module 4]]&lt;br /&gt;
[[Category:Modules]]&lt;/div&gt;</summary>
		<author><name>Marc</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=Module_6&amp;diff=795</id>
		<title>Module 6</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=Module_6&amp;diff=795"/>
		<updated>2012-10-14T03:51:21Z</updated>

		<summary type="html">&lt;p&gt;Marc: /* Grading */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In Module 4, you will learn about JavaScript, the prevailing client-side language, and AJAX, a method for performing asynchronous updates to a web page (without refreshing the page).&lt;br /&gt;
&lt;br /&gt;
This article contains your assignments for Module 4.&lt;br /&gt;
&lt;br /&gt;
== Individual Assignments ==&lt;br /&gt;
&lt;br /&gt;
=== JavaScript Calculator ===&lt;br /&gt;
&lt;br /&gt;
In Module 2, you made a calculator using PHP.  Now you will be making one using JavaScript.&lt;br /&gt;
&lt;br /&gt;
Read the JavaScript guide first: [[Javascript and AJAX]]&lt;br /&gt;
&lt;br /&gt;
* The web page should have two input fields and a radio button group for the operation, with the 4 basic math operations represented (add,subtract,multiply,divide).&lt;br /&gt;
* The javascript should monitor all three fields and display the current result whenever the user changes any value in any field, without refreshing the page.&lt;br /&gt;
* The calculator should be completely self-contained; i.e., you should not be making any requests to any other server-side or client-side scripts or web pages after the initial page load.&lt;br /&gt;
&lt;br /&gt;
'''Tip:''' You can embed JavaScript code into an HTML document like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;
// your code here&lt;br /&gt;
&amp;lt;/script&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Tip:''' If your code isn't working the way you expect, use a JavaScript error console.  In Chrome, for example, press Ctrl-Shift-I (or Cmd-Option-I) to open the WebKit inspector.&lt;br /&gt;
&lt;br /&gt;
=== Weather Widget ===&lt;br /&gt;
&lt;br /&gt;
In this section, you will make a web page that displays the weather forecast using AJAX requests to a weather server.  You should complete this section ''without'' using JavaScript libraries like jQuery.&lt;br /&gt;
&lt;br /&gt;
# Make an empty HTML document; name it '''weather.html'''&lt;br /&gt;
#: Refer to the [[HTML and CSS]] guide for the skeleton of an HTML document&lt;br /&gt;
# Define a function in JavaScript; call it '''fetchWeather()'''.  You may write your JavaScript in an embedded script in your head tag.&lt;br /&gt;
# Inside your '''fetchWeather()''' function, make an AJAX request to the weather server.&lt;br /&gt;
#: We have a server that outputs the current weather in JSON format.  The format is documented in the [[#JSON Structure]] section below.&lt;br /&gt;
#: '''URL:''' http://cloud.sffc1.com/wustl/weather_json.php&lt;br /&gt;
#: We kindly thank Yahoo Weather for providing us with up-to-date weather information.&lt;br /&gt;
#* '''Note:''' You normally cannot perform AJAX requests cross-domain.  We have set the &amp;lt;code&amp;gt;Access-Control-Allow-Origin&amp;lt;/code&amp;gt; header on our server to allow requests from your EC2 instances.&lt;br /&gt;
# In your callback, process the JSON and use JavaScript to manipulate the HTML DOM to display the following information on your page:&lt;br /&gt;
#* Location&lt;br /&gt;
#** City, in a &amp;lt;nowiki&amp;gt;&amp;lt;strong&amp;gt;&amp;lt;/nowiki&amp;gt; tag&lt;br /&gt;
#** State, not in any tag&lt;br /&gt;
#* Humidity&lt;br /&gt;
#* Current Temperature&lt;br /&gt;
#* Image for Tomorrow's Forecast (see [[#Weather Condition Images]] below for more information)&lt;br /&gt;
#* Image for the Day After Tomorrow's Forecast&lt;br /&gt;
# Finally, bind '''fetchWeather()''' to the DOMContentReady event so that your weather widget is automatically initialized when the page is loaded:&lt;br /&gt;
#: &amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;document.addEventListener(&amp;quot;DOMContentReady&amp;quot;, fetchWeather, false);&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Use the following HTML:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;weather&amp;quot; id=&amp;quot;weatherWidget&amp;quot;&amp;gt;&lt;br /&gt;
	&amp;lt;div class=&amp;quot;weather-loc&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
	&amp;lt;div class=&amp;quot;weather-humidity&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
	&amp;lt;div class=&amp;quot;weather-temp&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
	&amp;lt;img class=&amp;quot;weather-tomorrow&amp;quot; /&amp;gt;&lt;br /&gt;
	&amp;lt;img class=&amp;quot;weather-dayaftertomorrow&amp;quot; /&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Include the CSS file from here: http://cloud.sffc1.com/wustl/weather.css&lt;br /&gt;
&lt;br /&gt;
When everything is working, the weather widget should look something like this:&lt;br /&gt;
&lt;br /&gt;
[[File:WeatherWidget.png]]&lt;br /&gt;
&lt;br /&gt;
'''Important:''' The widget in this section needs to work in only Firefox and Chrome.  It does '''''not''''' need to work Internet Explorer.&lt;br /&gt;
&lt;br /&gt;
==== Tips ====&lt;br /&gt;
&lt;br /&gt;
===== JSON Structure =====&lt;br /&gt;
&lt;br /&gt;
The JSON from our server looks like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
   &amp;quot;updated&amp;quot;: &amp;quot;Thu, 11 Oct 2012 5:54 pm CDT&amp;quot;,&lt;br /&gt;
   &amp;quot;location&amp;quot;: {&lt;br /&gt;
      &amp;quot;city&amp;quot;: &amp;quot;St. Louis&amp;quot;,&lt;br /&gt;
      &amp;quot;state&amp;quot;: &amp;quot;MO&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;wind&amp;quot;: {&lt;br /&gt;
      &amp;quot;chill&amp;quot;: &amp;quot;62&amp;quot;,&lt;br /&gt;
      &amp;quot;direction&amp;quot;: &amp;quot;150&amp;quot;,&lt;br /&gt;
      &amp;quot;speed&amp;quot;: &amp;quot;3 mph&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;atmosphere&amp;quot;: {&lt;br /&gt;
      &amp;quot;humidity&amp;quot;: &amp;quot;50&amp;quot;,&lt;br /&gt;
      &amp;quot;visibility&amp;quot;: &amp;quot;10&amp;quot;,&lt;br /&gt;
      &amp;quot;pressure&amp;quot;: &amp;quot;30.12 in&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;current&amp;quot;: {&lt;br /&gt;
      &amp;quot;code&amp;quot;: &amp;quot;28&amp;quot;,&lt;br /&gt;
      &amp;quot;text&amp;quot;: &amp;quot;Mostly Cloudy&amp;quot;,&lt;br /&gt;
      &amp;quot;temp&amp;quot;: &amp;quot;62°F&amp;quot;,&lt;br /&gt;
      &amp;quot;date&amp;quot;: &amp;quot;Thu, 11 Oct 2012 5:54 pm CDT&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;tomorrow&amp;quot;: {&lt;br /&gt;
      &amp;quot;code&amp;quot;: &amp;quot;29&amp;quot;,&lt;br /&gt;
      &amp;quot;text&amp;quot;: &amp;quot;Clouds Early/Clearing Late&amp;quot;,&lt;br /&gt;
      &amp;quot;low&amp;quot;: &amp;quot;45°F&amp;quot;,&lt;br /&gt;
      &amp;quot;high&amp;quot;: &amp;quot;61°F&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;dayafter&amp;quot;: {&lt;br /&gt;
      &amp;quot;code&amp;quot;: &amp;quot;30&amp;quot;,&lt;br /&gt;
      &amp;quot;text&amp;quot;: &amp;quot;Partly Cloudy&amp;quot;,&lt;br /&gt;
      &amp;quot;low&amp;quot;: &amp;quot;53°F&amp;quot;,&lt;br /&gt;
      &amp;quot;high&amp;quot;: &amp;quot;65°F&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;credit&amp;quot;: &amp;quot;http://us.rd.yahoo.com/dailynews/rss/weather/St._Louis__MO/*http://weather.yahoo.com/forecast/USMO0170_f.html&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Weather Condition Images =====&lt;br /&gt;
&lt;br /&gt;
Each day's forecast has a code.  There are images associated with these codes.&lt;br /&gt;
&lt;br /&gt;
You can get images from here: &amp;lt;nowiki&amp;gt;http://us.i1.yimg.com/us.yimg.com/i/us/nws/weather/gr/&amp;lt;/nowiki&amp;gt;'''##'''&amp;lt;nowiki&amp;gt;ds.png&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Replace the '''##''' with the forecast code.  For example, for code 32, the URL would be: http://us.i1.yimg.com/us.yimg.com/i/us/nws/weather/gr/32ds.png&lt;br /&gt;
&lt;br /&gt;
=== jQuery Dialogs ===&lt;br /&gt;
&lt;br /&gt;
Helpful Resource: [http://docs.jquery.com/Main_Page jQuery Documentation] ... Some additional tips: [[jQuery]]&lt;br /&gt;
&lt;br /&gt;
Create a simple page using jQuery dialogs.&lt;br /&gt;
&lt;br /&gt;
* Create a page that has the words &amp;quot;Google&amp;quot; and &amp;quot;Yahoo&amp;quot;.&lt;br /&gt;
* When the user clicks the &amp;quot;Google&amp;quot; text, open a jQuery dialog window with one jQuery dialog button.  If the button is pressed, display the Google logo image (the image can be stored on your web server) on the web page, and if the dialog is closed any other way, do nothing.&lt;br /&gt;
* When the user clicks the &amp;quot;Yahoo&amp;quot; text, open a jQuery dialog window with one jQuery dialog button.  If the button is pressed, display the Yahoo logo image (the image can be stored on your web server) on the web page, and if the dialog is closed any other way, do nothing.&lt;br /&gt;
* Initially there should be no image on the page (i.e., the img should be hidden with the CSS display attribute).  After one of the two images is displayed, if the user clicks on the image, a jQuery dialog box should be opened with one dialog button, and if the button is pressed then the image should be hidden again.  Otherwise, do nothing.&lt;br /&gt;
&lt;br /&gt;
== Group Project ==&lt;br /&gt;
&lt;br /&gt;
You will work in pairs on this project.&lt;br /&gt;
&lt;br /&gt;
'''Important Reminder:''' frequently commit your work to your subversion repository as a backup!&lt;br /&gt;
&lt;br /&gt;
I forgot if I already mentioned this, but '''start early on this project!''' It will take longer than you think, I promise!&lt;br /&gt;
&lt;br /&gt;
=== Calendar ===&lt;br /&gt;
&lt;br /&gt;
Build a simple calendar that allows users to add and remove events dynamically.&lt;br /&gt;
&lt;br /&gt;
You will use JavaScript to process user interactions at the web browser, without ever refreshing the browser after the initial web page load.  You may use a JavaScript library of your choice, including jQuery.  (No extra credit will be given for ''not'' using a JavaScript library.)&lt;br /&gt;
&lt;br /&gt;
Your application should utilize AJAX to run server-side PHP scripts that query your database to save and retrieve information, including user accounts and events.&lt;br /&gt;
&lt;br /&gt;
==== Examples ====&lt;br /&gt;
&lt;br /&gt;
* https://calendar.google.com/&lt;br /&gt;
* http://www.zoho.com/calendar/&lt;br /&gt;
&lt;br /&gt;
==== Requirements ====&lt;br /&gt;
&lt;br /&gt;
* Support a month-by-month view of the calendar.&lt;br /&gt;
*: Show one month at a time, with buttons to move forward or backward.&lt;br /&gt;
*: There should be no limit to how far forward or backward the user can go.&lt;br /&gt;
* Users can register and log in to the website.&lt;br /&gt;
*: You may leverage your MySQL project code and database from last week to get started.&lt;br /&gt;
*: You may alternatively use OpenID for user authentication.  Note that you will still need a Users table in order associate calendar events with a certain OpenID.&lt;br /&gt;
* Unregistered users should see no events on the calendar.&lt;br /&gt;
* Registered users can add events.&lt;br /&gt;
*: All events should have a date and time, but do not need to have a duration.&lt;br /&gt;
*: You do ''not'' need to support recurring events (where you add an event that repeats, for example, every monday).&lt;br /&gt;
* Registered users see only events that they have added.&lt;br /&gt;
* Registered users can delete their events, but not the events of others.&lt;br /&gt;
* All user and event data should be kept in a database.&lt;br /&gt;
* At no time should the main page need to be reloaded.&lt;br /&gt;
*: User registration, user authentication, event addition, and event deletion should all be handled by JavaScript and AJAX requests to your server.&lt;br /&gt;
* Your page needs to work in the versions of Firefox and Chrome installed on the lab computers.&lt;br /&gt;
&lt;br /&gt;
'''Tip:''' Run your database schema by a TA before implementing it.&lt;br /&gt;
&lt;br /&gt;
==== Calendar Helper Library ====&lt;br /&gt;
&lt;br /&gt;
To help you get started with your calendar, we have written some JavaScript helper functions.  The code is available at:&lt;br /&gt;
* Full Version (for you to refer): http://cloud.sffc1.com/wustl/calendar.js&lt;br /&gt;
* Minified Version (to include in your pages): http://cloud.sffc1.com/wustl/calendar.min.js&lt;br /&gt;
&lt;br /&gt;
For example, this is how you would make a button to load the next month and show alerts containing all the days in the weeks contained by that month.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
// For our purposes, we can keep the current month in a variable in the global scope&lt;br /&gt;
var currentMonth = new Month(2012, 9); // October 2012&lt;br /&gt;
&lt;br /&gt;
// Change the month when the &amp;quot;next&amp;quot; button is pressed&lt;br /&gt;
document.getElementById(&amp;quot;next_month_btn&amp;quot;).addEventListener(&amp;quot;click&amp;quot;, function(event){&lt;br /&gt;
	currentMonth = currentMonth.nextMonth(); // Previous month would be currentMonth.prevMonth()&lt;br /&gt;
	updateCalendar(); // Whenever the month is updated, we'll need to re-render the calendar in HTML&lt;br /&gt;
	alert(&amp;quot;The new month is &amp;quot;+currentMonth.month+&amp;quot; &amp;quot;+currentMonth.year);&lt;br /&gt;
}, false);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
// This updateCalendar() function only alerts the dates in the currently specified month.  You need to write&lt;br /&gt;
// it to modify the DOM (optionally using jQuery) to display the days and weeks in the current month.&lt;br /&gt;
function updateCalendar(){&lt;br /&gt;
	var weeks = currentMonth.getWeeks();&lt;br /&gt;
	&lt;br /&gt;
	for(var w in weeks){&lt;br /&gt;
		var days = weeks[w].getDates();&lt;br /&gt;
		// days contains normal JavaScript Date objects.&lt;br /&gt;
		&lt;br /&gt;
		alert(&amp;quot;Week starting on &amp;quot;+days[0]);&lt;br /&gt;
		&lt;br /&gt;
		for(var d in days){&lt;br /&gt;
			// You can see console.log() output in your JavaScript debugging tool, like Firebug,&lt;br /&gt;
			// WebWit Inspector, or Dragonfly.&lt;br /&gt;
			console.log(days[d].toISOString());&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Important:''' JavaScript starts the months of a year, and the days of a week, at index 0.  This means that '''''in JavaScript, January is month 0, and December is month 11.'''''  Our calendar helper functions maintain this JavaScript convention.&lt;br /&gt;
&lt;br /&gt;
=== Web Security and Validation ===&lt;br /&gt;
&lt;br /&gt;
Your project needs to demonstrate that thought was put into web security and best practice.  For more information, see this week's Web Application Security guide: [[Web Application Security, Part 3]]&lt;br /&gt;
&lt;br /&gt;
In particular:&lt;br /&gt;
&lt;br /&gt;
* '''Your application needs to prevent XSS attacks.'''  The easiest way to prevent this is to continue sanitizing ''all'' of your output using '''htmlentities()'''.&lt;br /&gt;
* '''Perform precautionary measures to prevent session hijacking attacks.'''&lt;br /&gt;
*: You should specify your session cookie to be HTTP-Only.  However, for the means of this module, you need not test for user agent consistency.&lt;br /&gt;
* '''Extra Credit:''' Validate your JavaScript code using [http://www.jshint.com/ JSHint]&lt;br /&gt;
&lt;br /&gt;
You should continue the practices that you have learned in past weeks:&lt;br /&gt;
&lt;br /&gt;
* Pass tokens in forms to prevent CSRF attacks&lt;br /&gt;
* Use prepared queries to prevent SQL Injection attacks&lt;br /&gt;
* If storing passwords in a database, always store them encrypted&lt;br /&gt;
* Your page should validate with no errors through the W3C validator.&lt;br /&gt;
&lt;br /&gt;
== Grading ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;font-size:2em; line-height:2em;&amp;quot;&amp;gt;'''Due Date: _____ (both individual and group)'''&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
!Assignment&lt;br /&gt;
!Points&lt;br /&gt;
|-&lt;br /&gt;
|Calculator&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
|Weather Widget&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|jQuery Dialogs&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
!colspan=&amp;quot;2&amp;quot;|Group Portion:&lt;br /&gt;
|-&lt;br /&gt;
|Calendar month view correct and Move between months (without page reload)&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|User authentication and registration (without page reload)&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Add events Events (new event shown in calendar without page reload)&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
|Events added are private and other users cannot see them&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
|Delete events (event removed from calendar without page reload)&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|-&lt;br /&gt;
|Safe from XSS and Session Hijacking&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|-&lt;br /&gt;
|Validation, CSRF, Salted Passwords, Safe SQL Queries&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Creative Portion&lt;br /&gt;
|2&lt;br /&gt;
|-&lt;br /&gt;
|'''Extra Credit:''' JavaScript passes JSHint test&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
[[Category:Module 4]]&lt;br /&gt;
[[Category:Modules]]&lt;/div&gt;</summary>
		<author><name>Marc</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=Module_6&amp;diff=794</id>
		<title>Module 6</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=Module_6&amp;diff=794"/>
		<updated>2012-10-14T03:50:12Z</updated>

		<summary type="html">&lt;p&gt;Marc: /* Grading */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In Module 4, you will learn about JavaScript, the prevailing client-side language, and AJAX, a method for performing asynchronous updates to a web page (without refreshing the page).&lt;br /&gt;
&lt;br /&gt;
This article contains your assignments for Module 4.&lt;br /&gt;
&lt;br /&gt;
== Individual Assignments ==&lt;br /&gt;
&lt;br /&gt;
=== JavaScript Calculator ===&lt;br /&gt;
&lt;br /&gt;
In Module 2, you made a calculator using PHP.  Now you will be making one using JavaScript.&lt;br /&gt;
&lt;br /&gt;
Read the JavaScript guide first: [[Javascript and AJAX]]&lt;br /&gt;
&lt;br /&gt;
* The web page should have two input fields and a radio button group for the operation, with the 4 basic math operations represented (add,subtract,multiply,divide).&lt;br /&gt;
* The javascript should monitor all three fields and display the current result whenever the user changes any value in any field, without refreshing the page.&lt;br /&gt;
* The calculator should be completely self-contained; i.e., you should not be making any requests to any other server-side or client-side scripts or web pages after the initial page load.&lt;br /&gt;
&lt;br /&gt;
'''Tip:''' You can embed JavaScript code into an HTML document like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;
// your code here&lt;br /&gt;
&amp;lt;/script&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Tip:''' If your code isn't working the way you expect, use a JavaScript error console.  In Chrome, for example, press Ctrl-Shift-I (or Cmd-Option-I) to open the WebKit inspector.&lt;br /&gt;
&lt;br /&gt;
=== Weather Widget ===&lt;br /&gt;
&lt;br /&gt;
In this section, you will make a web page that displays the weather forecast using AJAX requests to a weather server.  You should complete this section ''without'' using JavaScript libraries like jQuery.&lt;br /&gt;
&lt;br /&gt;
# Make an empty HTML document; name it '''weather.html'''&lt;br /&gt;
#: Refer to the [[HTML and CSS]] guide for the skeleton of an HTML document&lt;br /&gt;
# Define a function in JavaScript; call it '''fetchWeather()'''.  You may write your JavaScript in an embedded script in your head tag.&lt;br /&gt;
# Inside your '''fetchWeather()''' function, make an AJAX request to the weather server.&lt;br /&gt;
#: We have a server that outputs the current weather in JSON format.  The format is documented in the [[#JSON Structure]] section below.&lt;br /&gt;
#: '''URL:''' http://cloud.sffc1.com/wustl/weather_json.php&lt;br /&gt;
#: We kindly thank Yahoo Weather for providing us with up-to-date weather information.&lt;br /&gt;
#* '''Note:''' You normally cannot perform AJAX requests cross-domain.  We have set the &amp;lt;code&amp;gt;Access-Control-Allow-Origin&amp;lt;/code&amp;gt; header on our server to allow requests from your EC2 instances.&lt;br /&gt;
# In your callback, process the JSON and use JavaScript to manipulate the HTML DOM to display the following information on your page:&lt;br /&gt;
#* Location&lt;br /&gt;
#** City, in a &amp;lt;nowiki&amp;gt;&amp;lt;strong&amp;gt;&amp;lt;/nowiki&amp;gt; tag&lt;br /&gt;
#** State, not in any tag&lt;br /&gt;
#* Humidity&lt;br /&gt;
#* Current Temperature&lt;br /&gt;
#* Image for Tomorrow's Forecast (see [[#Weather Condition Images]] below for more information)&lt;br /&gt;
#* Image for the Day After Tomorrow's Forecast&lt;br /&gt;
# Finally, bind '''fetchWeather()''' to the DOMContentReady event so that your weather widget is automatically initialized when the page is loaded:&lt;br /&gt;
#: &amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;document.addEventListener(&amp;quot;DOMContentReady&amp;quot;, fetchWeather, false);&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Use the following HTML:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;weather&amp;quot; id=&amp;quot;weatherWidget&amp;quot;&amp;gt;&lt;br /&gt;
	&amp;lt;div class=&amp;quot;weather-loc&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
	&amp;lt;div class=&amp;quot;weather-humidity&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
	&amp;lt;div class=&amp;quot;weather-temp&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
	&amp;lt;img class=&amp;quot;weather-tomorrow&amp;quot; /&amp;gt;&lt;br /&gt;
	&amp;lt;img class=&amp;quot;weather-dayaftertomorrow&amp;quot; /&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Include the CSS file from here: http://cloud.sffc1.com/wustl/weather.css&lt;br /&gt;
&lt;br /&gt;
When everything is working, the weather widget should look something like this:&lt;br /&gt;
&lt;br /&gt;
[[File:WeatherWidget.png]]&lt;br /&gt;
&lt;br /&gt;
'''Important:''' The widget in this section needs to work in only Firefox and Chrome.  It does '''''not''''' need to work Internet Explorer.&lt;br /&gt;
&lt;br /&gt;
==== Tips ====&lt;br /&gt;
&lt;br /&gt;
===== JSON Structure =====&lt;br /&gt;
&lt;br /&gt;
The JSON from our server looks like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
   &amp;quot;updated&amp;quot;: &amp;quot;Thu, 11 Oct 2012 5:54 pm CDT&amp;quot;,&lt;br /&gt;
   &amp;quot;location&amp;quot;: {&lt;br /&gt;
      &amp;quot;city&amp;quot;: &amp;quot;St. Louis&amp;quot;,&lt;br /&gt;
      &amp;quot;state&amp;quot;: &amp;quot;MO&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;wind&amp;quot;: {&lt;br /&gt;
      &amp;quot;chill&amp;quot;: &amp;quot;62&amp;quot;,&lt;br /&gt;
      &amp;quot;direction&amp;quot;: &amp;quot;150&amp;quot;,&lt;br /&gt;
      &amp;quot;speed&amp;quot;: &amp;quot;3 mph&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;atmosphere&amp;quot;: {&lt;br /&gt;
      &amp;quot;humidity&amp;quot;: &amp;quot;50&amp;quot;,&lt;br /&gt;
      &amp;quot;visibility&amp;quot;: &amp;quot;10&amp;quot;,&lt;br /&gt;
      &amp;quot;pressure&amp;quot;: &amp;quot;30.12 in&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;current&amp;quot;: {&lt;br /&gt;
      &amp;quot;code&amp;quot;: &amp;quot;28&amp;quot;,&lt;br /&gt;
      &amp;quot;text&amp;quot;: &amp;quot;Mostly Cloudy&amp;quot;,&lt;br /&gt;
      &amp;quot;temp&amp;quot;: &amp;quot;62°F&amp;quot;,&lt;br /&gt;
      &amp;quot;date&amp;quot;: &amp;quot;Thu, 11 Oct 2012 5:54 pm CDT&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;tomorrow&amp;quot;: {&lt;br /&gt;
      &amp;quot;code&amp;quot;: &amp;quot;29&amp;quot;,&lt;br /&gt;
      &amp;quot;text&amp;quot;: &amp;quot;Clouds Early/Clearing Late&amp;quot;,&lt;br /&gt;
      &amp;quot;low&amp;quot;: &amp;quot;45°F&amp;quot;,&lt;br /&gt;
      &amp;quot;high&amp;quot;: &amp;quot;61°F&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;dayafter&amp;quot;: {&lt;br /&gt;
      &amp;quot;code&amp;quot;: &amp;quot;30&amp;quot;,&lt;br /&gt;
      &amp;quot;text&amp;quot;: &amp;quot;Partly Cloudy&amp;quot;,&lt;br /&gt;
      &amp;quot;low&amp;quot;: &amp;quot;53°F&amp;quot;,&lt;br /&gt;
      &amp;quot;high&amp;quot;: &amp;quot;65°F&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;credit&amp;quot;: &amp;quot;http://us.rd.yahoo.com/dailynews/rss/weather/St._Louis__MO/*http://weather.yahoo.com/forecast/USMO0170_f.html&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Weather Condition Images =====&lt;br /&gt;
&lt;br /&gt;
Each day's forecast has a code.  There are images associated with these codes.&lt;br /&gt;
&lt;br /&gt;
You can get images from here: &amp;lt;nowiki&amp;gt;http://us.i1.yimg.com/us.yimg.com/i/us/nws/weather/gr/&amp;lt;/nowiki&amp;gt;'''##'''&amp;lt;nowiki&amp;gt;ds.png&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Replace the '''##''' with the forecast code.  For example, for code 32, the URL would be: http://us.i1.yimg.com/us.yimg.com/i/us/nws/weather/gr/32ds.png&lt;br /&gt;
&lt;br /&gt;
=== jQuery Dialogs ===&lt;br /&gt;
&lt;br /&gt;
Helpful Resource: [http://docs.jquery.com/Main_Page jQuery Documentation] ... Some additional tips: [[jQuery]]&lt;br /&gt;
&lt;br /&gt;
Create a simple page using jQuery dialogs.&lt;br /&gt;
&lt;br /&gt;
* Create a page that has the words &amp;quot;Google&amp;quot; and &amp;quot;Yahoo&amp;quot;.&lt;br /&gt;
* When the user clicks the &amp;quot;Google&amp;quot; text, open a jQuery dialog window with one jQuery dialog button.  If the button is pressed, display the Google logo image (the image can be stored on your web server) on the web page, and if the dialog is closed any other way, do nothing.&lt;br /&gt;
* When the user clicks the &amp;quot;Yahoo&amp;quot; text, open a jQuery dialog window with one jQuery dialog button.  If the button is pressed, display the Yahoo logo image (the image can be stored on your web server) on the web page, and if the dialog is closed any other way, do nothing.&lt;br /&gt;
* Initially there should be no image on the page (i.e., the img should be hidden with the CSS display attribute).  After one of the two images is displayed, if the user clicks on the image, a jQuery dialog box should be opened with one dialog button, and if the button is pressed then the image should be hidden again.  Otherwise, do nothing.&lt;br /&gt;
&lt;br /&gt;
== Group Project ==&lt;br /&gt;
&lt;br /&gt;
You will work in pairs on this project.&lt;br /&gt;
&lt;br /&gt;
'''Important Reminder:''' frequently commit your work to your subversion repository as a backup!&lt;br /&gt;
&lt;br /&gt;
I forgot if I already mentioned this, but '''start early on this project!''' It will take longer than you think, I promise!&lt;br /&gt;
&lt;br /&gt;
=== Calendar ===&lt;br /&gt;
&lt;br /&gt;
Build a simple calendar that allows users to add and remove events dynamically.&lt;br /&gt;
&lt;br /&gt;
You will use JavaScript to process user interactions at the web browser, without ever refreshing the browser after the initial web page load.  You may use a JavaScript library of your choice, including jQuery.  (No extra credit will be given for ''not'' using a JavaScript library.)&lt;br /&gt;
&lt;br /&gt;
Your application should utilize AJAX to run server-side PHP scripts that query your database to save and retrieve information, including user accounts and events.&lt;br /&gt;
&lt;br /&gt;
==== Examples ====&lt;br /&gt;
&lt;br /&gt;
* https://calendar.google.com/&lt;br /&gt;
* http://www.zoho.com/calendar/&lt;br /&gt;
&lt;br /&gt;
==== Requirements ====&lt;br /&gt;
&lt;br /&gt;
* Support a month-by-month view of the calendar.&lt;br /&gt;
*: Show one month at a time, with buttons to move forward or backward.&lt;br /&gt;
*: There should be no limit to how far forward or backward the user can go.&lt;br /&gt;
* Users can register and log in to the website.&lt;br /&gt;
*: You may leverage your MySQL project code and database from last week to get started.&lt;br /&gt;
*: You may alternatively use OpenID for user authentication.  Note that you will still need a Users table in order associate calendar events with a certain OpenID.&lt;br /&gt;
* Unregistered users should see no events on the calendar.&lt;br /&gt;
* Registered users can add events.&lt;br /&gt;
*: All events should have a date and time, but do not need to have a duration.&lt;br /&gt;
*: You do ''not'' need to support recurring events (where you add an event that repeats, for example, every monday).&lt;br /&gt;
* Registered users see only events that they have added.&lt;br /&gt;
* Registered users can delete their events, but not the events of others.&lt;br /&gt;
* All user and event data should be kept in a database.&lt;br /&gt;
* At no time should the main page need to be reloaded.&lt;br /&gt;
*: User registration, user authentication, event addition, and event deletion should all be handled by JavaScript and AJAX requests to your server.&lt;br /&gt;
* Your page needs to work in the versions of Firefox and Chrome installed on the lab computers.&lt;br /&gt;
&lt;br /&gt;
'''Tip:''' Run your database schema by a TA before implementing it.&lt;br /&gt;
&lt;br /&gt;
==== Calendar Helper Library ====&lt;br /&gt;
&lt;br /&gt;
To help you get started with your calendar, we have written some JavaScript helper functions.  The code is available at:&lt;br /&gt;
* Full Version (for you to refer): http://cloud.sffc1.com/wustl/calendar.js&lt;br /&gt;
* Minified Version (to include in your pages): http://cloud.sffc1.com/wustl/calendar.min.js&lt;br /&gt;
&lt;br /&gt;
For example, this is how you would make a button to load the next month and show alerts containing all the days in the weeks contained by that month.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
// For our purposes, we can keep the current month in a variable in the global scope&lt;br /&gt;
var currentMonth = new Month(2012, 9); // October 2012&lt;br /&gt;
&lt;br /&gt;
// Change the month when the &amp;quot;next&amp;quot; button is pressed&lt;br /&gt;
document.getElementById(&amp;quot;next_month_btn&amp;quot;).addEventListener(&amp;quot;click&amp;quot;, function(event){&lt;br /&gt;
	currentMonth = currentMonth.nextMonth(); // Previous month would be currentMonth.prevMonth()&lt;br /&gt;
	updateCalendar(); // Whenever the month is updated, we'll need to re-render the calendar in HTML&lt;br /&gt;
	alert(&amp;quot;The new month is &amp;quot;+currentMonth.month+&amp;quot; &amp;quot;+currentMonth.year);&lt;br /&gt;
}, false);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
// This updateCalendar() function only alerts the dates in the currently specified month.  You need to write&lt;br /&gt;
// it to modify the DOM (optionally using jQuery) to display the days and weeks in the current month.&lt;br /&gt;
function updateCalendar(){&lt;br /&gt;
	var weeks = currentMonth.getWeeks();&lt;br /&gt;
	&lt;br /&gt;
	for(var w in weeks){&lt;br /&gt;
		var days = weeks[w].getDates();&lt;br /&gt;
		// days contains normal JavaScript Date objects.&lt;br /&gt;
		&lt;br /&gt;
		alert(&amp;quot;Week starting on &amp;quot;+days[0]);&lt;br /&gt;
		&lt;br /&gt;
		for(var d in days){&lt;br /&gt;
			// You can see console.log() output in your JavaScript debugging tool, like Firebug,&lt;br /&gt;
			// WebWit Inspector, or Dragonfly.&lt;br /&gt;
			console.log(days[d].toISOString());&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Important:''' JavaScript starts the months of a year, and the days of a week, at index 0.  This means that '''''in JavaScript, January is month 0, and December is month 11.'''''  Our calendar helper functions maintain this JavaScript convention.&lt;br /&gt;
&lt;br /&gt;
=== Web Security and Validation ===&lt;br /&gt;
&lt;br /&gt;
Your project needs to demonstrate that thought was put into web security and best practice.  For more information, see this week's Web Application Security guide: [[Web Application Security, Part 3]]&lt;br /&gt;
&lt;br /&gt;
In particular:&lt;br /&gt;
&lt;br /&gt;
* '''Your application needs to prevent XSS attacks.'''  The easiest way to prevent this is to continue sanitizing ''all'' of your output using '''htmlentities()'''.&lt;br /&gt;
* '''Perform precautionary measures to prevent session hijacking attacks.'''&lt;br /&gt;
*: You should specify your session cookie to be HTTP-Only.  However, for the means of this module, you need not test for user agent consistency.&lt;br /&gt;
* '''Extra Credit:''' Validate your JavaScript code using [http://www.jshint.com/ JSHint]&lt;br /&gt;
&lt;br /&gt;
You should continue the practices that you have learned in past weeks:&lt;br /&gt;
&lt;br /&gt;
* Pass tokens in forms to prevent CSRF attacks&lt;br /&gt;
* Use prepared queries to prevent SQL Injection attacks&lt;br /&gt;
* If storing passwords in a database, always store them encrypted&lt;br /&gt;
* Your page should validate with no errors through the W3C validator.&lt;br /&gt;
&lt;br /&gt;
== Grading ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;font-size:2em; line-height:2em;&amp;quot;&amp;gt;'''Due Date: _____ (both individual and group)'''&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
!Assignment&lt;br /&gt;
!Points&lt;br /&gt;
|-&lt;br /&gt;
|Calculator&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
|Weather Widget&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|jQuery Dialogs&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
!colspan=&amp;quot;2&amp;quot;|Group Portion:&lt;br /&gt;
|-&lt;br /&gt;
|Calendar month view correct and Move between months (without page reload)&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|User authentication and registration (without page reload)&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Add events and Private Events (new event shown in calendar without page reload)&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Delete events (event removed from calendar without page reload)&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|-&lt;br /&gt;
|Safe from XSS and Session Hijacking&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|-&lt;br /&gt;
|Validation, CSRF, Salted Passwords, Safe SQL Queries&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Creative Portion&lt;br /&gt;
|2&lt;br /&gt;
|-&lt;br /&gt;
|'''Extra Credit:''' JavaScript passes JSHint test&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
[[Category:Module 4]]&lt;br /&gt;
[[Category:Modules]]&lt;/div&gt;</summary>
		<author><name>Marc</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=Module_6&amp;diff=793</id>
		<title>Module 6</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=Module_6&amp;diff=793"/>
		<updated>2012-10-14T03:47:56Z</updated>

		<summary type="html">&lt;p&gt;Marc: /* Grading */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In Module 4, you will learn about JavaScript, the prevailing client-side language, and AJAX, a method for performing asynchronous updates to a web page (without refreshing the page).&lt;br /&gt;
&lt;br /&gt;
This article contains your assignments for Module 4.&lt;br /&gt;
&lt;br /&gt;
== Individual Assignments ==&lt;br /&gt;
&lt;br /&gt;
=== JavaScript Calculator ===&lt;br /&gt;
&lt;br /&gt;
In Module 2, you made a calculator using PHP.  Now you will be making one using JavaScript.&lt;br /&gt;
&lt;br /&gt;
Read the JavaScript guide first: [[Javascript and AJAX]]&lt;br /&gt;
&lt;br /&gt;
* The web page should have two input fields and a radio button group for the operation, with the 4 basic math operations represented (add,subtract,multiply,divide).&lt;br /&gt;
* The javascript should monitor all three fields and display the current result whenever the user changes any value in any field, without refreshing the page.&lt;br /&gt;
* The calculator should be completely self-contained; i.e., you should not be making any requests to any other server-side or client-side scripts or web pages after the initial page load.&lt;br /&gt;
&lt;br /&gt;
'''Tip:''' You can embed JavaScript code into an HTML document like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;
// your code here&lt;br /&gt;
&amp;lt;/script&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Tip:''' If your code isn't working the way you expect, use a JavaScript error console.  In Chrome, for example, press Ctrl-Shift-I (or Cmd-Option-I) to open the WebKit inspector.&lt;br /&gt;
&lt;br /&gt;
=== Weather Widget ===&lt;br /&gt;
&lt;br /&gt;
In this section, you will make a web page that displays the weather forecast using AJAX requests to a weather server.  You should complete this section ''without'' using JavaScript libraries like jQuery.&lt;br /&gt;
&lt;br /&gt;
# Make an empty HTML document; name it '''weather.html'''&lt;br /&gt;
#: Refer to the [[HTML and CSS]] guide for the skeleton of an HTML document&lt;br /&gt;
# Define a function in JavaScript; call it '''fetchWeather()'''.  You may write your JavaScript in an embedded script in your head tag.&lt;br /&gt;
# Inside your '''fetchWeather()''' function, make an AJAX request to the weather server.&lt;br /&gt;
#: We have a server that outputs the current weather in JSON format.  The format is documented in the [[#JSON Structure]] section below.&lt;br /&gt;
#: '''URL:''' http://cloud.sffc1.com/wustl/weather_json.php&lt;br /&gt;
#: We kindly thank Yahoo Weather for providing us with up-to-date weather information.&lt;br /&gt;
#* '''Note:''' You normally cannot perform AJAX requests cross-domain.  We have set the &amp;lt;code&amp;gt;Access-Control-Allow-Origin&amp;lt;/code&amp;gt; header on our server to allow requests from your EC2 instances.&lt;br /&gt;
# In your callback, process the JSON and use JavaScript to manipulate the HTML DOM to display the following information on your page:&lt;br /&gt;
#* Location&lt;br /&gt;
#** City, in a &amp;lt;nowiki&amp;gt;&amp;lt;strong&amp;gt;&amp;lt;/nowiki&amp;gt; tag&lt;br /&gt;
#** State, not in any tag&lt;br /&gt;
#* Humidity&lt;br /&gt;
#* Current Temperature&lt;br /&gt;
#* Image for Tomorrow's Forecast (see [[#Weather Condition Images]] below for more information)&lt;br /&gt;
#* Image for the Day After Tomorrow's Forecast&lt;br /&gt;
# Finally, bind '''fetchWeather()''' to the DOMContentReady event so that your weather widget is automatically initialized when the page is loaded:&lt;br /&gt;
#: &amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;document.addEventListener(&amp;quot;DOMContentReady&amp;quot;, fetchWeather, false);&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Use the following HTML:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;weather&amp;quot; id=&amp;quot;weatherWidget&amp;quot;&amp;gt;&lt;br /&gt;
	&amp;lt;div class=&amp;quot;weather-loc&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
	&amp;lt;div class=&amp;quot;weather-humidity&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
	&amp;lt;div class=&amp;quot;weather-temp&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
	&amp;lt;img class=&amp;quot;weather-tomorrow&amp;quot; /&amp;gt;&lt;br /&gt;
	&amp;lt;img class=&amp;quot;weather-dayaftertomorrow&amp;quot; /&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Include the CSS file from here: http://cloud.sffc1.com/wustl/weather.css&lt;br /&gt;
&lt;br /&gt;
When everything is working, the weather widget should look something like this:&lt;br /&gt;
&lt;br /&gt;
[[File:WeatherWidget.png]]&lt;br /&gt;
&lt;br /&gt;
'''Important:''' The widget in this section needs to work in only Firefox and Chrome.  It does '''''not''''' need to work Internet Explorer.&lt;br /&gt;
&lt;br /&gt;
==== Tips ====&lt;br /&gt;
&lt;br /&gt;
===== JSON Structure =====&lt;br /&gt;
&lt;br /&gt;
The JSON from our server looks like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
   &amp;quot;updated&amp;quot;: &amp;quot;Thu, 11 Oct 2012 5:54 pm CDT&amp;quot;,&lt;br /&gt;
   &amp;quot;location&amp;quot;: {&lt;br /&gt;
      &amp;quot;city&amp;quot;: &amp;quot;St. Louis&amp;quot;,&lt;br /&gt;
      &amp;quot;state&amp;quot;: &amp;quot;MO&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;wind&amp;quot;: {&lt;br /&gt;
      &amp;quot;chill&amp;quot;: &amp;quot;62&amp;quot;,&lt;br /&gt;
      &amp;quot;direction&amp;quot;: &amp;quot;150&amp;quot;,&lt;br /&gt;
      &amp;quot;speed&amp;quot;: &amp;quot;3 mph&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;atmosphere&amp;quot;: {&lt;br /&gt;
      &amp;quot;humidity&amp;quot;: &amp;quot;50&amp;quot;,&lt;br /&gt;
      &amp;quot;visibility&amp;quot;: &amp;quot;10&amp;quot;,&lt;br /&gt;
      &amp;quot;pressure&amp;quot;: &amp;quot;30.12 in&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;current&amp;quot;: {&lt;br /&gt;
      &amp;quot;code&amp;quot;: &amp;quot;28&amp;quot;,&lt;br /&gt;
      &amp;quot;text&amp;quot;: &amp;quot;Mostly Cloudy&amp;quot;,&lt;br /&gt;
      &amp;quot;temp&amp;quot;: &amp;quot;62°F&amp;quot;,&lt;br /&gt;
      &amp;quot;date&amp;quot;: &amp;quot;Thu, 11 Oct 2012 5:54 pm CDT&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;tomorrow&amp;quot;: {&lt;br /&gt;
      &amp;quot;code&amp;quot;: &amp;quot;29&amp;quot;,&lt;br /&gt;
      &amp;quot;text&amp;quot;: &amp;quot;Clouds Early/Clearing Late&amp;quot;,&lt;br /&gt;
      &amp;quot;low&amp;quot;: &amp;quot;45°F&amp;quot;,&lt;br /&gt;
      &amp;quot;high&amp;quot;: &amp;quot;61°F&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;dayafter&amp;quot;: {&lt;br /&gt;
      &amp;quot;code&amp;quot;: &amp;quot;30&amp;quot;,&lt;br /&gt;
      &amp;quot;text&amp;quot;: &amp;quot;Partly Cloudy&amp;quot;,&lt;br /&gt;
      &amp;quot;low&amp;quot;: &amp;quot;53°F&amp;quot;,&lt;br /&gt;
      &amp;quot;high&amp;quot;: &amp;quot;65°F&amp;quot;&lt;br /&gt;
   },&lt;br /&gt;
   &amp;quot;credit&amp;quot;: &amp;quot;http://us.rd.yahoo.com/dailynews/rss/weather/St._Louis__MO/*http://weather.yahoo.com/forecast/USMO0170_f.html&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Weather Condition Images =====&lt;br /&gt;
&lt;br /&gt;
Each day's forecast has a code.  There are images associated with these codes.&lt;br /&gt;
&lt;br /&gt;
You can get images from here: &amp;lt;nowiki&amp;gt;http://us.i1.yimg.com/us.yimg.com/i/us/nws/weather/gr/&amp;lt;/nowiki&amp;gt;'''##'''&amp;lt;nowiki&amp;gt;ds.png&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Replace the '''##''' with the forecast code.  For example, for code 32, the URL would be: http://us.i1.yimg.com/us.yimg.com/i/us/nws/weather/gr/32ds.png&lt;br /&gt;
&lt;br /&gt;
=== jQuery Dialogs ===&lt;br /&gt;
&lt;br /&gt;
Helpful Resource: [http://docs.jquery.com/Main_Page jQuery Documentation] ... Some additional tips: [[jQuery]]&lt;br /&gt;
&lt;br /&gt;
Create a simple page using jQuery dialogs.&lt;br /&gt;
&lt;br /&gt;
* Create a page that has the words &amp;quot;Google&amp;quot; and &amp;quot;Yahoo&amp;quot;.&lt;br /&gt;
* When the user clicks the &amp;quot;Google&amp;quot; text, open a jQuery dialog window with one jQuery dialog button.  If the button is pressed, display the Google logo image (the image can be stored on your web server) on the web page, and if the dialog is closed any other way, do nothing.&lt;br /&gt;
* When the user clicks the &amp;quot;Yahoo&amp;quot; text, open a jQuery dialog window with one jQuery dialog button.  If the button is pressed, display the Yahoo logo image (the image can be stored on your web server) on the web page, and if the dialog is closed any other way, do nothing.&lt;br /&gt;
* Initially there should be no image on the page (i.e., the img should be hidden with the CSS display attribute).  After one of the two images is displayed, if the user clicks on the image, a jQuery dialog box should be opened with one dialog button, and if the button is pressed then the image should be hidden again.  Otherwise, do nothing.&lt;br /&gt;
&lt;br /&gt;
== Group Project ==&lt;br /&gt;
&lt;br /&gt;
You will work in pairs on this project.&lt;br /&gt;
&lt;br /&gt;
'''Important Reminder:''' frequently commit your work to your subversion repository as a backup!&lt;br /&gt;
&lt;br /&gt;
I forgot if I already mentioned this, but '''start early on this project!''' It will take longer than you think, I promise!&lt;br /&gt;
&lt;br /&gt;
=== Calendar ===&lt;br /&gt;
&lt;br /&gt;
Build a simple calendar that allows users to add and remove events dynamically.&lt;br /&gt;
&lt;br /&gt;
You will use JavaScript to process user interactions at the web browser, without ever refreshing the browser after the initial web page load.  You may use a JavaScript library of your choice, including jQuery.  (No extra credit will be given for ''not'' using a JavaScript library.)&lt;br /&gt;
&lt;br /&gt;
Your application should utilize AJAX to run server-side PHP scripts that query your database to save and retrieve information, including user accounts and events.&lt;br /&gt;
&lt;br /&gt;
==== Examples ====&lt;br /&gt;
&lt;br /&gt;
* https://calendar.google.com/&lt;br /&gt;
* http://www.zoho.com/calendar/&lt;br /&gt;
&lt;br /&gt;
==== Requirements ====&lt;br /&gt;
&lt;br /&gt;
* Support a month-by-month view of the calendar.&lt;br /&gt;
*: Show one month at a time, with buttons to move forward or backward.&lt;br /&gt;
*: There should be no limit to how far forward or backward the user can go.&lt;br /&gt;
* Users can register and log in to the website.&lt;br /&gt;
*: You may leverage your MySQL project code and database from last week to get started.&lt;br /&gt;
*: You may alternatively use OpenID for user authentication.  Note that you will still need a Users table in order associate calendar events with a certain OpenID.&lt;br /&gt;
* Unregistered users should see no events on the calendar.&lt;br /&gt;
* Registered users can add events.&lt;br /&gt;
*: All events should have a date and time, but do not need to have a duration.&lt;br /&gt;
*: You do ''not'' need to support recurring events (where you add an event that repeats, for example, every monday).&lt;br /&gt;
* Registered users see only events that they have added.&lt;br /&gt;
* Registered users can delete their events, but not the events of others.&lt;br /&gt;
* All user and event data should be kept in a database.&lt;br /&gt;
* At no time should the main page need to be reloaded.&lt;br /&gt;
*: User registration, user authentication, event addition, and event deletion should all be handled by JavaScript and AJAX requests to your server.&lt;br /&gt;
* Your page needs to work in the versions of Firefox and Chrome installed on the lab computers.&lt;br /&gt;
&lt;br /&gt;
'''Tip:''' Run your database schema by a TA before implementing it.&lt;br /&gt;
&lt;br /&gt;
==== Calendar Helper Library ====&lt;br /&gt;
&lt;br /&gt;
To help you get started with your calendar, we have written some JavaScript helper functions.  The code is available at:&lt;br /&gt;
* Full Version (for you to refer): http://cloud.sffc1.com/wustl/calendar.js&lt;br /&gt;
* Minified Version (to include in your pages): http://cloud.sffc1.com/wustl/calendar.min.js&lt;br /&gt;
&lt;br /&gt;
For example, this is how you would make a button to load the next month and show alerts containing all the days in the weeks contained by that month.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
// For our purposes, we can keep the current month in a variable in the global scope&lt;br /&gt;
var currentMonth = new Month(2012, 9); // October 2012&lt;br /&gt;
&lt;br /&gt;
// Change the month when the &amp;quot;next&amp;quot; button is pressed&lt;br /&gt;
document.getElementById(&amp;quot;next_month_btn&amp;quot;).addEventListener(&amp;quot;click&amp;quot;, function(event){&lt;br /&gt;
	currentMonth = currentMonth.nextMonth(); // Previous month would be currentMonth.prevMonth()&lt;br /&gt;
	updateCalendar(); // Whenever the month is updated, we'll need to re-render the calendar in HTML&lt;br /&gt;
	alert(&amp;quot;The new month is &amp;quot;+currentMonth.month+&amp;quot; &amp;quot;+currentMonth.year);&lt;br /&gt;
}, false);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
// This updateCalendar() function only alerts the dates in the currently specified month.  You need to write&lt;br /&gt;
// it to modify the DOM (optionally using jQuery) to display the days and weeks in the current month.&lt;br /&gt;
function updateCalendar(){&lt;br /&gt;
	var weeks = currentMonth.getWeeks();&lt;br /&gt;
	&lt;br /&gt;
	for(var w in weeks){&lt;br /&gt;
		var days = weeks[w].getDates();&lt;br /&gt;
		// days contains normal JavaScript Date objects.&lt;br /&gt;
		&lt;br /&gt;
		alert(&amp;quot;Week starting on &amp;quot;+days[0]);&lt;br /&gt;
		&lt;br /&gt;
		for(var d in days){&lt;br /&gt;
			// You can see console.log() output in your JavaScript debugging tool, like Firebug,&lt;br /&gt;
			// WebWit Inspector, or Dragonfly.&lt;br /&gt;
			console.log(days[d].toISOString());&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Important:''' JavaScript starts the months of a year, and the days of a week, at index 0.  This means that '''''in JavaScript, January is month 0, and December is month 11.'''''  Our calendar helper functions maintain this JavaScript convention.&lt;br /&gt;
&lt;br /&gt;
=== Web Security and Validation ===&lt;br /&gt;
&lt;br /&gt;
Your project needs to demonstrate that thought was put into web security and best practice.  For more information, see this week's Web Application Security guide: [[Web Application Security, Part 3]]&lt;br /&gt;
&lt;br /&gt;
In particular:&lt;br /&gt;
&lt;br /&gt;
* '''Your application needs to prevent XSS attacks.'''  The easiest way to prevent this is to continue sanitizing ''all'' of your output using '''htmlentities()'''.&lt;br /&gt;
* '''Perform precautionary measures to prevent session hijacking attacks.'''&lt;br /&gt;
*: You should specify your session cookie to be HTTP-Only.  However, for the means of this module, you need not test for user agent consistency.&lt;br /&gt;
* '''Extra Credit:''' Validate your JavaScript code using [http://www.jshint.com/ JSHint]&lt;br /&gt;
&lt;br /&gt;
You should continue the practices that you have learned in past weeks:&lt;br /&gt;
&lt;br /&gt;
* Pass tokens in forms to prevent CSRF attacks&lt;br /&gt;
* Use prepared queries to prevent SQL Injection attacks&lt;br /&gt;
* If storing passwords in a database, always store them encrypted&lt;br /&gt;
* Your page should validate with no errors through the W3C validator.&lt;br /&gt;
&lt;br /&gt;
== Grading ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;font-size:2em; line-height:2em;&amp;quot;&amp;gt;'''Due Date: _____ (both individual and group)'''&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
!Assignment&lt;br /&gt;
!Points&lt;br /&gt;
|-&lt;br /&gt;
|Calculator&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
|Weather Widget&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|jQuery Dialogs&lt;br /&gt;
|0.5&lt;br /&gt;
|-&lt;br /&gt;
!colspan=&amp;quot;2&amp;quot;|Group Portion:&lt;br /&gt;
|-&lt;br /&gt;
|Calendar month view correct&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Move between months (without page reload)&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|User authentication and registration (without page reload)&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Add events (new event shown in calendar without page reload)&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Delete events (event removed from calendar without page reload)&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|User events are private&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Safe from XSS&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Safe from Session Hijacking&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Validation, CSRF, Salted Passwords, Safe SQL Queries&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Creative Portion&lt;br /&gt;
|2&lt;br /&gt;
|-&lt;br /&gt;
|'''Extra Credit:''' JavaScript passes JSHint test&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
[[Category:Module 4]]&lt;br /&gt;
[[Category:Modules]]&lt;/div&gt;</summary>
		<author><name>Marc</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=Module_3&amp;diff=706</id>
		<title>Module 3</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=Module_3&amp;diff=706"/>
		<updated>2012-09-25T02:14:25Z</updated>

		<summary type="html">&lt;p&gt;Marc: /* Grading */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In Module 3, you will learn about MySQL, a web application database.&lt;br /&gt;
&lt;br /&gt;
This article contains your assignments for Module 3.&lt;br /&gt;
&lt;br /&gt;
== Individual Assignments ==&lt;br /&gt;
&lt;br /&gt;
You will create a simple grades database containing four tables.&lt;br /&gt;
&lt;br /&gt;
'''IMPORTANT:''' The individual assignment is to be done by writing queries by hand.  (You can use phpMyAdmin to run the queries, but '''do not let phpMyAdmin write your queries for you!''')  Writing your own queries gives you a greater understanding of the underlying mechanisms and databases in general.  Additionally, having SQL knowledge and experience is a very marketable trait.&lt;br /&gt;
&lt;br /&gt;
=== Install MySQL and phpMyAdmin ===&lt;br /&gt;
&lt;br /&gt;
Before you start, '''you need to install MySQL''' on your EC2 instance.  You may also install phpMyAdmin, a web frontend to MySQL, if you choose to do so.&lt;br /&gt;
&lt;br /&gt;
You may find the following article to be very helpful: [[Introduction to MySQL]]&lt;br /&gt;
&lt;br /&gt;
=== Set Up a Database ===&lt;br /&gt;
&lt;br /&gt;
You may find the following article to be very helpful: [[Introduction to MySQL]]&lt;br /&gt;
&lt;br /&gt;
# Create a database named '''wustl''' &lt;br /&gt;
# Create a user named '''wustl_inst''' and give them the password '''wustl_pass'''&lt;br /&gt;
&lt;br /&gt;
=== Create Tables ===&lt;br /&gt;
&lt;br /&gt;
You may find the following article to be very helpful: [[MySQL Schema and State]]&lt;br /&gt;
&lt;br /&gt;
When creating tables, keep the following items in mind:&lt;br /&gt;
&lt;br /&gt;
* You should create all tables such that they use the InnoDB storage engine, since we wish to make use of its support of foreign keys. In other database engines, foreign key constraints are not enforced.  (If you mess up, you can use ALTER TABLE to change the storage engine.)&lt;br /&gt;
* Where it is appropriate, you should take advantage of the ability to define fields NOT NULL so that you do not inadvertently insert incomplete data for a row.&lt;br /&gt;
&lt;br /&gt;
Create the following tables:&lt;br /&gt;
&lt;br /&gt;
# Create a table named '''students''' with the following fields:&lt;br /&gt;
#* '''id''' of an appropriately-sized unsigned integer type (we will never need to process more than a million students)&lt;br /&gt;
#* '''first_name''' of type '''VARCHAR(50)'''&lt;br /&gt;
#* '''last_name''' of type '''VARCHAR(50)'''&lt;br /&gt;
#* '''email_address''' of type '''VARCHAR(50)'''&lt;br /&gt;
#: The primary key should be on the '''id''' field.&lt;br /&gt;
# Create a table named '''departments''' with the following fields:&lt;br /&gt;
#* '''school_code''' of type '''ENUM''' (e.g. &amp;quot;L&amp;quot; for ArtSci and &amp;quot;E&amp;quot; for Engineering).  The options are as follows:&lt;br /&gt;
#*: 'L', 'B', 'A', 'F', 'E', 'T', 'I', 'W', 'S', 'U', 'M'&lt;br /&gt;
#* '''dept_id''' of an appropriately-sized unsigned integer type (in the foreseeable future there will never be more than 200 departments in a school)&lt;br /&gt;
#* '''abbreviation''' of type '''VARCHAR(9)''' (e.g. CSE, ChemE, etc)&lt;br /&gt;
#* '''dept_name''' of type '''VARCHAR(200)''' (e.g. Computer Science and Engineering)&lt;br /&gt;
#: The primary key should be on two fields: '''school_code''' and '''dept_id'''&lt;br /&gt;
#: '''Note:''' Why not just use the department ID? The ID numbers are sometimes reused across schools. For instance, department 33 in The School of Arts and Sciences is Psychology while department 33 in The School of Engineering and Applied Sciences is Energy, Environmental and Chemical Engineering. Thus we must also include the school code to differentiate them  such that the record for  E33 is distinct from that of L33.&lt;br /&gt;
# Create a table named '''courses''' with the following fields:&lt;br /&gt;
#* '''school_code''' of type '''ENUM'''&lt;br /&gt;
#*: This should have the same letters in the same order as the '''school_code''' '''ENUM''' field in the '''departments''' table.&lt;br /&gt;
#* '''dept_id''' of the same size of integer as in the '''departments''' table&lt;br /&gt;
#* '''course_code''' of type '''CHAR(5)''' (this will hold course codes; e.g., '330S', '131', '2960')&lt;br /&gt;
#* '''name''' of type '''VARCHAR(150)'''&lt;br /&gt;
#: The appropriate fields in this table should make a foreign key reference to the corresponding fields in '''department'''.&lt;br /&gt;
#: In addition, it is up to you to determine the field(s) for the primary key.&lt;br /&gt;
#: '''Note:''' If you are unsure which fields to make the foreign keys and feel the need to beg your friends or the TAs to give you the answer, bang your head on your desk whilst repeating &amp;quot;I WILL EXERCISE REASON AND COMMON SENSE AND I WILL CURTAIL MY DESIRE TO BLINDLY FOLLOW DIRECTIONS&amp;quot;&lt;br /&gt;
#: ''Disclaimer: don't actually bang your head on your desk, the resulting head trauma may in fact make it harder for you to determine which fields should have associated foreign keys.''&lt;br /&gt;
# Create a table named '''grades''' with the following fields:&lt;br /&gt;
#* '''pk_grade_ID''' of an appropriately-sized unsigned integer type (should be larger than the one you chose for the '''students''' table)&lt;br /&gt;
#*: You should declare this field to be '''auto_increment''' and make it the primary key.&lt;br /&gt;
#*: This is called a ''surrogate key'' as opposed to a ''natural key'' because it doesn't arise &amp;quot;naturally&amp;quot; from the data; that is to say that it is not derived from application data. The use of surrogate keys vs. natural keys is a polemic issue amongst database designers.  For a decently unbiased take on the issue, see this page: http://www.agiledata.org/essays/keys.html#Comparison&lt;br /&gt;
#*: '''Food for thought:''' Aside from simply exposing you to the concept, can you think of any reasons why a surrogate key might be preferable for this table?  Alternatively, what attributes, if any, could you use as a natural key, and what might be the drawbacks of doing so?&lt;br /&gt;
#* '''student_id''' of the same integer (unsigned) type that you chose in the '''students''' table&lt;br /&gt;
#* '''grade''' of type '''decimal'''&lt;br /&gt;
#* '''school_code''' of type '''ENUM'''&lt;br /&gt;
#*: Can you guess what entries to use for the enum?&lt;br /&gt;
#* '''dept_id''' of the same integer type that you've used for this field in other tables&lt;br /&gt;
#* '''course_code''' of the same type you chose for the course code in the '''courses''' table&lt;br /&gt;
#: The '''grades''' table should have foreign keys to both the '''students''' table and the '''courses''' table.&lt;br /&gt;
&lt;br /&gt;
=== Populate Tables ===&lt;br /&gt;
&lt;br /&gt;
Now, populate the tables by downloading the text files given below and loading them into the appropriate tables.&lt;br /&gt;
&lt;br /&gt;
'''Note:''' Do not insert all the values manually; instead, use the MySQL's ability to load in data from text files.&lt;br /&gt;
&lt;br /&gt;
You may find the following article to be very helpful: [[MySQL Schema and State]]&lt;br /&gt;
&lt;br /&gt;
The files containing the data are:&lt;br /&gt;
&lt;br /&gt;
* students: https://docs.google.com/file/d/0ByHgvetJ0GJyMGFjMWI4MzAtMzljYy00Yjk3LTllMWItZjZkYmU1NzU3NWU0/edit&lt;br /&gt;
* courses: https://docs.google.com/file/d/0ByHgvetJ0GJyMGY1NGYzYmUtNGQwYi00MTY3LTkzMjgtMDYwOTM3NDNjZTg4/edit&lt;br /&gt;
* departments: https://docs.google.com/file/d/0ByHgvetJ0GJyZWY2OWE4ZWEtYzVmMC00YjBiLWEzZjgtYzdhMDczODAyNDli/edit&lt;br /&gt;
* grades: https://docs.google.com/file/d/0ByHgvetJ0GJyZmJjNzllNjAtMzdhZC00MzU5LTg3MDYtMTRmMjE5MDE2MzY2/edit&lt;br /&gt;
&lt;br /&gt;
=== Insert More Data ===&lt;br /&gt;
&lt;br /&gt;
Insert the following data into the tables that you have created and populated:&lt;br /&gt;
&lt;br /&gt;
# Insert an entry for CSE 330&lt;br /&gt;
#: ''If you don't know CSE's department code, how can you find out using the tables in the database?''&lt;br /&gt;
# Insert the grades given for the students named below.  You may choose to make the entries for whichever classes you like, with the one condition that all of the students must have a grade for CSE 330 (who wouldn't want to take that class: I hear the professor and TAs are amazing!)&lt;br /&gt;
#* '''Ben Harper'''&lt;br /&gt;
#** E-mail: '''bharper@ffym.com'''&lt;br /&gt;
#** Student ID: '''88'''&lt;br /&gt;
#** Grades:&lt;br /&gt;
#*** 5.5&lt;br /&gt;
#*** 0&lt;br /&gt;
#*** 20&lt;br /&gt;
#* '''Matt Freeman'''&lt;br /&gt;
#** E-mail: '''mfreeman@kickinbassist.net'''&lt;br /&gt;
#** Student ID: '''202'''&lt;br /&gt;
#** Grades:&lt;br /&gt;
#*** 100&lt;br /&gt;
#*** 90.5&lt;br /&gt;
#*** 94.8&lt;br /&gt;
#* '''Marc Roberge'''&lt;br /&gt;
#** E-mail: '''mroberge@ofarevolution.us'''&lt;br /&gt;
#** Student ID: '''115'''&lt;br /&gt;
#** Grades:&lt;br /&gt;
#*** 15&lt;br /&gt;
#*** 37&lt;br /&gt;
#*** 45.5&lt;br /&gt;
#: You may choose any 3 classes you'd like for them to be enrolled in, with at least one class, &amp;quot;CSE 330S&amp;quot;, in which they are all enrolled.&lt;br /&gt;
&lt;br /&gt;
=== Querying Your Database ===&lt;br /&gt;
&lt;br /&gt;
Now that you have a fully-functional, populated database, let's do some queries on it!&lt;br /&gt;
&lt;br /&gt;
Please take a screenshot of running the following '''select''' queries and show them to a TA (be sure to include your query command and the response:&lt;br /&gt;
&lt;br /&gt;
# Select the entire grades table.&lt;br /&gt;
# Select all fields describing the courses offered in the school of arts and sciences (school code L).&lt;br /&gt;
# The names, student IDs, and grades of the students who are in CSE330.&lt;br /&gt;
# The names and e-mails of any student with an average below 50 so that the dean can send them an email notification that they are now on academic probation.&lt;br /&gt;
#: ''You should be able to do this in only one query, without making any temporary tables.  You will need to use aggregation functions and the '''having''' keyword.''&lt;br /&gt;
# An individual report card for Jack Johnson, consisting of two tables (these can be done using separate queries):&lt;br /&gt;
## His student ID, e-mail address, and average grade.&lt;br /&gt;
##: ''Again, you should be able to do this in just one query, using the correct combination of aggregation functions and joins.''&lt;br /&gt;
## The classes he is in and his grades for those classes. To give you an idea, one row in the table should look like this:&lt;br /&gt;
##: &amp;lt;code&amp;gt;E	81	400	Independent Study	98.5&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Group Project ==&lt;br /&gt;
&lt;br /&gt;
You will work in pairs on this project.  You may work with the same partner from Module 2, or change to someone else.&lt;br /&gt;
&lt;br /&gt;
'''Important Reminder:''' frequently commit your work to your subversion repository as a backup!&lt;br /&gt;
&lt;br /&gt;
=== Simple News Web Site ===&lt;br /&gt;
&lt;br /&gt;
'''Examples:'''&lt;br /&gt;
* http://digg.com/&lt;br /&gt;
* http://slashdot.org/&lt;br /&gt;
&lt;br /&gt;
You should use '''PHP''' unless you get permission to use another web technology from the instructor.  You may also use phpMyAdmin to help set up databases.&lt;br /&gt;
&lt;br /&gt;
You may find this wiki article helpful: [[PHP and MySQL]]&lt;br /&gt;
&lt;br /&gt;
==== Requirements ====&lt;br /&gt;
&lt;br /&gt;
* Users can register for accounts and then log in to the website.&lt;br /&gt;
* Accounts should have both a username and a ''secure'' password.  '''NEVER store plaintext passwords in a database!'''&lt;br /&gt;
*: For more information on password security, refer to [[Web Application Security, Part 2#Password Security|the Web Application Security guide]].&lt;br /&gt;
* Registered users can submit stories: either a link with summary or news text.&lt;br /&gt;
*: You do not have to make a distinction between the two types of stories, although if you want to, you could do something with this for the creative portion of your project.&lt;br /&gt;
* Registered users can comment on any story.&lt;br /&gt;
* Administrator users can delete stories and comments.&lt;br /&gt;
* Unregistered users can only view stories and comments.&lt;br /&gt;
* Registered users can edit their stories and can delete their comments.&lt;br /&gt;
* All data must be kept in a MySQL database (user information, stories, comments, and categories).&lt;br /&gt;
* As before, please check with a TA to see if your creative portion is okay or not before you proceed.&lt;br /&gt;
&lt;br /&gt;
=== Web Security and Validation ===&lt;br /&gt;
&lt;br /&gt;
Your project needs to demonstrate that thought was put into web security and best practice.  For more information, see this week's Web Application Security guide: [[Web Application Security, Part 2]]&lt;br /&gt;
&lt;br /&gt;
In particular:&lt;br /&gt;
&lt;br /&gt;
* '''Your application needs to be secure from SQL injection attacks'''. If you are using prepared queries, you should already be safe on this front.&lt;br /&gt;
* '''All of your output needs to be sanitized using htmlentities()'''.&lt;br /&gt;
&lt;br /&gt;
You shouldn't forget the practices you learned last week:&lt;br /&gt;
&lt;br /&gt;
* '''You should pass tokens in forms''' to prevent CSRF attacks.&lt;br /&gt;
* '''Your page should validate''' with no errors through the W3C validator.&lt;br /&gt;
&lt;br /&gt;
== Grading ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;font-size:2em; line-height:2em;&amp;quot;&amp;gt;'''Due Date: Wednesday October 10th, by 1pm (both individual and group)'''&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
!Assignment&lt;br /&gt;
!Points&lt;br /&gt;
|-&lt;br /&gt;
|Tables Correct&lt;br /&gt;
|2&lt;br /&gt;
|-&lt;br /&gt;
|Data Queries Correct&lt;br /&gt;
|2&lt;br /&gt;
|-&lt;br /&gt;
!colspan=&amp;quot;2&amp;quot;|Group Portion:&lt;br /&gt;
|-&lt;br /&gt;
|User Authentication&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|User Registration&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Salted One-Way Encryption&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Main page displays all stories (or most recent stories)&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Page with individual story and comments&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Story Submission&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Comment System&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Administrator Deletion of Stories/Comments&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|User Edit of Story (1 pt) and Comment (1 pt)&lt;br /&gt;
|2&lt;br /&gt;
|-&lt;br /&gt;
|Protect Against SQL Injection Attack&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Sanitize Output&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|CSRF Safe and Validation&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Creative Portion&lt;br /&gt;
|2&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Total Points = 19&lt;br /&gt;
[[Category:Module 3]]&lt;br /&gt;
[[Category:Modules]]&lt;/div&gt;</summary>
		<author><name>Marc</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=Module_3&amp;diff=705</id>
		<title>Module 3</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=Module_3&amp;diff=705"/>
		<updated>2012-09-25T02:13:20Z</updated>

		<summary type="html">&lt;p&gt;Marc: /* Grading */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In Module 3, you will learn about MySQL, a web application database.&lt;br /&gt;
&lt;br /&gt;
This article contains your assignments for Module 3.&lt;br /&gt;
&lt;br /&gt;
== Individual Assignments ==&lt;br /&gt;
&lt;br /&gt;
You will create a simple grades database containing four tables.&lt;br /&gt;
&lt;br /&gt;
'''IMPORTANT:''' The individual assignment is to be done by writing queries by hand.  (You can use phpMyAdmin to run the queries, but '''do not let phpMyAdmin write your queries for you!''')  Writing your own queries gives you a greater understanding of the underlying mechanisms and databases in general.  Additionally, having SQL knowledge and experience is a very marketable trait.&lt;br /&gt;
&lt;br /&gt;
=== Install MySQL and phpMyAdmin ===&lt;br /&gt;
&lt;br /&gt;
Before you start, '''you need to install MySQL''' on your EC2 instance.  You may also install phpMyAdmin, a web frontend to MySQL, if you choose to do so.&lt;br /&gt;
&lt;br /&gt;
You may find the following article to be very helpful: [[Introduction to MySQL]]&lt;br /&gt;
&lt;br /&gt;
=== Set Up a Database ===&lt;br /&gt;
&lt;br /&gt;
You may find the following article to be very helpful: [[Introduction to MySQL]]&lt;br /&gt;
&lt;br /&gt;
# Create a database named '''wustl''' &lt;br /&gt;
# Create a user named '''wustl_inst''' and give them the password '''wustl_pass'''&lt;br /&gt;
&lt;br /&gt;
=== Create Tables ===&lt;br /&gt;
&lt;br /&gt;
You may find the following article to be very helpful: [[MySQL Schema and State]]&lt;br /&gt;
&lt;br /&gt;
When creating tables, keep the following items in mind:&lt;br /&gt;
&lt;br /&gt;
* You should create all tables such that they use the InnoDB storage engine, since we wish to make use of its support of foreign keys. In other database engines, foreign key constraints are not enforced.  (If you mess up, you can use ALTER TABLE to change the storage engine.)&lt;br /&gt;
* Where it is appropriate, you should take advantage of the ability to define fields NOT NULL so that you do not inadvertently insert incomplete data for a row.&lt;br /&gt;
&lt;br /&gt;
Create the following tables:&lt;br /&gt;
&lt;br /&gt;
# Create a table named '''students''' with the following fields:&lt;br /&gt;
#* '''id''' of an appropriately-sized unsigned integer type (we will never need to process more than a million students)&lt;br /&gt;
#* '''first_name''' of type '''VARCHAR(50)'''&lt;br /&gt;
#* '''last_name''' of type '''VARCHAR(50)'''&lt;br /&gt;
#* '''email_address''' of type '''VARCHAR(50)'''&lt;br /&gt;
#: The primary key should be on the '''id''' field.&lt;br /&gt;
# Create a table named '''departments''' with the following fields:&lt;br /&gt;
#* '''school_code''' of type '''ENUM''' (e.g. &amp;quot;L&amp;quot; for ArtSci and &amp;quot;E&amp;quot; for Engineering).  The options are as follows:&lt;br /&gt;
#*: 'L', 'B', 'A', 'F', 'E', 'T', 'I', 'W', 'S', 'U', 'M'&lt;br /&gt;
#* '''dept_id''' of an appropriately-sized unsigned integer type (in the foreseeable future there will never be more than 200 departments in a school)&lt;br /&gt;
#* '''abbreviation''' of type '''VARCHAR(9)''' (e.g. CSE, ChemE, etc)&lt;br /&gt;
#* '''dept_name''' of type '''VARCHAR(200)''' (e.g. Computer Science and Engineering)&lt;br /&gt;
#: The primary key should be on two fields: '''school_code''' and '''dept_id'''&lt;br /&gt;
#: '''Note:''' Why not just use the department ID? The ID numbers are sometimes reused across schools. For instance, department 33 in The School of Arts and Sciences is Psychology while department 33 in The School of Engineering and Applied Sciences is Energy, Environmental and Chemical Engineering. Thus we must also include the school code to differentiate them  such that the record for  E33 is distinct from that of L33.&lt;br /&gt;
# Create a table named '''courses''' with the following fields:&lt;br /&gt;
#* '''school_code''' of type '''ENUM'''&lt;br /&gt;
#*: This should have the same letters in the same order as the '''school_code''' '''ENUM''' field in the '''departments''' table.&lt;br /&gt;
#* '''dept_id''' of the same size of integer as in the '''departments''' table&lt;br /&gt;
#* '''course_code''' of type '''CHAR(5)''' (this will hold course codes; e.g., '330S', '131', '2960')&lt;br /&gt;
#* '''name''' of type '''VARCHAR(150)'''&lt;br /&gt;
#: The appropriate fields in this table should make a foreign key reference to the corresponding fields in '''department'''.&lt;br /&gt;
#: In addition, it is up to you to determine the field(s) for the primary key.&lt;br /&gt;
#: '''Note:''' If you are unsure which fields to make the foreign keys and feel the need to beg your friends or the TAs to give you the answer, bang your head on your desk whilst repeating &amp;quot;I WILL EXERCISE REASON AND COMMON SENSE AND I WILL CURTAIL MY DESIRE TO BLINDLY FOLLOW DIRECTIONS&amp;quot;&lt;br /&gt;
#: ''Disclaimer: don't actually bang your head on your desk, the resulting head trauma may in fact make it harder for you to determine which fields should have associated foreign keys.''&lt;br /&gt;
# Create a table named '''grades''' with the following fields:&lt;br /&gt;
#* '''pk_grade_ID''' of an appropriately-sized unsigned integer type (should be larger than the one you chose for the '''students''' table)&lt;br /&gt;
#*: You should declare this field to be '''auto_increment''' and make it the primary key.&lt;br /&gt;
#*: This is called a ''surrogate key'' as opposed to a ''natural key'' because it doesn't arise &amp;quot;naturally&amp;quot; from the data; that is to say that it is not derived from application data. The use of surrogate keys vs. natural keys is a polemic issue amongst database designers.  For a decently unbiased take on the issue, see this page: http://www.agiledata.org/essays/keys.html#Comparison&lt;br /&gt;
#*: '''Food for thought:''' Aside from simply exposing you to the concept, can you think of any reasons why a surrogate key might be preferable for this table?  Alternatively, what attributes, if any, could you use as a natural key, and what might be the drawbacks of doing so?&lt;br /&gt;
#* '''student_id''' of the same integer (unsigned) type that you chose in the '''students''' table&lt;br /&gt;
#* '''grade''' of type '''decimal'''&lt;br /&gt;
#* '''school_code''' of type '''ENUM'''&lt;br /&gt;
#*: Can you guess what entries to use for the enum?&lt;br /&gt;
#* '''dept_id''' of the same integer type that you've used for this field in other tables&lt;br /&gt;
#* '''course_code''' of the same type you chose for the course code in the '''courses''' table&lt;br /&gt;
#: The '''grades''' table should have foreign keys to both the '''students''' table and the '''courses''' table.&lt;br /&gt;
&lt;br /&gt;
=== Populate Tables ===&lt;br /&gt;
&lt;br /&gt;
Now, populate the tables by downloading the text files given below and loading them into the appropriate tables.&lt;br /&gt;
&lt;br /&gt;
'''Note:''' Do not insert all the values manually; instead, use the MySQL's ability to load in data from text files.&lt;br /&gt;
&lt;br /&gt;
You may find the following article to be very helpful: [[MySQL Schema and State]]&lt;br /&gt;
&lt;br /&gt;
The files containing the data are:&lt;br /&gt;
&lt;br /&gt;
* students: https://docs.google.com/file/d/0ByHgvetJ0GJyMGFjMWI4MzAtMzljYy00Yjk3LTllMWItZjZkYmU1NzU3NWU0/edit&lt;br /&gt;
* courses: https://docs.google.com/file/d/0ByHgvetJ0GJyMGY1NGYzYmUtNGQwYi00MTY3LTkzMjgtMDYwOTM3NDNjZTg4/edit&lt;br /&gt;
* departments: https://docs.google.com/file/d/0ByHgvetJ0GJyZWY2OWE4ZWEtYzVmMC00YjBiLWEzZjgtYzdhMDczODAyNDli/edit&lt;br /&gt;
* grades: https://docs.google.com/file/d/0ByHgvetJ0GJyZmJjNzllNjAtMzdhZC00MzU5LTg3MDYtMTRmMjE5MDE2MzY2/edit&lt;br /&gt;
&lt;br /&gt;
=== Insert More Data ===&lt;br /&gt;
&lt;br /&gt;
Insert the following data into the tables that you have created and populated:&lt;br /&gt;
&lt;br /&gt;
# Insert an entry for CSE 330&lt;br /&gt;
#: ''If you don't know CSE's department code, how can you find out using the tables in the database?''&lt;br /&gt;
# Insert the grades given for the students named below.  You may choose to make the entries for whichever classes you like, with the one condition that all of the students must have a grade for CSE 330 (who wouldn't want to take that class: I hear the professor and TAs are amazing!)&lt;br /&gt;
#* '''Ben Harper'''&lt;br /&gt;
#** E-mail: '''bharper@ffym.com'''&lt;br /&gt;
#** Student ID: '''88'''&lt;br /&gt;
#** Grades:&lt;br /&gt;
#*** 5.5&lt;br /&gt;
#*** 0&lt;br /&gt;
#*** 20&lt;br /&gt;
#* '''Matt Freeman'''&lt;br /&gt;
#** E-mail: '''mfreeman@kickinbassist.net'''&lt;br /&gt;
#** Student ID: '''202'''&lt;br /&gt;
#** Grades:&lt;br /&gt;
#*** 100&lt;br /&gt;
#*** 90.5&lt;br /&gt;
#*** 94.8&lt;br /&gt;
#* '''Marc Roberge'''&lt;br /&gt;
#** E-mail: '''mroberge@ofarevolution.us'''&lt;br /&gt;
#** Student ID: '''115'''&lt;br /&gt;
#** Grades:&lt;br /&gt;
#*** 15&lt;br /&gt;
#*** 37&lt;br /&gt;
#*** 45.5&lt;br /&gt;
#: You may choose any 3 classes you'd like for them to be enrolled in, with at least one class, &amp;quot;CSE 330S&amp;quot;, in which they are all enrolled.&lt;br /&gt;
&lt;br /&gt;
=== Querying Your Database ===&lt;br /&gt;
&lt;br /&gt;
Now that you have a fully-functional, populated database, let's do some queries on it!&lt;br /&gt;
&lt;br /&gt;
Please take a screenshot of running the following '''select''' queries and show them to a TA (be sure to include your query command and the response:&lt;br /&gt;
&lt;br /&gt;
# Select the entire grades table.&lt;br /&gt;
# Select all fields describing the courses offered in the school of arts and sciences (school code L).&lt;br /&gt;
# The names, student IDs, and grades of the students who are in CSE330.&lt;br /&gt;
# The names and e-mails of any student with an average below 50 so that the dean can send them an email notification that they are now on academic probation.&lt;br /&gt;
#: ''You should be able to do this in only one query, without making any temporary tables.  You will need to use aggregation functions and the '''having''' keyword.''&lt;br /&gt;
# An individual report card for Jack Johnson, consisting of two tables (these can be done using separate queries):&lt;br /&gt;
## His student ID, e-mail address, and average grade.&lt;br /&gt;
##: ''Again, you should be able to do this in just one query, using the correct combination of aggregation functions and joins.''&lt;br /&gt;
## The classes he is in and his grades for those classes. To give you an idea, one row in the table should look like this:&lt;br /&gt;
##: &amp;lt;code&amp;gt;E	81	400	Independent Study	98.5&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Group Project ==&lt;br /&gt;
&lt;br /&gt;
You will work in pairs on this project.  You may work with the same partner from Module 2, or change to someone else.&lt;br /&gt;
&lt;br /&gt;
'''Important Reminder:''' frequently commit your work to your subversion repository as a backup!&lt;br /&gt;
&lt;br /&gt;
=== Simple News Web Site ===&lt;br /&gt;
&lt;br /&gt;
'''Examples:'''&lt;br /&gt;
* http://digg.com/&lt;br /&gt;
* http://slashdot.org/&lt;br /&gt;
&lt;br /&gt;
You should use '''PHP''' unless you get permission to use another web technology from the instructor.  You may also use phpMyAdmin to help set up databases.&lt;br /&gt;
&lt;br /&gt;
You may find this wiki article helpful: [[PHP and MySQL]]&lt;br /&gt;
&lt;br /&gt;
==== Requirements ====&lt;br /&gt;
&lt;br /&gt;
* Users can register for accounts and then log in to the website.&lt;br /&gt;
* Accounts should have both a username and a ''secure'' password.  '''NEVER store plaintext passwords in a database!'''&lt;br /&gt;
*: For more information on password security, refer to [[Web Application Security, Part 2#Password Security|the Web Application Security guide]].&lt;br /&gt;
* Registered users can submit stories: either a link with summary or news text.&lt;br /&gt;
*: You do not have to make a distinction between the two types of stories, although if you want to, you could do something with this for the creative portion of your project.&lt;br /&gt;
* Registered users can comment on any story.&lt;br /&gt;
* Administrator users can delete stories and comments.&lt;br /&gt;
* Unregistered users can only view stories and comments.&lt;br /&gt;
* Registered users can edit their stories and can delete their comments.&lt;br /&gt;
* All data must be kept in a MySQL database (user information, stories, comments, and categories).&lt;br /&gt;
* As before, please check with a TA to see if your creative portion is okay or not before you proceed.&lt;br /&gt;
&lt;br /&gt;
=== Web Security and Validation ===&lt;br /&gt;
&lt;br /&gt;
Your project needs to demonstrate that thought was put into web security and best practice.  For more information, see this week's Web Application Security guide: [[Web Application Security, Part 2]]&lt;br /&gt;
&lt;br /&gt;
In particular:&lt;br /&gt;
&lt;br /&gt;
* '''Your application needs to be secure from SQL injection attacks'''. If you are using prepared queries, you should already be safe on this front.&lt;br /&gt;
* '''All of your output needs to be sanitized using htmlentities()'''.&lt;br /&gt;
&lt;br /&gt;
You shouldn't forget the practices you learned last week:&lt;br /&gt;
&lt;br /&gt;
* '''You should pass tokens in forms''' to prevent CSRF attacks.&lt;br /&gt;
* '''Your page should validate''' with no errors through the W3C validator.&lt;br /&gt;
&lt;br /&gt;
== Grading ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;font-size:2em; line-height:2em;&amp;quot;&amp;gt;'''Due Date: Wednesday October 10th, by 1pm (both individual and group)'''&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
!Assignment&lt;br /&gt;
!Points&lt;br /&gt;
|-&lt;br /&gt;
|Tables Correct&lt;br /&gt;
|2&lt;br /&gt;
|-&lt;br /&gt;
|Data Queries Correct&lt;br /&gt;
|2&lt;br /&gt;
|-&lt;br /&gt;
!colspan=&amp;quot;2&amp;quot;|Group Portion:&lt;br /&gt;
|-&lt;br /&gt;
|User Authentication&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|User Registration&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Salted MD5 Encryption&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Main page displays all stories (or most recent stories)&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Page with individual story and comments&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Story Submission&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Comment System&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Administrator Deletion of Stories/Comments&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|User Edit of Story (1 pt) and Comment (1 pt)&lt;br /&gt;
|2&lt;br /&gt;
|-&lt;br /&gt;
|Protect Against SQL Injection Attack&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Sanitize Output&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|CSRF Safe and Validation&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Creative Portion&lt;br /&gt;
|2&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Total Points = 19&lt;br /&gt;
[[Category:Module 3]]&lt;br /&gt;
[[Category:Modules]]&lt;/div&gt;</summary>
		<author><name>Marc</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=Module_3&amp;diff=704</id>
		<title>Module 3</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=Module_3&amp;diff=704"/>
		<updated>2012-09-25T02:13:05Z</updated>

		<summary type="html">&lt;p&gt;Marc: /* Grading */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In Module 3, you will learn about MySQL, a web application database.&lt;br /&gt;
&lt;br /&gt;
This article contains your assignments for Module 3.&lt;br /&gt;
&lt;br /&gt;
== Individual Assignments ==&lt;br /&gt;
&lt;br /&gt;
You will create a simple grades database containing four tables.&lt;br /&gt;
&lt;br /&gt;
'''IMPORTANT:''' The individual assignment is to be done by writing queries by hand.  (You can use phpMyAdmin to run the queries, but '''do not let phpMyAdmin write your queries for you!''')  Writing your own queries gives you a greater understanding of the underlying mechanisms and databases in general.  Additionally, having SQL knowledge and experience is a very marketable trait.&lt;br /&gt;
&lt;br /&gt;
=== Install MySQL and phpMyAdmin ===&lt;br /&gt;
&lt;br /&gt;
Before you start, '''you need to install MySQL''' on your EC2 instance.  You may also install phpMyAdmin, a web frontend to MySQL, if you choose to do so.&lt;br /&gt;
&lt;br /&gt;
You may find the following article to be very helpful: [[Introduction to MySQL]]&lt;br /&gt;
&lt;br /&gt;
=== Set Up a Database ===&lt;br /&gt;
&lt;br /&gt;
You may find the following article to be very helpful: [[Introduction to MySQL]]&lt;br /&gt;
&lt;br /&gt;
# Create a database named '''wustl''' &lt;br /&gt;
# Create a user named '''wustl_inst''' and give them the password '''wustl_pass'''&lt;br /&gt;
&lt;br /&gt;
=== Create Tables ===&lt;br /&gt;
&lt;br /&gt;
You may find the following article to be very helpful: [[MySQL Schema and State]]&lt;br /&gt;
&lt;br /&gt;
When creating tables, keep the following items in mind:&lt;br /&gt;
&lt;br /&gt;
* You should create all tables such that they use the InnoDB storage engine, since we wish to make use of its support of foreign keys. In other database engines, foreign key constraints are not enforced.  (If you mess up, you can use ALTER TABLE to change the storage engine.)&lt;br /&gt;
* Where it is appropriate, you should take advantage of the ability to define fields NOT NULL so that you do not inadvertently insert incomplete data for a row.&lt;br /&gt;
&lt;br /&gt;
Create the following tables:&lt;br /&gt;
&lt;br /&gt;
# Create a table named '''students''' with the following fields:&lt;br /&gt;
#* '''id''' of an appropriately-sized unsigned integer type (we will never need to process more than a million students)&lt;br /&gt;
#* '''first_name''' of type '''VARCHAR(50)'''&lt;br /&gt;
#* '''last_name''' of type '''VARCHAR(50)'''&lt;br /&gt;
#* '''email_address''' of type '''VARCHAR(50)'''&lt;br /&gt;
#: The primary key should be on the '''id''' field.&lt;br /&gt;
# Create a table named '''departments''' with the following fields:&lt;br /&gt;
#* '''school_code''' of type '''ENUM''' (e.g. &amp;quot;L&amp;quot; for ArtSci and &amp;quot;E&amp;quot; for Engineering).  The options are as follows:&lt;br /&gt;
#*: 'L', 'B', 'A', 'F', 'E', 'T', 'I', 'W', 'S', 'U', 'M'&lt;br /&gt;
#* '''dept_id''' of an appropriately-sized unsigned integer type (in the foreseeable future there will never be more than 200 departments in a school)&lt;br /&gt;
#* '''abbreviation''' of type '''VARCHAR(9)''' (e.g. CSE, ChemE, etc)&lt;br /&gt;
#* '''dept_name''' of type '''VARCHAR(200)''' (e.g. Computer Science and Engineering)&lt;br /&gt;
#: The primary key should be on two fields: '''school_code''' and '''dept_id'''&lt;br /&gt;
#: '''Note:''' Why not just use the department ID? The ID numbers are sometimes reused across schools. For instance, department 33 in The School of Arts and Sciences is Psychology while department 33 in The School of Engineering and Applied Sciences is Energy, Environmental and Chemical Engineering. Thus we must also include the school code to differentiate them  such that the record for  E33 is distinct from that of L33.&lt;br /&gt;
# Create a table named '''courses''' with the following fields:&lt;br /&gt;
#* '''school_code''' of type '''ENUM'''&lt;br /&gt;
#*: This should have the same letters in the same order as the '''school_code''' '''ENUM''' field in the '''departments''' table.&lt;br /&gt;
#* '''dept_id''' of the same size of integer as in the '''departments''' table&lt;br /&gt;
#* '''course_code''' of type '''CHAR(5)''' (this will hold course codes; e.g., '330S', '131', '2960')&lt;br /&gt;
#* '''name''' of type '''VARCHAR(150)'''&lt;br /&gt;
#: The appropriate fields in this table should make a foreign key reference to the corresponding fields in '''department'''.&lt;br /&gt;
#: In addition, it is up to you to determine the field(s) for the primary key.&lt;br /&gt;
#: '''Note:''' If you are unsure which fields to make the foreign keys and feel the need to beg your friends or the TAs to give you the answer, bang your head on your desk whilst repeating &amp;quot;I WILL EXERCISE REASON AND COMMON SENSE AND I WILL CURTAIL MY DESIRE TO BLINDLY FOLLOW DIRECTIONS&amp;quot;&lt;br /&gt;
#: ''Disclaimer: don't actually bang your head on your desk, the resulting head trauma may in fact make it harder for you to determine which fields should have associated foreign keys.''&lt;br /&gt;
# Create a table named '''grades''' with the following fields:&lt;br /&gt;
#* '''pk_grade_ID''' of an appropriately-sized unsigned integer type (should be larger than the one you chose for the '''students''' table)&lt;br /&gt;
#*: You should declare this field to be '''auto_increment''' and make it the primary key.&lt;br /&gt;
#*: This is called a ''surrogate key'' as opposed to a ''natural key'' because it doesn't arise &amp;quot;naturally&amp;quot; from the data; that is to say that it is not derived from application data. The use of surrogate keys vs. natural keys is a polemic issue amongst database designers.  For a decently unbiased take on the issue, see this page: http://www.agiledata.org/essays/keys.html#Comparison&lt;br /&gt;
#*: '''Food for thought:''' Aside from simply exposing you to the concept, can you think of any reasons why a surrogate key might be preferable for this table?  Alternatively, what attributes, if any, could you use as a natural key, and what might be the drawbacks of doing so?&lt;br /&gt;
#* '''student_id''' of the same integer (unsigned) type that you chose in the '''students''' table&lt;br /&gt;
#* '''grade''' of type '''decimal'''&lt;br /&gt;
#* '''school_code''' of type '''ENUM'''&lt;br /&gt;
#*: Can you guess what entries to use for the enum?&lt;br /&gt;
#* '''dept_id''' of the same integer type that you've used for this field in other tables&lt;br /&gt;
#* '''course_code''' of the same type you chose for the course code in the '''courses''' table&lt;br /&gt;
#: The '''grades''' table should have foreign keys to both the '''students''' table and the '''courses''' table.&lt;br /&gt;
&lt;br /&gt;
=== Populate Tables ===&lt;br /&gt;
&lt;br /&gt;
Now, populate the tables by downloading the text files given below and loading them into the appropriate tables.&lt;br /&gt;
&lt;br /&gt;
'''Note:''' Do not insert all the values manually; instead, use the MySQL's ability to load in data from text files.&lt;br /&gt;
&lt;br /&gt;
You may find the following article to be very helpful: [[MySQL Schema and State]]&lt;br /&gt;
&lt;br /&gt;
The files containing the data are:&lt;br /&gt;
&lt;br /&gt;
* students: https://docs.google.com/file/d/0ByHgvetJ0GJyMGFjMWI4MzAtMzljYy00Yjk3LTllMWItZjZkYmU1NzU3NWU0/edit&lt;br /&gt;
* courses: https://docs.google.com/file/d/0ByHgvetJ0GJyMGY1NGYzYmUtNGQwYi00MTY3LTkzMjgtMDYwOTM3NDNjZTg4/edit&lt;br /&gt;
* departments: https://docs.google.com/file/d/0ByHgvetJ0GJyZWY2OWE4ZWEtYzVmMC00YjBiLWEzZjgtYzdhMDczODAyNDli/edit&lt;br /&gt;
* grades: https://docs.google.com/file/d/0ByHgvetJ0GJyZmJjNzllNjAtMzdhZC00MzU5LTg3MDYtMTRmMjE5MDE2MzY2/edit&lt;br /&gt;
&lt;br /&gt;
=== Insert More Data ===&lt;br /&gt;
&lt;br /&gt;
Insert the following data into the tables that you have created and populated:&lt;br /&gt;
&lt;br /&gt;
# Insert an entry for CSE 330&lt;br /&gt;
#: ''If you don't know CSE's department code, how can you find out using the tables in the database?''&lt;br /&gt;
# Insert the grades given for the students named below.  You may choose to make the entries for whichever classes you like, with the one condition that all of the students must have a grade for CSE 330 (who wouldn't want to take that class: I hear the professor and TAs are amazing!)&lt;br /&gt;
#* '''Ben Harper'''&lt;br /&gt;
#** E-mail: '''bharper@ffym.com'''&lt;br /&gt;
#** Student ID: '''88'''&lt;br /&gt;
#** Grades:&lt;br /&gt;
#*** 5.5&lt;br /&gt;
#*** 0&lt;br /&gt;
#*** 20&lt;br /&gt;
#* '''Matt Freeman'''&lt;br /&gt;
#** E-mail: '''mfreeman@kickinbassist.net'''&lt;br /&gt;
#** Student ID: '''202'''&lt;br /&gt;
#** Grades:&lt;br /&gt;
#*** 100&lt;br /&gt;
#*** 90.5&lt;br /&gt;
#*** 94.8&lt;br /&gt;
#* '''Marc Roberge'''&lt;br /&gt;
#** E-mail: '''mroberge@ofarevolution.us'''&lt;br /&gt;
#** Student ID: '''115'''&lt;br /&gt;
#** Grades:&lt;br /&gt;
#*** 15&lt;br /&gt;
#*** 37&lt;br /&gt;
#*** 45.5&lt;br /&gt;
#: You may choose any 3 classes you'd like for them to be enrolled in, with at least one class, &amp;quot;CSE 330S&amp;quot;, in which they are all enrolled.&lt;br /&gt;
&lt;br /&gt;
=== Querying Your Database ===&lt;br /&gt;
&lt;br /&gt;
Now that you have a fully-functional, populated database, let's do some queries on it!&lt;br /&gt;
&lt;br /&gt;
Please take a screenshot of running the following '''select''' queries and show them to a TA (be sure to include your query command and the response:&lt;br /&gt;
&lt;br /&gt;
# Select the entire grades table.&lt;br /&gt;
# Select all fields describing the courses offered in the school of arts and sciences (school code L).&lt;br /&gt;
# The names, student IDs, and grades of the students who are in CSE330.&lt;br /&gt;
# The names and e-mails of any student with an average below 50 so that the dean can send them an email notification that they are now on academic probation.&lt;br /&gt;
#: ''You should be able to do this in only one query, without making any temporary tables.  You will need to use aggregation functions and the '''having''' keyword.''&lt;br /&gt;
# An individual report card for Jack Johnson, consisting of two tables (these can be done using separate queries):&lt;br /&gt;
## His student ID, e-mail address, and average grade.&lt;br /&gt;
##: ''Again, you should be able to do this in just one query, using the correct combination of aggregation functions and joins.''&lt;br /&gt;
## The classes he is in and his grades for those classes. To give you an idea, one row in the table should look like this:&lt;br /&gt;
##: &amp;lt;code&amp;gt;E	81	400	Independent Study	98.5&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Group Project ==&lt;br /&gt;
&lt;br /&gt;
You will work in pairs on this project.  You may work with the same partner from Module 2, or change to someone else.&lt;br /&gt;
&lt;br /&gt;
'''Important Reminder:''' frequently commit your work to your subversion repository as a backup!&lt;br /&gt;
&lt;br /&gt;
=== Simple News Web Site ===&lt;br /&gt;
&lt;br /&gt;
'''Examples:'''&lt;br /&gt;
* http://digg.com/&lt;br /&gt;
* http://slashdot.org/&lt;br /&gt;
&lt;br /&gt;
You should use '''PHP''' unless you get permission to use another web technology from the instructor.  You may also use phpMyAdmin to help set up databases.&lt;br /&gt;
&lt;br /&gt;
You may find this wiki article helpful: [[PHP and MySQL]]&lt;br /&gt;
&lt;br /&gt;
==== Requirements ====&lt;br /&gt;
&lt;br /&gt;
* Users can register for accounts and then log in to the website.&lt;br /&gt;
* Accounts should have both a username and a ''secure'' password.  '''NEVER store plaintext passwords in a database!'''&lt;br /&gt;
*: For more information on password security, refer to [[Web Application Security, Part 2#Password Security|the Web Application Security guide]].&lt;br /&gt;
* Registered users can submit stories: either a link with summary or news text.&lt;br /&gt;
*: You do not have to make a distinction between the two types of stories, although if you want to, you could do something with this for the creative portion of your project.&lt;br /&gt;
* Registered users can comment on any story.&lt;br /&gt;
* Administrator users can delete stories and comments.&lt;br /&gt;
* Unregistered users can only view stories and comments.&lt;br /&gt;
* Registered users can edit their stories and can delete their comments.&lt;br /&gt;
* All data must be kept in a MySQL database (user information, stories, comments, and categories).&lt;br /&gt;
* As before, please check with a TA to see if your creative portion is okay or not before you proceed.&lt;br /&gt;
&lt;br /&gt;
=== Web Security and Validation ===&lt;br /&gt;
&lt;br /&gt;
Your project needs to demonstrate that thought was put into web security and best practice.  For more information, see this week's Web Application Security guide: [[Web Application Security, Part 2]]&lt;br /&gt;
&lt;br /&gt;
In particular:&lt;br /&gt;
&lt;br /&gt;
* '''Your application needs to be secure from SQL injection attacks'''. If you are using prepared queries, you should already be safe on this front.&lt;br /&gt;
* '''All of your output needs to be sanitized using htmlentities()'''.&lt;br /&gt;
&lt;br /&gt;
You shouldn't forget the practices you learned last week:&lt;br /&gt;
&lt;br /&gt;
* '''You should pass tokens in forms''' to prevent CSRF attacks.&lt;br /&gt;
* '''Your page should validate''' with no errors through the W3C validator.&lt;br /&gt;
&lt;br /&gt;
== Grading ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;font-size:2em; line-height:2em;&amp;quot;&amp;gt;'''Due Date: Wednesday October 10th, by 1pm (both individual and group)'''&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
!Assignment&lt;br /&gt;
!Points&lt;br /&gt;
|-&lt;br /&gt;
|Tables Correct&lt;br /&gt;
|2&lt;br /&gt;
|-&lt;br /&gt;
|Data Queries Correct&lt;br /&gt;
|2&lt;br /&gt;
|-&lt;br /&gt;
!colspan=&amp;quot;2&amp;quot;|Group Portion:&lt;br /&gt;
|-&lt;br /&gt;
|User Authentication&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|User Registration&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
Salted MD5 Encryption&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Main page displays all stories (or most recent stories)&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Page with individual story and comments&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Story Submission&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Comment System&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Administrator Deletion of Stories/Comments&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|User Edit of Story (1 pt) and Comment (1 pt)&lt;br /&gt;
|2&lt;br /&gt;
|-&lt;br /&gt;
|Protect Against SQL Injection Attack&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Sanitize Output&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|CSRF Safe and Validation&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Creative Portion&lt;br /&gt;
|2&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Total Points = 19&lt;br /&gt;
[[Category:Module 3]]&lt;br /&gt;
[[Category:Modules]]&lt;/div&gt;</summary>
		<author><name>Marc</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=Module_3&amp;diff=703</id>
		<title>Module 3</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=Module_3&amp;diff=703"/>
		<updated>2012-09-25T02:12:16Z</updated>

		<summary type="html">&lt;p&gt;Marc: /* Requirements */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In Module 3, you will learn about MySQL, a web application database.&lt;br /&gt;
&lt;br /&gt;
This article contains your assignments for Module 3.&lt;br /&gt;
&lt;br /&gt;
== Individual Assignments ==&lt;br /&gt;
&lt;br /&gt;
You will create a simple grades database containing four tables.&lt;br /&gt;
&lt;br /&gt;
'''IMPORTANT:''' The individual assignment is to be done by writing queries by hand.  (You can use phpMyAdmin to run the queries, but '''do not let phpMyAdmin write your queries for you!''')  Writing your own queries gives you a greater understanding of the underlying mechanisms and databases in general.  Additionally, having SQL knowledge and experience is a very marketable trait.&lt;br /&gt;
&lt;br /&gt;
=== Install MySQL and phpMyAdmin ===&lt;br /&gt;
&lt;br /&gt;
Before you start, '''you need to install MySQL''' on your EC2 instance.  You may also install phpMyAdmin, a web frontend to MySQL, if you choose to do so.&lt;br /&gt;
&lt;br /&gt;
You may find the following article to be very helpful: [[Introduction to MySQL]]&lt;br /&gt;
&lt;br /&gt;
=== Set Up a Database ===&lt;br /&gt;
&lt;br /&gt;
You may find the following article to be very helpful: [[Introduction to MySQL]]&lt;br /&gt;
&lt;br /&gt;
# Create a database named '''wustl''' &lt;br /&gt;
# Create a user named '''wustl_inst''' and give them the password '''wustl_pass'''&lt;br /&gt;
&lt;br /&gt;
=== Create Tables ===&lt;br /&gt;
&lt;br /&gt;
You may find the following article to be very helpful: [[MySQL Schema and State]]&lt;br /&gt;
&lt;br /&gt;
When creating tables, keep the following items in mind:&lt;br /&gt;
&lt;br /&gt;
* You should create all tables such that they use the InnoDB storage engine, since we wish to make use of its support of foreign keys. In other database engines, foreign key constraints are not enforced.  (If you mess up, you can use ALTER TABLE to change the storage engine.)&lt;br /&gt;
* Where it is appropriate, you should take advantage of the ability to define fields NOT NULL so that you do not inadvertently insert incomplete data for a row.&lt;br /&gt;
&lt;br /&gt;
Create the following tables:&lt;br /&gt;
&lt;br /&gt;
# Create a table named '''students''' with the following fields:&lt;br /&gt;
#* '''id''' of an appropriately-sized unsigned integer type (we will never need to process more than a million students)&lt;br /&gt;
#* '''first_name''' of type '''VARCHAR(50)'''&lt;br /&gt;
#* '''last_name''' of type '''VARCHAR(50)'''&lt;br /&gt;
#* '''email_address''' of type '''VARCHAR(50)'''&lt;br /&gt;
#: The primary key should be on the '''id''' field.&lt;br /&gt;
# Create a table named '''departments''' with the following fields:&lt;br /&gt;
#* '''school_code''' of type '''ENUM''' (e.g. &amp;quot;L&amp;quot; for ArtSci and &amp;quot;E&amp;quot; for Engineering).  The options are as follows:&lt;br /&gt;
#*: 'L', 'B', 'A', 'F', 'E', 'T', 'I', 'W', 'S', 'U', 'M'&lt;br /&gt;
#* '''dept_id''' of an appropriately-sized unsigned integer type (in the foreseeable future there will never be more than 200 departments in a school)&lt;br /&gt;
#* '''abbreviation''' of type '''VARCHAR(9)''' (e.g. CSE, ChemE, etc)&lt;br /&gt;
#* '''dept_name''' of type '''VARCHAR(200)''' (e.g. Computer Science and Engineering)&lt;br /&gt;
#: The primary key should be on two fields: '''school_code''' and '''dept_id'''&lt;br /&gt;
#: '''Note:''' Why not just use the department ID? The ID numbers are sometimes reused across schools. For instance, department 33 in The School of Arts and Sciences is Psychology while department 33 in The School of Engineering and Applied Sciences is Energy, Environmental and Chemical Engineering. Thus we must also include the school code to differentiate them  such that the record for  E33 is distinct from that of L33.&lt;br /&gt;
# Create a table named '''courses''' with the following fields:&lt;br /&gt;
#* '''school_code''' of type '''ENUM'''&lt;br /&gt;
#*: This should have the same letters in the same order as the '''school_code''' '''ENUM''' field in the '''departments''' table.&lt;br /&gt;
#* '''dept_id''' of the same size of integer as in the '''departments''' table&lt;br /&gt;
#* '''course_code''' of type '''CHAR(5)''' (this will hold course codes; e.g., '330S', '131', '2960')&lt;br /&gt;
#* '''name''' of type '''VARCHAR(150)'''&lt;br /&gt;
#: The appropriate fields in this table should make a foreign key reference to the corresponding fields in '''department'''.&lt;br /&gt;
#: In addition, it is up to you to determine the field(s) for the primary key.&lt;br /&gt;
#: '''Note:''' If you are unsure which fields to make the foreign keys and feel the need to beg your friends or the TAs to give you the answer, bang your head on your desk whilst repeating &amp;quot;I WILL EXERCISE REASON AND COMMON SENSE AND I WILL CURTAIL MY DESIRE TO BLINDLY FOLLOW DIRECTIONS&amp;quot;&lt;br /&gt;
#: ''Disclaimer: don't actually bang your head on your desk, the resulting head trauma may in fact make it harder for you to determine which fields should have associated foreign keys.''&lt;br /&gt;
# Create a table named '''grades''' with the following fields:&lt;br /&gt;
#* '''pk_grade_ID''' of an appropriately-sized unsigned integer type (should be larger than the one you chose for the '''students''' table)&lt;br /&gt;
#*: You should declare this field to be '''auto_increment''' and make it the primary key.&lt;br /&gt;
#*: This is called a ''surrogate key'' as opposed to a ''natural key'' because it doesn't arise &amp;quot;naturally&amp;quot; from the data; that is to say that it is not derived from application data. The use of surrogate keys vs. natural keys is a polemic issue amongst database designers.  For a decently unbiased take on the issue, see this page: http://www.agiledata.org/essays/keys.html#Comparison&lt;br /&gt;
#*: '''Food for thought:''' Aside from simply exposing you to the concept, can you think of any reasons why a surrogate key might be preferable for this table?  Alternatively, what attributes, if any, could you use as a natural key, and what might be the drawbacks of doing so?&lt;br /&gt;
#* '''student_id''' of the same integer (unsigned) type that you chose in the '''students''' table&lt;br /&gt;
#* '''grade''' of type '''decimal'''&lt;br /&gt;
#* '''school_code''' of type '''ENUM'''&lt;br /&gt;
#*: Can you guess what entries to use for the enum?&lt;br /&gt;
#* '''dept_id''' of the same integer type that you've used for this field in other tables&lt;br /&gt;
#* '''course_code''' of the same type you chose for the course code in the '''courses''' table&lt;br /&gt;
#: The '''grades''' table should have foreign keys to both the '''students''' table and the '''courses''' table.&lt;br /&gt;
&lt;br /&gt;
=== Populate Tables ===&lt;br /&gt;
&lt;br /&gt;
Now, populate the tables by downloading the text files given below and loading them into the appropriate tables.&lt;br /&gt;
&lt;br /&gt;
'''Note:''' Do not insert all the values manually; instead, use the MySQL's ability to load in data from text files.&lt;br /&gt;
&lt;br /&gt;
You may find the following article to be very helpful: [[MySQL Schema and State]]&lt;br /&gt;
&lt;br /&gt;
The files containing the data are:&lt;br /&gt;
&lt;br /&gt;
* students: https://docs.google.com/file/d/0ByHgvetJ0GJyMGFjMWI4MzAtMzljYy00Yjk3LTllMWItZjZkYmU1NzU3NWU0/edit&lt;br /&gt;
* courses: https://docs.google.com/file/d/0ByHgvetJ0GJyMGY1NGYzYmUtNGQwYi00MTY3LTkzMjgtMDYwOTM3NDNjZTg4/edit&lt;br /&gt;
* departments: https://docs.google.com/file/d/0ByHgvetJ0GJyZWY2OWE4ZWEtYzVmMC00YjBiLWEzZjgtYzdhMDczODAyNDli/edit&lt;br /&gt;
* grades: https://docs.google.com/file/d/0ByHgvetJ0GJyZmJjNzllNjAtMzdhZC00MzU5LTg3MDYtMTRmMjE5MDE2MzY2/edit&lt;br /&gt;
&lt;br /&gt;
=== Insert More Data ===&lt;br /&gt;
&lt;br /&gt;
Insert the following data into the tables that you have created and populated:&lt;br /&gt;
&lt;br /&gt;
# Insert an entry for CSE 330&lt;br /&gt;
#: ''If you don't know CSE's department code, how can you find out using the tables in the database?''&lt;br /&gt;
# Insert the grades given for the students named below.  You may choose to make the entries for whichever classes you like, with the one condition that all of the students must have a grade for CSE 330 (who wouldn't want to take that class: I hear the professor and TAs are amazing!)&lt;br /&gt;
#* '''Ben Harper'''&lt;br /&gt;
#** E-mail: '''bharper@ffym.com'''&lt;br /&gt;
#** Student ID: '''88'''&lt;br /&gt;
#** Grades:&lt;br /&gt;
#*** 5.5&lt;br /&gt;
#*** 0&lt;br /&gt;
#*** 20&lt;br /&gt;
#* '''Matt Freeman'''&lt;br /&gt;
#** E-mail: '''mfreeman@kickinbassist.net'''&lt;br /&gt;
#** Student ID: '''202'''&lt;br /&gt;
#** Grades:&lt;br /&gt;
#*** 100&lt;br /&gt;
#*** 90.5&lt;br /&gt;
#*** 94.8&lt;br /&gt;
#* '''Marc Roberge'''&lt;br /&gt;
#** E-mail: '''mroberge@ofarevolution.us'''&lt;br /&gt;
#** Student ID: '''115'''&lt;br /&gt;
#** Grades:&lt;br /&gt;
#*** 15&lt;br /&gt;
#*** 37&lt;br /&gt;
#*** 45.5&lt;br /&gt;
#: You may choose any 3 classes you'd like for them to be enrolled in, with at least one class, &amp;quot;CSE 330S&amp;quot;, in which they are all enrolled.&lt;br /&gt;
&lt;br /&gt;
=== Querying Your Database ===&lt;br /&gt;
&lt;br /&gt;
Now that you have a fully-functional, populated database, let's do some queries on it!&lt;br /&gt;
&lt;br /&gt;
Please take a screenshot of running the following '''select''' queries and show them to a TA (be sure to include your query command and the response:&lt;br /&gt;
&lt;br /&gt;
# Select the entire grades table.&lt;br /&gt;
# Select all fields describing the courses offered in the school of arts and sciences (school code L).&lt;br /&gt;
# The names, student IDs, and grades of the students who are in CSE330.&lt;br /&gt;
# The names and e-mails of any student with an average below 50 so that the dean can send them an email notification that they are now on academic probation.&lt;br /&gt;
#: ''You should be able to do this in only one query, without making any temporary tables.  You will need to use aggregation functions and the '''having''' keyword.''&lt;br /&gt;
# An individual report card for Jack Johnson, consisting of two tables (these can be done using separate queries):&lt;br /&gt;
## His student ID, e-mail address, and average grade.&lt;br /&gt;
##: ''Again, you should be able to do this in just one query, using the correct combination of aggregation functions and joins.''&lt;br /&gt;
## The classes he is in and his grades for those classes. To give you an idea, one row in the table should look like this:&lt;br /&gt;
##: &amp;lt;code&amp;gt;E	81	400	Independent Study	98.5&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Group Project ==&lt;br /&gt;
&lt;br /&gt;
You will work in pairs on this project.  You may work with the same partner from Module 2, or change to someone else.&lt;br /&gt;
&lt;br /&gt;
'''Important Reminder:''' frequently commit your work to your subversion repository as a backup!&lt;br /&gt;
&lt;br /&gt;
=== Simple News Web Site ===&lt;br /&gt;
&lt;br /&gt;
'''Examples:'''&lt;br /&gt;
* http://digg.com/&lt;br /&gt;
* http://slashdot.org/&lt;br /&gt;
&lt;br /&gt;
You should use '''PHP''' unless you get permission to use another web technology from the instructor.  You may also use phpMyAdmin to help set up databases.&lt;br /&gt;
&lt;br /&gt;
You may find this wiki article helpful: [[PHP and MySQL]]&lt;br /&gt;
&lt;br /&gt;
==== Requirements ====&lt;br /&gt;
&lt;br /&gt;
* Users can register for accounts and then log in to the website.&lt;br /&gt;
* Accounts should have both a username and a ''secure'' password.  '''NEVER store plaintext passwords in a database!'''&lt;br /&gt;
*: For more information on password security, refer to [[Web Application Security, Part 2#Password Security|the Web Application Security guide]].&lt;br /&gt;
* Registered users can submit stories: either a link with summary or news text.&lt;br /&gt;
*: You do not have to make a distinction between the two types of stories, although if you want to, you could do something with this for the creative portion of your project.&lt;br /&gt;
* Registered users can comment on any story.&lt;br /&gt;
* Administrator users can delete stories and comments.&lt;br /&gt;
* Unregistered users can only view stories and comments.&lt;br /&gt;
* Registered users can edit their stories and can delete their comments.&lt;br /&gt;
* All data must be kept in a MySQL database (user information, stories, comments, and categories).&lt;br /&gt;
* As before, please check with a TA to see if your creative portion is okay or not before you proceed.&lt;br /&gt;
&lt;br /&gt;
=== Web Security and Validation ===&lt;br /&gt;
&lt;br /&gt;
Your project needs to demonstrate that thought was put into web security and best practice.  For more information, see this week's Web Application Security guide: [[Web Application Security, Part 2]]&lt;br /&gt;
&lt;br /&gt;
In particular:&lt;br /&gt;
&lt;br /&gt;
* '''Your application needs to be secure from SQL injection attacks'''. If you are using prepared queries, you should already be safe on this front.&lt;br /&gt;
* '''All of your output needs to be sanitized using htmlentities()'''.&lt;br /&gt;
&lt;br /&gt;
You shouldn't forget the practices you learned last week:&lt;br /&gt;
&lt;br /&gt;
* '''You should pass tokens in forms''' to prevent CSRF attacks.&lt;br /&gt;
* '''Your page should validate''' with no errors through the W3C validator.&lt;br /&gt;
&lt;br /&gt;
== Grading ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;font-size:2em; line-height:2em;&amp;quot;&amp;gt;'''Due Date: Wednesday October 10th, by 1pm (both individual and group)'''&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
!Assignment&lt;br /&gt;
!Points&lt;br /&gt;
|-&lt;br /&gt;
|Tables Correct&lt;br /&gt;
|2&lt;br /&gt;
|-&lt;br /&gt;
|Data Queries Correct&lt;br /&gt;
|2&lt;br /&gt;
|-&lt;br /&gt;
!colspan=&amp;quot;2&amp;quot;|Group Portion:&lt;br /&gt;
|-&lt;br /&gt;
|User Authentication&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|User Registration&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Some type of password encryption&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Main page displays all stories (or most recent stories)&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Page with individual story and comments&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Story Submission&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Comment System&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Administrator Deletion of Stories/Comments&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|User Edit of Story (1 pt) and Comment (1 pt)&lt;br /&gt;
|2&lt;br /&gt;
|-&lt;br /&gt;
|Protect Against SQL Injection Attack&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Sanitize Output&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|CSRF Safe and Validation&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Creative Portion&lt;br /&gt;
|2&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Total Points = 19&lt;br /&gt;
[[Category:Module 3]]&lt;br /&gt;
[[Category:Modules]]&lt;/div&gt;</summary>
		<author><name>Marc</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=Module_3&amp;diff=702</id>
		<title>Module 3</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=Module_3&amp;diff=702"/>
		<updated>2012-09-25T01:46:43Z</updated>

		<summary type="html">&lt;p&gt;Marc: /* Grading */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In Module 3, you will learn about MySQL, a web application database.&lt;br /&gt;
&lt;br /&gt;
This article contains your assignments for Module 3.&lt;br /&gt;
&lt;br /&gt;
== Individual Assignments ==&lt;br /&gt;
&lt;br /&gt;
You will create a simple grades database containing four tables.&lt;br /&gt;
&lt;br /&gt;
'''IMPORTANT:''' The individual assignment is to be done by writing queries by hand.  (You can use phpMyAdmin to run the queries, but '''do not let phpMyAdmin write your queries for you!''')  Writing your own queries gives you a greater understanding of the underlying mechanisms and databases in general.  Additionally, having SQL knowledge and experience is a very marketable trait.&lt;br /&gt;
&lt;br /&gt;
=== Install MySQL and phpMyAdmin ===&lt;br /&gt;
&lt;br /&gt;
Before you start, '''you need to install MySQL''' on your EC2 instance.  You may also install phpMyAdmin, a web frontend to MySQL, if you choose to do so.&lt;br /&gt;
&lt;br /&gt;
You may find the following article to be very helpful: [[Introduction to MySQL]]&lt;br /&gt;
&lt;br /&gt;
=== Set Up a Database ===&lt;br /&gt;
&lt;br /&gt;
You may find the following article to be very helpful: [[Introduction to MySQL]]&lt;br /&gt;
&lt;br /&gt;
# Create a database named '''wustl''' &lt;br /&gt;
# Create a user named '''wustl_inst''' and give them the password '''wustl_pass'''&lt;br /&gt;
&lt;br /&gt;
=== Create Tables ===&lt;br /&gt;
&lt;br /&gt;
You may find the following article to be very helpful: [[MySQL Schema and State]]&lt;br /&gt;
&lt;br /&gt;
When creating tables, keep the following items in mind:&lt;br /&gt;
&lt;br /&gt;
* You should create all tables such that they use the InnoDB storage engine, since we wish to make use of its support of foreign keys. In other database engines, foreign key constraints are not enforced.  (If you mess up, you can use ALTER TABLE to change the storage engine.)&lt;br /&gt;
* Where it is appropriate, you should take advantage of the ability to define fields NOT NULL so that you do not inadvertently insert incomplete data for a row.&lt;br /&gt;
&lt;br /&gt;
Create the following tables:&lt;br /&gt;
&lt;br /&gt;
# Create a table named '''students''' with the following fields:&lt;br /&gt;
#* '''id''' of an appropriately-sized unsigned integer type (we will never need to process more than a million students)&lt;br /&gt;
#* '''first_name''' of type '''VARCHAR(50)'''&lt;br /&gt;
#* '''last_name''' of type '''VARCHAR(50)'''&lt;br /&gt;
#* '''email_address''' of type '''VARCHAR(50)'''&lt;br /&gt;
#: The primary key should be on the '''id''' field.&lt;br /&gt;
# Create a table named '''departments''' with the following fields:&lt;br /&gt;
#* '''school_code''' of type '''ENUM''' (e.g. &amp;quot;L&amp;quot; for ArtSci and &amp;quot;E&amp;quot; for Engineering).  The options are as follows:&lt;br /&gt;
#*: 'L', 'B', 'A', 'F', 'E', 'T', 'I', 'W', 'S', 'U', 'M'&lt;br /&gt;
#* '''dept_id''' of an appropriately-sized unsigned integer type (in the foreseeable future there will never be more than 200 departments in a school)&lt;br /&gt;
#* '''abbreviation''' of type '''VARCHAR(9)''' (e.g. CSE, ChemE, etc)&lt;br /&gt;
#* '''dept_name''' of type '''VARCHAR(200)''' (e.g. Computer Science and Engineering)&lt;br /&gt;
#: The primary key should be on two fields: '''school_code''' and '''dept_id'''&lt;br /&gt;
#: '''Note:''' Why not just use the department ID? The ID numbers are sometimes reused across schools. For instance, department 33 in The School of Arts and Sciences is Psychology while department 33 in The School of Engineering and Applied Sciences is Energy, Environmental and Chemical Engineering. Thus we must also include the school code to differentiate them  such that the record for  E33 is distinct from that of L33.&lt;br /&gt;
# Create a table named '''courses''' with the following fields:&lt;br /&gt;
#* '''school_code''' of type '''ENUM'''&lt;br /&gt;
#*: This should have the same letters in the same order as the '''school_code''' '''ENUM''' field in the '''departments''' table.&lt;br /&gt;
#* '''dept_id''' of the same size of integer as in the '''departments''' table&lt;br /&gt;
#* '''course_code''' of type '''CHAR(5)''' (this will hold course codes; e.g., '330S', '131', '2960')&lt;br /&gt;
#* '''name''' of type '''VARCHAR(150)'''&lt;br /&gt;
#: The appropriate fields in this table should make a foreign key reference to the corresponding fields in '''department'''.&lt;br /&gt;
#: In addition, it is up to you to determine the field(s) for the primary key.&lt;br /&gt;
#: '''Note:''' If you are unsure which fields to make the foreign keys and feel the need to beg your friends or the TAs to give you the answer, bang your head on your desk whilst repeating &amp;quot;I WILL EXERCISE REASON AND COMMON SENSE AND I WILL CURTAIL MY DESIRE TO BLINDLY FOLLOW DIRECTIONS&amp;quot;&lt;br /&gt;
#: ''Disclaimer: don't actually bang your head on your desk, the resulting head trauma may in fact make it harder for you to determine which fields should have associated foreign keys.''&lt;br /&gt;
# Create a table named '''grades''' with the following fields:&lt;br /&gt;
#* '''pk_grade_ID''' of an appropriately-sized unsigned integer type (should be larger than the one you chose for the '''students''' table)&lt;br /&gt;
#*: You should declare this field to be '''auto_increment''' and make it the primary key.&lt;br /&gt;
#*: This is called a ''surrogate key'' as opposed to a ''natural key'' because it doesn't arise &amp;quot;naturally&amp;quot; from the data; that is to say that it is not derived from application data. The use of surrogate keys vs. natural keys is a polemic issue amongst database designers.  For a decently unbiased take on the issue, see this page: http://www.agiledata.org/essays/keys.html#Comparison&lt;br /&gt;
#*: '''Food for thought:''' Aside from simply exposing you to the concept, can you think of any reasons why a surrogate key might be preferable for this table?  Alternatively, what attributes, if any, could you use as a natural key, and what might be the drawbacks of doing so?&lt;br /&gt;
#* '''student_id''' of the same integer (unsigned) type that you chose in the '''students''' table&lt;br /&gt;
#* '''grade''' of type '''decimal'''&lt;br /&gt;
#* '''school_code''' of type '''ENUM'''&lt;br /&gt;
#*: Can you guess what entries to use for the enum?&lt;br /&gt;
#* '''dept_id''' of the same integer type that you've used for this field in other tables&lt;br /&gt;
#* '''course_code''' of the same type you chose for the course code in the '''courses''' table&lt;br /&gt;
#: The '''grades''' table should have foreign keys to both the '''students''' table and the '''courses''' table.&lt;br /&gt;
&lt;br /&gt;
=== Populate Tables ===&lt;br /&gt;
&lt;br /&gt;
Now, populate the tables by downloading the text files given below and loading them into the appropriate tables.&lt;br /&gt;
&lt;br /&gt;
'''Note:''' Do not insert all the values manually; instead, use the MySQL's ability to load in data from text files.&lt;br /&gt;
&lt;br /&gt;
You may find the following article to be very helpful: [[MySQL Schema and State]]&lt;br /&gt;
&lt;br /&gt;
The files containing the data are:&lt;br /&gt;
&lt;br /&gt;
* students: https://docs.google.com/file/d/0ByHgvetJ0GJyMGFjMWI4MzAtMzljYy00Yjk3LTllMWItZjZkYmU1NzU3NWU0/edit&lt;br /&gt;
* courses: https://docs.google.com/file/d/0ByHgvetJ0GJyMGY1NGYzYmUtNGQwYi00MTY3LTkzMjgtMDYwOTM3NDNjZTg4/edit&lt;br /&gt;
* departments: https://docs.google.com/file/d/0ByHgvetJ0GJyZWY2OWE4ZWEtYzVmMC00YjBiLWEzZjgtYzdhMDczODAyNDli/edit&lt;br /&gt;
* grades: https://docs.google.com/file/d/0ByHgvetJ0GJyZmJjNzllNjAtMzdhZC00MzU5LTg3MDYtMTRmMjE5MDE2MzY2/edit&lt;br /&gt;
&lt;br /&gt;
=== Insert More Data ===&lt;br /&gt;
&lt;br /&gt;
Insert the following data into the tables that you have created and populated:&lt;br /&gt;
&lt;br /&gt;
# Insert an entry for CSE 330&lt;br /&gt;
#: ''If you don't know CSE's department code, how can you find out using the tables in the database?''&lt;br /&gt;
# Insert the grades given for the students named below.  You may choose to make the entries for whichever classes you like, with the one condition that all of the students must have a grade for CSE 330 (who wouldn't want to take that class: I hear the professor and TAs are amazing!)&lt;br /&gt;
#* '''Ben Harper'''&lt;br /&gt;
#** E-mail: '''bharper@ffym.com'''&lt;br /&gt;
#** Student ID: '''88'''&lt;br /&gt;
#** Grades:&lt;br /&gt;
#*** 5.5&lt;br /&gt;
#*** 0&lt;br /&gt;
#*** 20&lt;br /&gt;
#* '''Matt Freeman'''&lt;br /&gt;
#** E-mail: '''mfreeman@kickinbassist.net'''&lt;br /&gt;
#** Student ID: '''202'''&lt;br /&gt;
#** Grades:&lt;br /&gt;
#*** 100&lt;br /&gt;
#*** 90.5&lt;br /&gt;
#*** 94.8&lt;br /&gt;
#* '''Marc Roberge'''&lt;br /&gt;
#** E-mail: '''mroberge@ofarevolution.us'''&lt;br /&gt;
#** Student ID: '''115'''&lt;br /&gt;
#** Grades:&lt;br /&gt;
#*** 15&lt;br /&gt;
#*** 37&lt;br /&gt;
#*** 45.5&lt;br /&gt;
#: You may choose any 3 classes you'd like for them to be enrolled in, with at least one class, &amp;quot;CSE 330S&amp;quot;, in which they are all enrolled.&lt;br /&gt;
&lt;br /&gt;
=== Querying Your Database ===&lt;br /&gt;
&lt;br /&gt;
Now that you have a fully-functional, populated database, let's do some queries on it!&lt;br /&gt;
&lt;br /&gt;
Please take a screenshot of running the following '''select''' queries and show them to a TA (be sure to include your query command and the response:&lt;br /&gt;
&lt;br /&gt;
# Select the entire grades table.&lt;br /&gt;
# Select all fields describing the courses offered in the school of arts and sciences (school code L).&lt;br /&gt;
# The names, student IDs, and grades of the students who are in CSE330.&lt;br /&gt;
# The names and e-mails of any student with an average below 50 so that the dean can send them an email notification that they are now on academic probation.&lt;br /&gt;
#: ''You should be able to do this in only one query, without making any temporary tables.  You will need to use aggregation functions and the '''having''' keyword.''&lt;br /&gt;
# An individual report card for Jack Johnson, consisting of two tables (these can be done using separate queries):&lt;br /&gt;
## His student ID, e-mail address, and average grade.&lt;br /&gt;
##: ''Again, you should be able to do this in just one query, using the correct combination of aggregation functions and joins.''&lt;br /&gt;
## The classes he is in and his grades for those classes. To give you an idea, one row in the table should look like this:&lt;br /&gt;
##: &amp;lt;code&amp;gt;E	81	400	Independent Study	98.5&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Group Project ==&lt;br /&gt;
&lt;br /&gt;
You will work in pairs on this project.  You may work with the same partner from Module 2, or change to someone else.&lt;br /&gt;
&lt;br /&gt;
'''Important Reminder:''' frequently commit your work to your subversion repository as a backup!&lt;br /&gt;
&lt;br /&gt;
=== Simple News Web Site ===&lt;br /&gt;
&lt;br /&gt;
'''Examples:'''&lt;br /&gt;
* http://digg.com/&lt;br /&gt;
* http://slashdot.org/&lt;br /&gt;
&lt;br /&gt;
You should use '''PHP''' unless you get permission to use another web technology from the instructor.  You may also use phpMyAdmin to help set up databases.&lt;br /&gt;
&lt;br /&gt;
You may find this wiki article helpful: [[PHP and MySQL]]&lt;br /&gt;
&lt;br /&gt;
==== Requirements ====&lt;br /&gt;
&lt;br /&gt;
* Users can register for accounts and then log in to the website.&lt;br /&gt;
* Accounts should have both a username and a ''secure'' password.  '''NEVER store plaintext passwords in a database!'''&lt;br /&gt;
*: For more information on password security, refer to [[Web Application Security, Part 2#Password Security|the Web Application Security guide]].&lt;br /&gt;
*: You may use OpenID as a password system.  While not best practice, md5 is sufficient for points on the lab.  You may also design your own encryption system.&lt;br /&gt;
* Registered users can submit stories: either a link with summary or news text.&lt;br /&gt;
*: You do not have to make a distinction between the two types of stories, although if you want to, you could do something with this for the creative portion of your project.&lt;br /&gt;
* Registered users can comment on any story.&lt;br /&gt;
* Administrator users can delete stories and comments.&lt;br /&gt;
* Unregistered users can only view stories and comments.&lt;br /&gt;
* Registered users can edit their stories and can delete their comments.&lt;br /&gt;
* All data must be kept in a MySQL database (user information, stories, comments, and categories).&lt;br /&gt;
* As before, please check with a TA to see if your creative portion is okay or not before you proceed.&lt;br /&gt;
&lt;br /&gt;
=== Web Security and Validation ===&lt;br /&gt;
&lt;br /&gt;
Your project needs to demonstrate that thought was put into web security and best practice.  For more information, see this week's Web Application Security guide: [[Web Application Security, Part 2]]&lt;br /&gt;
&lt;br /&gt;
In particular:&lt;br /&gt;
&lt;br /&gt;
* '''Your application needs to be secure from SQL injection attacks'''. If you are using prepared queries, you should already be safe on this front.&lt;br /&gt;
* '''All of your output needs to be sanitized using htmlentities()'''.&lt;br /&gt;
&lt;br /&gt;
You shouldn't forget the practices you learned last week:&lt;br /&gt;
&lt;br /&gt;
* '''You should pass tokens in forms''' to prevent CSRF attacks.&lt;br /&gt;
* '''Your page should validate''' with no errors through the W3C validator.&lt;br /&gt;
&lt;br /&gt;
== Grading ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;font-size:2em; line-height:2em;&amp;quot;&amp;gt;'''Due Date: Wednesday October 10th, by 1pm (both individual and group)'''&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
!Assignment&lt;br /&gt;
!Points&lt;br /&gt;
|-&lt;br /&gt;
|Tables Correct&lt;br /&gt;
|2&lt;br /&gt;
|-&lt;br /&gt;
|Data Queries Correct&lt;br /&gt;
|2&lt;br /&gt;
|-&lt;br /&gt;
!colspan=&amp;quot;2&amp;quot;|Group Portion:&lt;br /&gt;
|-&lt;br /&gt;
|User Authentication&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|User Registration&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Some type of password encryption&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Main page displays all stories (or most recent stories)&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Page with individual story and comments&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Story Submission&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Comment System&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Administrator Deletion of Stories/Comments&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|User Edit of Story (1 pt) and Comment (1 pt)&lt;br /&gt;
|2&lt;br /&gt;
|-&lt;br /&gt;
|Protect Against SQL Injection Attack&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Sanitize Output&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|CSRF Safe and Validation&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Creative Portion&lt;br /&gt;
|2&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Total Points = 19&lt;br /&gt;
[[Category:Module 3]]&lt;br /&gt;
[[Category:Modules]]&lt;/div&gt;</summary>
		<author><name>Marc</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=Module_3&amp;diff=701</id>
		<title>Module 3</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=Module_3&amp;diff=701"/>
		<updated>2012-09-25T01:46:32Z</updated>

		<summary type="html">&lt;p&gt;Marc: /* Grading */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In Module 3, you will learn about MySQL, a web application database.&lt;br /&gt;
&lt;br /&gt;
This article contains your assignments for Module 3.&lt;br /&gt;
&lt;br /&gt;
== Individual Assignments ==&lt;br /&gt;
&lt;br /&gt;
You will create a simple grades database containing four tables.&lt;br /&gt;
&lt;br /&gt;
'''IMPORTANT:''' The individual assignment is to be done by writing queries by hand.  (You can use phpMyAdmin to run the queries, but '''do not let phpMyAdmin write your queries for you!''')  Writing your own queries gives you a greater understanding of the underlying mechanisms and databases in general.  Additionally, having SQL knowledge and experience is a very marketable trait.&lt;br /&gt;
&lt;br /&gt;
=== Install MySQL and phpMyAdmin ===&lt;br /&gt;
&lt;br /&gt;
Before you start, '''you need to install MySQL''' on your EC2 instance.  You may also install phpMyAdmin, a web frontend to MySQL, if you choose to do so.&lt;br /&gt;
&lt;br /&gt;
You may find the following article to be very helpful: [[Introduction to MySQL]]&lt;br /&gt;
&lt;br /&gt;
=== Set Up a Database ===&lt;br /&gt;
&lt;br /&gt;
You may find the following article to be very helpful: [[Introduction to MySQL]]&lt;br /&gt;
&lt;br /&gt;
# Create a database named '''wustl''' &lt;br /&gt;
# Create a user named '''wustl_inst''' and give them the password '''wustl_pass'''&lt;br /&gt;
&lt;br /&gt;
=== Create Tables ===&lt;br /&gt;
&lt;br /&gt;
You may find the following article to be very helpful: [[MySQL Schema and State]]&lt;br /&gt;
&lt;br /&gt;
When creating tables, keep the following items in mind:&lt;br /&gt;
&lt;br /&gt;
* You should create all tables such that they use the InnoDB storage engine, since we wish to make use of its support of foreign keys. In other database engines, foreign key constraints are not enforced.  (If you mess up, you can use ALTER TABLE to change the storage engine.)&lt;br /&gt;
* Where it is appropriate, you should take advantage of the ability to define fields NOT NULL so that you do not inadvertently insert incomplete data for a row.&lt;br /&gt;
&lt;br /&gt;
Create the following tables:&lt;br /&gt;
&lt;br /&gt;
# Create a table named '''students''' with the following fields:&lt;br /&gt;
#* '''id''' of an appropriately-sized unsigned integer type (we will never need to process more than a million students)&lt;br /&gt;
#* '''first_name''' of type '''VARCHAR(50)'''&lt;br /&gt;
#* '''last_name''' of type '''VARCHAR(50)'''&lt;br /&gt;
#* '''email_address''' of type '''VARCHAR(50)'''&lt;br /&gt;
#: The primary key should be on the '''id''' field.&lt;br /&gt;
# Create a table named '''departments''' with the following fields:&lt;br /&gt;
#* '''school_code''' of type '''ENUM''' (e.g. &amp;quot;L&amp;quot; for ArtSci and &amp;quot;E&amp;quot; for Engineering).  The options are as follows:&lt;br /&gt;
#*: 'L', 'B', 'A', 'F', 'E', 'T', 'I', 'W', 'S', 'U', 'M'&lt;br /&gt;
#* '''dept_id''' of an appropriately-sized unsigned integer type (in the foreseeable future there will never be more than 200 departments in a school)&lt;br /&gt;
#* '''abbreviation''' of type '''VARCHAR(9)''' (e.g. CSE, ChemE, etc)&lt;br /&gt;
#* '''dept_name''' of type '''VARCHAR(200)''' (e.g. Computer Science and Engineering)&lt;br /&gt;
#: The primary key should be on two fields: '''school_code''' and '''dept_id'''&lt;br /&gt;
#: '''Note:''' Why not just use the department ID? The ID numbers are sometimes reused across schools. For instance, department 33 in The School of Arts and Sciences is Psychology while department 33 in The School of Engineering and Applied Sciences is Energy, Environmental and Chemical Engineering. Thus we must also include the school code to differentiate them  such that the record for  E33 is distinct from that of L33.&lt;br /&gt;
# Create a table named '''courses''' with the following fields:&lt;br /&gt;
#* '''school_code''' of type '''ENUM'''&lt;br /&gt;
#*: This should have the same letters in the same order as the '''school_code''' '''ENUM''' field in the '''departments''' table.&lt;br /&gt;
#* '''dept_id''' of the same size of integer as in the '''departments''' table&lt;br /&gt;
#* '''course_code''' of type '''CHAR(5)''' (this will hold course codes; e.g., '330S', '131', '2960')&lt;br /&gt;
#* '''name''' of type '''VARCHAR(150)'''&lt;br /&gt;
#: The appropriate fields in this table should make a foreign key reference to the corresponding fields in '''department'''.&lt;br /&gt;
#: In addition, it is up to you to determine the field(s) for the primary key.&lt;br /&gt;
#: '''Note:''' If you are unsure which fields to make the foreign keys and feel the need to beg your friends or the TAs to give you the answer, bang your head on your desk whilst repeating &amp;quot;I WILL EXERCISE REASON AND COMMON SENSE AND I WILL CURTAIL MY DESIRE TO BLINDLY FOLLOW DIRECTIONS&amp;quot;&lt;br /&gt;
#: ''Disclaimer: don't actually bang your head on your desk, the resulting head trauma may in fact make it harder for you to determine which fields should have associated foreign keys.''&lt;br /&gt;
# Create a table named '''grades''' with the following fields:&lt;br /&gt;
#* '''pk_grade_ID''' of an appropriately-sized unsigned integer type (should be larger than the one you chose for the '''students''' table)&lt;br /&gt;
#*: You should declare this field to be '''auto_increment''' and make it the primary key.&lt;br /&gt;
#*: This is called a ''surrogate key'' as opposed to a ''natural key'' because it doesn't arise &amp;quot;naturally&amp;quot; from the data; that is to say that it is not derived from application data. The use of surrogate keys vs. natural keys is a polemic issue amongst database designers.  For a decently unbiased take on the issue, see this page: http://www.agiledata.org/essays/keys.html#Comparison&lt;br /&gt;
#*: '''Food for thought:''' Aside from simply exposing you to the concept, can you think of any reasons why a surrogate key might be preferable for this table?  Alternatively, what attributes, if any, could you use as a natural key, and what might be the drawbacks of doing so?&lt;br /&gt;
#* '''student_id''' of the same integer (unsigned) type that you chose in the '''students''' table&lt;br /&gt;
#* '''grade''' of type '''decimal'''&lt;br /&gt;
#* '''school_code''' of type '''ENUM'''&lt;br /&gt;
#*: Can you guess what entries to use for the enum?&lt;br /&gt;
#* '''dept_id''' of the same integer type that you've used for this field in other tables&lt;br /&gt;
#* '''course_code''' of the same type you chose for the course code in the '''courses''' table&lt;br /&gt;
#: The '''grades''' table should have foreign keys to both the '''students''' table and the '''courses''' table.&lt;br /&gt;
&lt;br /&gt;
=== Populate Tables ===&lt;br /&gt;
&lt;br /&gt;
Now, populate the tables by downloading the text files given below and loading them into the appropriate tables.&lt;br /&gt;
&lt;br /&gt;
'''Note:''' Do not insert all the values manually; instead, use the MySQL's ability to load in data from text files.&lt;br /&gt;
&lt;br /&gt;
You may find the following article to be very helpful: [[MySQL Schema and State]]&lt;br /&gt;
&lt;br /&gt;
The files containing the data are:&lt;br /&gt;
&lt;br /&gt;
* students: https://docs.google.com/file/d/0ByHgvetJ0GJyMGFjMWI4MzAtMzljYy00Yjk3LTllMWItZjZkYmU1NzU3NWU0/edit&lt;br /&gt;
* courses: https://docs.google.com/file/d/0ByHgvetJ0GJyMGY1NGYzYmUtNGQwYi00MTY3LTkzMjgtMDYwOTM3NDNjZTg4/edit&lt;br /&gt;
* departments: https://docs.google.com/file/d/0ByHgvetJ0GJyZWY2OWE4ZWEtYzVmMC00YjBiLWEzZjgtYzdhMDczODAyNDli/edit&lt;br /&gt;
* grades: https://docs.google.com/file/d/0ByHgvetJ0GJyZmJjNzllNjAtMzdhZC00MzU5LTg3MDYtMTRmMjE5MDE2MzY2/edit&lt;br /&gt;
&lt;br /&gt;
=== Insert More Data ===&lt;br /&gt;
&lt;br /&gt;
Insert the following data into the tables that you have created and populated:&lt;br /&gt;
&lt;br /&gt;
# Insert an entry for CSE 330&lt;br /&gt;
#: ''If you don't know CSE's department code, how can you find out using the tables in the database?''&lt;br /&gt;
# Insert the grades given for the students named below.  You may choose to make the entries for whichever classes you like, with the one condition that all of the students must have a grade for CSE 330 (who wouldn't want to take that class: I hear the professor and TAs are amazing!)&lt;br /&gt;
#* '''Ben Harper'''&lt;br /&gt;
#** E-mail: '''bharper@ffym.com'''&lt;br /&gt;
#** Student ID: '''88'''&lt;br /&gt;
#** Grades:&lt;br /&gt;
#*** 5.5&lt;br /&gt;
#*** 0&lt;br /&gt;
#*** 20&lt;br /&gt;
#* '''Matt Freeman'''&lt;br /&gt;
#** E-mail: '''mfreeman@kickinbassist.net'''&lt;br /&gt;
#** Student ID: '''202'''&lt;br /&gt;
#** Grades:&lt;br /&gt;
#*** 100&lt;br /&gt;
#*** 90.5&lt;br /&gt;
#*** 94.8&lt;br /&gt;
#* '''Marc Roberge'''&lt;br /&gt;
#** E-mail: '''mroberge@ofarevolution.us'''&lt;br /&gt;
#** Student ID: '''115'''&lt;br /&gt;
#** Grades:&lt;br /&gt;
#*** 15&lt;br /&gt;
#*** 37&lt;br /&gt;
#*** 45.5&lt;br /&gt;
#: You may choose any 3 classes you'd like for them to be enrolled in, with at least one class, &amp;quot;CSE 330S&amp;quot;, in which they are all enrolled.&lt;br /&gt;
&lt;br /&gt;
=== Querying Your Database ===&lt;br /&gt;
&lt;br /&gt;
Now that you have a fully-functional, populated database, let's do some queries on it!&lt;br /&gt;
&lt;br /&gt;
Please take a screenshot of running the following '''select''' queries and show them to a TA (be sure to include your query command and the response:&lt;br /&gt;
&lt;br /&gt;
# Select the entire grades table.&lt;br /&gt;
# Select all fields describing the courses offered in the school of arts and sciences (school code L).&lt;br /&gt;
# The names, student IDs, and grades of the students who are in CSE330.&lt;br /&gt;
# The names and e-mails of any student with an average below 50 so that the dean can send them an email notification that they are now on academic probation.&lt;br /&gt;
#: ''You should be able to do this in only one query, without making any temporary tables.  You will need to use aggregation functions and the '''having''' keyword.''&lt;br /&gt;
# An individual report card for Jack Johnson, consisting of two tables (these can be done using separate queries):&lt;br /&gt;
## His student ID, e-mail address, and average grade.&lt;br /&gt;
##: ''Again, you should be able to do this in just one query, using the correct combination of aggregation functions and joins.''&lt;br /&gt;
## The classes he is in and his grades for those classes. To give you an idea, one row in the table should look like this:&lt;br /&gt;
##: &amp;lt;code&amp;gt;E	81	400	Independent Study	98.5&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Group Project ==&lt;br /&gt;
&lt;br /&gt;
You will work in pairs on this project.  You may work with the same partner from Module 2, or change to someone else.&lt;br /&gt;
&lt;br /&gt;
'''Important Reminder:''' frequently commit your work to your subversion repository as a backup!&lt;br /&gt;
&lt;br /&gt;
=== Simple News Web Site ===&lt;br /&gt;
&lt;br /&gt;
'''Examples:'''&lt;br /&gt;
* http://digg.com/&lt;br /&gt;
* http://slashdot.org/&lt;br /&gt;
&lt;br /&gt;
You should use '''PHP''' unless you get permission to use another web technology from the instructor.  You may also use phpMyAdmin to help set up databases.&lt;br /&gt;
&lt;br /&gt;
You may find this wiki article helpful: [[PHP and MySQL]]&lt;br /&gt;
&lt;br /&gt;
==== Requirements ====&lt;br /&gt;
&lt;br /&gt;
* Users can register for accounts and then log in to the website.&lt;br /&gt;
* Accounts should have both a username and a ''secure'' password.  '''NEVER store plaintext passwords in a database!'''&lt;br /&gt;
*: For more information on password security, refer to [[Web Application Security, Part 2#Password Security|the Web Application Security guide]].&lt;br /&gt;
*: You may use OpenID as a password system.  While not best practice, md5 is sufficient for points on the lab.  You may also design your own encryption system.&lt;br /&gt;
* Registered users can submit stories: either a link with summary or news text.&lt;br /&gt;
*: You do not have to make a distinction between the two types of stories, although if you want to, you could do something with this for the creative portion of your project.&lt;br /&gt;
* Registered users can comment on any story.&lt;br /&gt;
* Administrator users can delete stories and comments.&lt;br /&gt;
* Unregistered users can only view stories and comments.&lt;br /&gt;
* Registered users can edit their stories and can delete their comments.&lt;br /&gt;
* All data must be kept in a MySQL database (user information, stories, comments, and categories).&lt;br /&gt;
* As before, please check with a TA to see if your creative portion is okay or not before you proceed.&lt;br /&gt;
&lt;br /&gt;
=== Web Security and Validation ===&lt;br /&gt;
&lt;br /&gt;
Your project needs to demonstrate that thought was put into web security and best practice.  For more information, see this week's Web Application Security guide: [[Web Application Security, Part 2]]&lt;br /&gt;
&lt;br /&gt;
In particular:&lt;br /&gt;
&lt;br /&gt;
* '''Your application needs to be secure from SQL injection attacks'''. If you are using prepared queries, you should already be safe on this front.&lt;br /&gt;
* '''All of your output needs to be sanitized using htmlentities()'''.&lt;br /&gt;
&lt;br /&gt;
You shouldn't forget the practices you learned last week:&lt;br /&gt;
&lt;br /&gt;
* '''You should pass tokens in forms''' to prevent CSRF attacks.&lt;br /&gt;
* '''Your page should validate''' with no errors through the W3C validator.&lt;br /&gt;
&lt;br /&gt;
== Grading ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;font-size:2em; line-height:2em;&amp;quot;&amp;gt;'''Due Date: Wednesday October 10th, by 1pm (both individual and group)'''&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
!Assignment&lt;br /&gt;
!Points&lt;br /&gt;
|-&lt;br /&gt;
|Tables Correct&lt;br /&gt;
|2&lt;br /&gt;
|-&lt;br /&gt;
|Data Queries Correct&lt;br /&gt;
|2&lt;br /&gt;
|-&lt;br /&gt;
!colspan=&amp;quot;2&amp;quot;|Group Portion:&lt;br /&gt;
|-&lt;br /&gt;
|User Authentication&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|User Registration&lt;br /&gt;
|1&lt;br /&gt;
|Some type of password encryption&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Main page displays all stories (or most recent stories)&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Page with individual story and comments&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Story Submission&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Comment System&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Administrator Deletion of Stories/Comments&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|User Edit of Story (1 pt) and Comment (1 pt)&lt;br /&gt;
|2&lt;br /&gt;
|-&lt;br /&gt;
|Protect Against SQL Injection Attack&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Sanitize Output&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|CSRF Safe and Validation&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Creative Portion&lt;br /&gt;
|2&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Total Points = 19&lt;br /&gt;
[[Category:Module 3]]&lt;br /&gt;
[[Category:Modules]]&lt;/div&gt;</summary>
		<author><name>Marc</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=Module_3&amp;diff=700</id>
		<title>Module 3</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=Module_3&amp;diff=700"/>
		<updated>2012-09-25T01:46:19Z</updated>

		<summary type="html">&lt;p&gt;Marc: /* Grading */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In Module 3, you will learn about MySQL, a web application database.&lt;br /&gt;
&lt;br /&gt;
This article contains your assignments for Module 3.&lt;br /&gt;
&lt;br /&gt;
== Individual Assignments ==&lt;br /&gt;
&lt;br /&gt;
You will create a simple grades database containing four tables.&lt;br /&gt;
&lt;br /&gt;
'''IMPORTANT:''' The individual assignment is to be done by writing queries by hand.  (You can use phpMyAdmin to run the queries, but '''do not let phpMyAdmin write your queries for you!''')  Writing your own queries gives you a greater understanding of the underlying mechanisms and databases in general.  Additionally, having SQL knowledge and experience is a very marketable trait.&lt;br /&gt;
&lt;br /&gt;
=== Install MySQL and phpMyAdmin ===&lt;br /&gt;
&lt;br /&gt;
Before you start, '''you need to install MySQL''' on your EC2 instance.  You may also install phpMyAdmin, a web frontend to MySQL, if you choose to do so.&lt;br /&gt;
&lt;br /&gt;
You may find the following article to be very helpful: [[Introduction to MySQL]]&lt;br /&gt;
&lt;br /&gt;
=== Set Up a Database ===&lt;br /&gt;
&lt;br /&gt;
You may find the following article to be very helpful: [[Introduction to MySQL]]&lt;br /&gt;
&lt;br /&gt;
# Create a database named '''wustl''' &lt;br /&gt;
# Create a user named '''wustl_inst''' and give them the password '''wustl_pass'''&lt;br /&gt;
&lt;br /&gt;
=== Create Tables ===&lt;br /&gt;
&lt;br /&gt;
You may find the following article to be very helpful: [[MySQL Schema and State]]&lt;br /&gt;
&lt;br /&gt;
When creating tables, keep the following items in mind:&lt;br /&gt;
&lt;br /&gt;
* You should create all tables such that they use the InnoDB storage engine, since we wish to make use of its support of foreign keys. In other database engines, foreign key constraints are not enforced.  (If you mess up, you can use ALTER TABLE to change the storage engine.)&lt;br /&gt;
* Where it is appropriate, you should take advantage of the ability to define fields NOT NULL so that you do not inadvertently insert incomplete data for a row.&lt;br /&gt;
&lt;br /&gt;
Create the following tables:&lt;br /&gt;
&lt;br /&gt;
# Create a table named '''students''' with the following fields:&lt;br /&gt;
#* '''id''' of an appropriately-sized unsigned integer type (we will never need to process more than a million students)&lt;br /&gt;
#* '''first_name''' of type '''VARCHAR(50)'''&lt;br /&gt;
#* '''last_name''' of type '''VARCHAR(50)'''&lt;br /&gt;
#* '''email_address''' of type '''VARCHAR(50)'''&lt;br /&gt;
#: The primary key should be on the '''id''' field.&lt;br /&gt;
# Create a table named '''departments''' with the following fields:&lt;br /&gt;
#* '''school_code''' of type '''ENUM''' (e.g. &amp;quot;L&amp;quot; for ArtSci and &amp;quot;E&amp;quot; for Engineering).  The options are as follows:&lt;br /&gt;
#*: 'L', 'B', 'A', 'F', 'E', 'T', 'I', 'W', 'S', 'U', 'M'&lt;br /&gt;
#* '''dept_id''' of an appropriately-sized unsigned integer type (in the foreseeable future there will never be more than 200 departments in a school)&lt;br /&gt;
#* '''abbreviation''' of type '''VARCHAR(9)''' (e.g. CSE, ChemE, etc)&lt;br /&gt;
#* '''dept_name''' of type '''VARCHAR(200)''' (e.g. Computer Science and Engineering)&lt;br /&gt;
#: The primary key should be on two fields: '''school_code''' and '''dept_id'''&lt;br /&gt;
#: '''Note:''' Why not just use the department ID? The ID numbers are sometimes reused across schools. For instance, department 33 in The School of Arts and Sciences is Psychology while department 33 in The School of Engineering and Applied Sciences is Energy, Environmental and Chemical Engineering. Thus we must also include the school code to differentiate them  such that the record for  E33 is distinct from that of L33.&lt;br /&gt;
# Create a table named '''courses''' with the following fields:&lt;br /&gt;
#* '''school_code''' of type '''ENUM'''&lt;br /&gt;
#*: This should have the same letters in the same order as the '''school_code''' '''ENUM''' field in the '''departments''' table.&lt;br /&gt;
#* '''dept_id''' of the same size of integer as in the '''departments''' table&lt;br /&gt;
#* '''course_code''' of type '''CHAR(5)''' (this will hold course codes; e.g., '330S', '131', '2960')&lt;br /&gt;
#* '''name''' of type '''VARCHAR(150)'''&lt;br /&gt;
#: The appropriate fields in this table should make a foreign key reference to the corresponding fields in '''department'''.&lt;br /&gt;
#: In addition, it is up to you to determine the field(s) for the primary key.&lt;br /&gt;
#: '''Note:''' If you are unsure which fields to make the foreign keys and feel the need to beg your friends or the TAs to give you the answer, bang your head on your desk whilst repeating &amp;quot;I WILL EXERCISE REASON AND COMMON SENSE AND I WILL CURTAIL MY DESIRE TO BLINDLY FOLLOW DIRECTIONS&amp;quot;&lt;br /&gt;
#: ''Disclaimer: don't actually bang your head on your desk, the resulting head trauma may in fact make it harder for you to determine which fields should have associated foreign keys.''&lt;br /&gt;
# Create a table named '''grades''' with the following fields:&lt;br /&gt;
#* '''pk_grade_ID''' of an appropriately-sized unsigned integer type (should be larger than the one you chose for the '''students''' table)&lt;br /&gt;
#*: You should declare this field to be '''auto_increment''' and make it the primary key.&lt;br /&gt;
#*: This is called a ''surrogate key'' as opposed to a ''natural key'' because it doesn't arise &amp;quot;naturally&amp;quot; from the data; that is to say that it is not derived from application data. The use of surrogate keys vs. natural keys is a polemic issue amongst database designers.  For a decently unbiased take on the issue, see this page: http://www.agiledata.org/essays/keys.html#Comparison&lt;br /&gt;
#*: '''Food for thought:''' Aside from simply exposing you to the concept, can you think of any reasons why a surrogate key might be preferable for this table?  Alternatively, what attributes, if any, could you use as a natural key, and what might be the drawbacks of doing so?&lt;br /&gt;
#* '''student_id''' of the same integer (unsigned) type that you chose in the '''students''' table&lt;br /&gt;
#* '''grade''' of type '''decimal'''&lt;br /&gt;
#* '''school_code''' of type '''ENUM'''&lt;br /&gt;
#*: Can you guess what entries to use for the enum?&lt;br /&gt;
#* '''dept_id''' of the same integer type that you've used for this field in other tables&lt;br /&gt;
#* '''course_code''' of the same type you chose for the course code in the '''courses''' table&lt;br /&gt;
#: The '''grades''' table should have foreign keys to both the '''students''' table and the '''courses''' table.&lt;br /&gt;
&lt;br /&gt;
=== Populate Tables ===&lt;br /&gt;
&lt;br /&gt;
Now, populate the tables by downloading the text files given below and loading them into the appropriate tables.&lt;br /&gt;
&lt;br /&gt;
'''Note:''' Do not insert all the values manually; instead, use the MySQL's ability to load in data from text files.&lt;br /&gt;
&lt;br /&gt;
You may find the following article to be very helpful: [[MySQL Schema and State]]&lt;br /&gt;
&lt;br /&gt;
The files containing the data are:&lt;br /&gt;
&lt;br /&gt;
* students: https://docs.google.com/file/d/0ByHgvetJ0GJyMGFjMWI4MzAtMzljYy00Yjk3LTllMWItZjZkYmU1NzU3NWU0/edit&lt;br /&gt;
* courses: https://docs.google.com/file/d/0ByHgvetJ0GJyMGY1NGYzYmUtNGQwYi00MTY3LTkzMjgtMDYwOTM3NDNjZTg4/edit&lt;br /&gt;
* departments: https://docs.google.com/file/d/0ByHgvetJ0GJyZWY2OWE4ZWEtYzVmMC00YjBiLWEzZjgtYzdhMDczODAyNDli/edit&lt;br /&gt;
* grades: https://docs.google.com/file/d/0ByHgvetJ0GJyZmJjNzllNjAtMzdhZC00MzU5LTg3MDYtMTRmMjE5MDE2MzY2/edit&lt;br /&gt;
&lt;br /&gt;
=== Insert More Data ===&lt;br /&gt;
&lt;br /&gt;
Insert the following data into the tables that you have created and populated:&lt;br /&gt;
&lt;br /&gt;
# Insert an entry for CSE 330&lt;br /&gt;
#: ''If you don't know CSE's department code, how can you find out using the tables in the database?''&lt;br /&gt;
# Insert the grades given for the students named below.  You may choose to make the entries for whichever classes you like, with the one condition that all of the students must have a grade for CSE 330 (who wouldn't want to take that class: I hear the professor and TAs are amazing!)&lt;br /&gt;
#* '''Ben Harper'''&lt;br /&gt;
#** E-mail: '''bharper@ffym.com'''&lt;br /&gt;
#** Student ID: '''88'''&lt;br /&gt;
#** Grades:&lt;br /&gt;
#*** 5.5&lt;br /&gt;
#*** 0&lt;br /&gt;
#*** 20&lt;br /&gt;
#* '''Matt Freeman'''&lt;br /&gt;
#** E-mail: '''mfreeman@kickinbassist.net'''&lt;br /&gt;
#** Student ID: '''202'''&lt;br /&gt;
#** Grades:&lt;br /&gt;
#*** 100&lt;br /&gt;
#*** 90.5&lt;br /&gt;
#*** 94.8&lt;br /&gt;
#* '''Marc Roberge'''&lt;br /&gt;
#** E-mail: '''mroberge@ofarevolution.us'''&lt;br /&gt;
#** Student ID: '''115'''&lt;br /&gt;
#** Grades:&lt;br /&gt;
#*** 15&lt;br /&gt;
#*** 37&lt;br /&gt;
#*** 45.5&lt;br /&gt;
#: You may choose any 3 classes you'd like for them to be enrolled in, with at least one class, &amp;quot;CSE 330S&amp;quot;, in which they are all enrolled.&lt;br /&gt;
&lt;br /&gt;
=== Querying Your Database ===&lt;br /&gt;
&lt;br /&gt;
Now that you have a fully-functional, populated database, let's do some queries on it!&lt;br /&gt;
&lt;br /&gt;
Please take a screenshot of running the following '''select''' queries and show them to a TA (be sure to include your query command and the response:&lt;br /&gt;
&lt;br /&gt;
# Select the entire grades table.&lt;br /&gt;
# Select all fields describing the courses offered in the school of arts and sciences (school code L).&lt;br /&gt;
# The names, student IDs, and grades of the students who are in CSE330.&lt;br /&gt;
# The names and e-mails of any student with an average below 50 so that the dean can send them an email notification that they are now on academic probation.&lt;br /&gt;
#: ''You should be able to do this in only one query, without making any temporary tables.  You will need to use aggregation functions and the '''having''' keyword.''&lt;br /&gt;
# An individual report card for Jack Johnson, consisting of two tables (these can be done using separate queries):&lt;br /&gt;
## His student ID, e-mail address, and average grade.&lt;br /&gt;
##: ''Again, you should be able to do this in just one query, using the correct combination of aggregation functions and joins.''&lt;br /&gt;
## The classes he is in and his grades for those classes. To give you an idea, one row in the table should look like this:&lt;br /&gt;
##: &amp;lt;code&amp;gt;E	81	400	Independent Study	98.5&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Group Project ==&lt;br /&gt;
&lt;br /&gt;
You will work in pairs on this project.  You may work with the same partner from Module 2, or change to someone else.&lt;br /&gt;
&lt;br /&gt;
'''Important Reminder:''' frequently commit your work to your subversion repository as a backup!&lt;br /&gt;
&lt;br /&gt;
=== Simple News Web Site ===&lt;br /&gt;
&lt;br /&gt;
'''Examples:'''&lt;br /&gt;
* http://digg.com/&lt;br /&gt;
* http://slashdot.org/&lt;br /&gt;
&lt;br /&gt;
You should use '''PHP''' unless you get permission to use another web technology from the instructor.  You may also use phpMyAdmin to help set up databases.&lt;br /&gt;
&lt;br /&gt;
You may find this wiki article helpful: [[PHP and MySQL]]&lt;br /&gt;
&lt;br /&gt;
==== Requirements ====&lt;br /&gt;
&lt;br /&gt;
* Users can register for accounts and then log in to the website.&lt;br /&gt;
* Accounts should have both a username and a ''secure'' password.  '''NEVER store plaintext passwords in a database!'''&lt;br /&gt;
*: For more information on password security, refer to [[Web Application Security, Part 2#Password Security|the Web Application Security guide]].&lt;br /&gt;
*: You may use OpenID as a password system.  While not best practice, md5 is sufficient for points on the lab.  You may also design your own encryption system.&lt;br /&gt;
* Registered users can submit stories: either a link with summary or news text.&lt;br /&gt;
*: You do not have to make a distinction between the two types of stories, although if you want to, you could do something with this for the creative portion of your project.&lt;br /&gt;
* Registered users can comment on any story.&lt;br /&gt;
* Administrator users can delete stories and comments.&lt;br /&gt;
* Unregistered users can only view stories and comments.&lt;br /&gt;
* Registered users can edit their stories and can delete their comments.&lt;br /&gt;
* All data must be kept in a MySQL database (user information, stories, comments, and categories).&lt;br /&gt;
* As before, please check with a TA to see if your creative portion is okay or not before you proceed.&lt;br /&gt;
&lt;br /&gt;
=== Web Security and Validation ===&lt;br /&gt;
&lt;br /&gt;
Your project needs to demonstrate that thought was put into web security and best practice.  For more information, see this week's Web Application Security guide: [[Web Application Security, Part 2]]&lt;br /&gt;
&lt;br /&gt;
In particular:&lt;br /&gt;
&lt;br /&gt;
* '''Your application needs to be secure from SQL injection attacks'''. If you are using prepared queries, you should already be safe on this front.&lt;br /&gt;
* '''All of your output needs to be sanitized using htmlentities()'''.&lt;br /&gt;
&lt;br /&gt;
You shouldn't forget the practices you learned last week:&lt;br /&gt;
&lt;br /&gt;
* '''You should pass tokens in forms''' to prevent CSRF attacks.&lt;br /&gt;
* '''Your page should validate''' with no errors through the W3C validator.&lt;br /&gt;
&lt;br /&gt;
== Grading ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;font-size:2em; line-height:2em;&amp;quot;&amp;gt;'''Due Date: Wednesday October 10th, by 1pm (both individual and group)'''&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
!Assignment&lt;br /&gt;
!Points&lt;br /&gt;
|-&lt;br /&gt;
|Tables Correct&lt;br /&gt;
|2&lt;br /&gt;
|-&lt;br /&gt;
|Data Queries Correct&lt;br /&gt;
|2&lt;br /&gt;
|-&lt;br /&gt;
!colspan=&amp;quot;2&amp;quot;|Group Portion:&lt;br /&gt;
|-&lt;br /&gt;
|User Authentication&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|User Registration&lt;br /&gt;
|1&lt;br /&gt;
Some type of password encryption&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Main page displays all stories (or most recent stories)&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Page with individual story and comments&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Story Submission&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Comment System&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Administrator Deletion of Stories/Comments&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|User Edit of Story (1 pt) and Comment (1 pt)&lt;br /&gt;
|2&lt;br /&gt;
|-&lt;br /&gt;
|Protect Against SQL Injection Attack&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Sanitize Output&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|CSRF Safe and Validation&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Creative Portion&lt;br /&gt;
|2&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Total Points = 19&lt;br /&gt;
[[Category:Module 3]]&lt;br /&gt;
[[Category:Modules]]&lt;/div&gt;</summary>
		<author><name>Marc</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=Module_3&amp;diff=699</id>
		<title>Module 3</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=Module_3&amp;diff=699"/>
		<updated>2012-09-25T01:45:14Z</updated>

		<summary type="html">&lt;p&gt;Marc: /* Grading */ i cant add&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In Module 3, you will learn about MySQL, a web application database.&lt;br /&gt;
&lt;br /&gt;
This article contains your assignments for Module 3.&lt;br /&gt;
&lt;br /&gt;
== Individual Assignments ==&lt;br /&gt;
&lt;br /&gt;
You will create a simple grades database containing four tables.&lt;br /&gt;
&lt;br /&gt;
'''IMPORTANT:''' The individual assignment is to be done by writing queries by hand.  (You can use phpMyAdmin to run the queries, but '''do not let phpMyAdmin write your queries for you!''')  Writing your own queries gives you a greater understanding of the underlying mechanisms and databases in general.  Additionally, having SQL knowledge and experience is a very marketable trait.&lt;br /&gt;
&lt;br /&gt;
=== Install MySQL and phpMyAdmin ===&lt;br /&gt;
&lt;br /&gt;
Before you start, '''you need to install MySQL''' on your EC2 instance.  You may also install phpMyAdmin, a web frontend to MySQL, if you choose to do so.&lt;br /&gt;
&lt;br /&gt;
You may find the following article to be very helpful: [[Introduction to MySQL]]&lt;br /&gt;
&lt;br /&gt;
=== Set Up a Database ===&lt;br /&gt;
&lt;br /&gt;
You may find the following article to be very helpful: [[Introduction to MySQL]]&lt;br /&gt;
&lt;br /&gt;
# Create a database named '''wustl''' &lt;br /&gt;
# Create a user named '''wustl_inst''' and give them the password '''wustl_pass'''&lt;br /&gt;
&lt;br /&gt;
=== Create Tables ===&lt;br /&gt;
&lt;br /&gt;
You may find the following article to be very helpful: [[MySQL Schema and State]]&lt;br /&gt;
&lt;br /&gt;
When creating tables, keep the following items in mind:&lt;br /&gt;
&lt;br /&gt;
* You should create all tables such that they use the InnoDB storage engine, since we wish to make use of its support of foreign keys. In other database engines, foreign key constraints are not enforced.  (If you mess up, you can use ALTER TABLE to change the storage engine.)&lt;br /&gt;
* Where it is appropriate, you should take advantage of the ability to define fields NOT NULL so that you do not inadvertently insert incomplete data for a row.&lt;br /&gt;
&lt;br /&gt;
Create the following tables:&lt;br /&gt;
&lt;br /&gt;
# Create a table named '''students''' with the following fields:&lt;br /&gt;
#* '''id''' of an appropriately-sized unsigned integer type (we will never need to process more than a million students)&lt;br /&gt;
#* '''first_name''' of type '''VARCHAR(50)'''&lt;br /&gt;
#* '''last_name''' of type '''VARCHAR(50)'''&lt;br /&gt;
#* '''email_address''' of type '''VARCHAR(50)'''&lt;br /&gt;
#: The primary key should be on the '''id''' field.&lt;br /&gt;
# Create a table named '''departments''' with the following fields:&lt;br /&gt;
#* '''school_code''' of type '''ENUM''' (e.g. &amp;quot;L&amp;quot; for ArtSci and &amp;quot;E&amp;quot; for Engineering).  The options are as follows:&lt;br /&gt;
#*: 'L', 'B', 'A', 'F', 'E', 'T', 'I', 'W', 'S', 'U', 'M'&lt;br /&gt;
#* '''dept_id''' of an appropriately-sized unsigned integer type (in the foreseeable future there will never be more than 200 departments in a school)&lt;br /&gt;
#* '''abbreviation''' of type '''VARCHAR(9)''' (e.g. CSE, ChemE, etc)&lt;br /&gt;
#* '''dept_name''' of type '''VARCHAR(200)''' (e.g. Computer Science and Engineering)&lt;br /&gt;
#: The primary key should be on two fields: '''school_code''' and '''dept_id'''&lt;br /&gt;
#: '''Note:''' Why not just use the department ID? The ID numbers are sometimes reused across schools. For instance, department 33 in The School of Arts and Sciences is Psychology while department 33 in The School of Engineering and Applied Sciences is Energy, Environmental and Chemical Engineering. Thus we must also include the school code to differentiate them  such that the record for  E33 is distinct from that of L33.&lt;br /&gt;
# Create a table named '''courses''' with the following fields:&lt;br /&gt;
#* '''school_code''' of type '''ENUM'''&lt;br /&gt;
#*: This should have the same letters in the same order as the '''school_code''' '''ENUM''' field in the '''departments''' table.&lt;br /&gt;
#* '''dept_id''' of the same size of integer as in the '''departments''' table&lt;br /&gt;
#* '''course_code''' of type '''CHAR(5)''' (this will hold course codes; e.g., '330S', '131', '2960')&lt;br /&gt;
#* '''name''' of type '''VARCHAR(150)'''&lt;br /&gt;
#: The appropriate fields in this table should make a foreign key reference to the corresponding fields in '''department'''.&lt;br /&gt;
#: In addition, it is up to you to determine the field(s) for the primary key.&lt;br /&gt;
#: '''Note:''' If you are unsure which fields to make the foreign keys and feel the need to beg your friends or the TAs to give you the answer, bang your head on your desk whilst repeating &amp;quot;I WILL EXERCISE REASON AND COMMON SENSE AND I WILL CURTAIL MY DESIRE TO BLINDLY FOLLOW DIRECTIONS&amp;quot;&lt;br /&gt;
#: ''Disclaimer: don't actually bang your head on your desk, the resulting head trauma may in fact make it harder for you to determine which fields should have associated foreign keys.''&lt;br /&gt;
# Create a table named '''grades''' with the following fields:&lt;br /&gt;
#* '''pk_grade_ID''' of an appropriately-sized unsigned integer type (should be larger than the one you chose for the '''students''' table)&lt;br /&gt;
#*: You should declare this field to be '''auto_increment''' and make it the primary key.&lt;br /&gt;
#*: This is called a ''surrogate key'' as opposed to a ''natural key'' because it doesn't arise &amp;quot;naturally&amp;quot; from the data; that is to say that it is not derived from application data. The use of surrogate keys vs. natural keys is a polemic issue amongst database designers.  For a decently unbiased take on the issue, see this page: http://www.agiledata.org/essays/keys.html#Comparison&lt;br /&gt;
#*: '''Food for thought:''' Aside from simply exposing you to the concept, can you think of any reasons why a surrogate key might be preferable for this table?  Alternatively, what attributes, if any, could you use as a natural key, and what might be the drawbacks of doing so?&lt;br /&gt;
#* '''student_id''' of the same integer (unsigned) type that you chose in the '''students''' table&lt;br /&gt;
#* '''grade''' of type '''decimal'''&lt;br /&gt;
#* '''school_code''' of type '''ENUM'''&lt;br /&gt;
#*: Can you guess what entries to use for the enum?&lt;br /&gt;
#* '''dept_id''' of the same integer type that you've used for this field in other tables&lt;br /&gt;
#* '''course_code''' of the same type you chose for the course code in the '''courses''' table&lt;br /&gt;
#: The '''grades''' table should have foreign keys to both the '''students''' table and the '''courses''' table.&lt;br /&gt;
&lt;br /&gt;
=== Populate Tables ===&lt;br /&gt;
&lt;br /&gt;
Now, populate the tables by downloading the text files given below and loading them into the appropriate tables.&lt;br /&gt;
&lt;br /&gt;
'''Note:''' Do not insert all the values manually; instead, use the MySQL's ability to load in data from text files.&lt;br /&gt;
&lt;br /&gt;
You may find the following article to be very helpful: [[MySQL Schema and State]]&lt;br /&gt;
&lt;br /&gt;
The files containing the data are:&lt;br /&gt;
&lt;br /&gt;
* students: https://docs.google.com/file/d/0ByHgvetJ0GJyMGFjMWI4MzAtMzljYy00Yjk3LTllMWItZjZkYmU1NzU3NWU0/edit&lt;br /&gt;
* courses: https://docs.google.com/file/d/0ByHgvetJ0GJyMGY1NGYzYmUtNGQwYi00MTY3LTkzMjgtMDYwOTM3NDNjZTg4/edit&lt;br /&gt;
* departments: https://docs.google.com/file/d/0ByHgvetJ0GJyZWY2OWE4ZWEtYzVmMC00YjBiLWEzZjgtYzdhMDczODAyNDli/edit&lt;br /&gt;
* grades: https://docs.google.com/file/d/0ByHgvetJ0GJyZmJjNzllNjAtMzdhZC00MzU5LTg3MDYtMTRmMjE5MDE2MzY2/edit&lt;br /&gt;
&lt;br /&gt;
=== Insert More Data ===&lt;br /&gt;
&lt;br /&gt;
Insert the following data into the tables that you have created and populated:&lt;br /&gt;
&lt;br /&gt;
# Insert an entry for CSE 330&lt;br /&gt;
#: ''If you don't know CSE's department code, how can you find out using the tables in the database?''&lt;br /&gt;
# Insert the grades given for the students named below.  You may choose to make the entries for whichever classes you like, with the one condition that all of the students must have a grade for CSE 330 (who wouldn't want to take that class: I hear the professor and TAs are amazing!)&lt;br /&gt;
#* '''Ben Harper'''&lt;br /&gt;
#** E-mail: '''bharper@ffym.com'''&lt;br /&gt;
#** Student ID: '''88'''&lt;br /&gt;
#** Grades:&lt;br /&gt;
#*** 5.5&lt;br /&gt;
#*** 0&lt;br /&gt;
#*** 20&lt;br /&gt;
#* '''Matt Freeman'''&lt;br /&gt;
#** E-mail: '''mfreeman@kickinbassist.net'''&lt;br /&gt;
#** Student ID: '''202'''&lt;br /&gt;
#** Grades:&lt;br /&gt;
#*** 100&lt;br /&gt;
#*** 90.5&lt;br /&gt;
#*** 94.8&lt;br /&gt;
#* '''Marc Roberge'''&lt;br /&gt;
#** E-mail: '''mroberge@ofarevolution.us'''&lt;br /&gt;
#** Student ID: '''115'''&lt;br /&gt;
#** Grades:&lt;br /&gt;
#*** 15&lt;br /&gt;
#*** 37&lt;br /&gt;
#*** 45.5&lt;br /&gt;
#: You may choose any 3 classes you'd like for them to be enrolled in, with at least one class, &amp;quot;CSE 330S&amp;quot;, in which they are all enrolled.&lt;br /&gt;
&lt;br /&gt;
=== Querying Your Database ===&lt;br /&gt;
&lt;br /&gt;
Now that you have a fully-functional, populated database, let's do some queries on it!&lt;br /&gt;
&lt;br /&gt;
Please take a screenshot of running the following '''select''' queries and show them to a TA (be sure to include your query command and the response:&lt;br /&gt;
&lt;br /&gt;
# Select the entire grades table.&lt;br /&gt;
# Select all fields describing the courses offered in the school of arts and sciences (school code L).&lt;br /&gt;
# The names, student IDs, and grades of the students who are in CSE330.&lt;br /&gt;
# The names and e-mails of any student with an average below 50 so that the dean can send them an email notification that they are now on academic probation.&lt;br /&gt;
#: ''You should be able to do this in only one query, without making any temporary tables.  You will need to use aggregation functions and the '''having''' keyword.''&lt;br /&gt;
# An individual report card for Jack Johnson, consisting of two tables (these can be done using separate queries):&lt;br /&gt;
## His student ID, e-mail address, and average grade.&lt;br /&gt;
##: ''Again, you should be able to do this in just one query, using the correct combination of aggregation functions and joins.''&lt;br /&gt;
## The classes he is in and his grades for those classes. To give you an idea, one row in the table should look like this:&lt;br /&gt;
##: &amp;lt;code&amp;gt;E	81	400	Independent Study	98.5&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Group Project ==&lt;br /&gt;
&lt;br /&gt;
You will work in pairs on this project.  You may work with the same partner from Module 2, or change to someone else.&lt;br /&gt;
&lt;br /&gt;
'''Important Reminder:''' frequently commit your work to your subversion repository as a backup!&lt;br /&gt;
&lt;br /&gt;
=== Simple News Web Site ===&lt;br /&gt;
&lt;br /&gt;
'''Examples:'''&lt;br /&gt;
* http://digg.com/&lt;br /&gt;
* http://slashdot.org/&lt;br /&gt;
&lt;br /&gt;
You should use '''PHP''' unless you get permission to use another web technology from the instructor.  You may also use phpMyAdmin to help set up databases.&lt;br /&gt;
&lt;br /&gt;
You may find this wiki article helpful: [[PHP and MySQL]]&lt;br /&gt;
&lt;br /&gt;
==== Requirements ====&lt;br /&gt;
&lt;br /&gt;
* Users can register for accounts and then log in to the website.&lt;br /&gt;
* Accounts should have both a username and a ''secure'' password.  '''NEVER store plaintext passwords in a database!'''&lt;br /&gt;
*: For more information on password security, refer to [[Web Application Security, Part 2#Password Security|the Web Application Security guide]].&lt;br /&gt;
*: You may use OpenID as a password system.  While not best practice, md5 is sufficient for points on the lab.  You may also design your own encryption system.&lt;br /&gt;
* Registered users can submit stories: either a link with summary or news text.&lt;br /&gt;
*: You do not have to make a distinction between the two types of stories, although if you want to, you could do something with this for the creative portion of your project.&lt;br /&gt;
* Registered users can comment on any story.&lt;br /&gt;
* Administrator users can delete stories and comments.&lt;br /&gt;
* Unregistered users can only view stories and comments.&lt;br /&gt;
* Registered users can edit their stories and can delete their comments.&lt;br /&gt;
* All data must be kept in a MySQL database (user information, stories, comments, and categories).&lt;br /&gt;
* As before, please check with a TA to see if your creative portion is okay or not before you proceed.&lt;br /&gt;
&lt;br /&gt;
=== Web Security and Validation ===&lt;br /&gt;
&lt;br /&gt;
Your project needs to demonstrate that thought was put into web security and best practice.  For more information, see this week's Web Application Security guide: [[Web Application Security, Part 2]]&lt;br /&gt;
&lt;br /&gt;
In particular:&lt;br /&gt;
&lt;br /&gt;
* '''Your application needs to be secure from SQL injection attacks'''. If you are using prepared queries, you should already be safe on this front.&lt;br /&gt;
* '''All of your output needs to be sanitized using htmlentities()'''.&lt;br /&gt;
&lt;br /&gt;
You shouldn't forget the practices you learned last week:&lt;br /&gt;
&lt;br /&gt;
* '''You should pass tokens in forms''' to prevent CSRF attacks.&lt;br /&gt;
* '''Your page should validate''' with no errors through the W3C validator.&lt;br /&gt;
&lt;br /&gt;
== Grading ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;font-size:2em; line-height:2em;&amp;quot;&amp;gt;'''Due Date: Wednesday October 10th, by 1pm (both individual and group)'''&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
!Assignment&lt;br /&gt;
!Points&lt;br /&gt;
|-&lt;br /&gt;
|Tables Correct&lt;br /&gt;
|2&lt;br /&gt;
|-&lt;br /&gt;
|Data Queries Correct&lt;br /&gt;
|2&lt;br /&gt;
|-&lt;br /&gt;
!colspan=&amp;quot;2&amp;quot;|Group Portion:&lt;br /&gt;
|-&lt;br /&gt;
|User Authentication&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|User Registration&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Password Encryption using a Salt&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Main page displays all stories (or most recent stories)&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Page with individual story and comments&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Story Submission&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Comment System&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Administrator Deletion of Stories/Comments&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|User Edit of Story (1 pt) and Comment (1 pt)&lt;br /&gt;
|2&lt;br /&gt;
|-&lt;br /&gt;
|Protect Against SQL Injection Attack&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Sanitize Output&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|CSRF Safe and Validation&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Creative Portion&lt;br /&gt;
|2&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Total Points = 19&lt;br /&gt;
[[Category:Module 3]]&lt;br /&gt;
[[Category:Modules]]&lt;/div&gt;</summary>
		<author><name>Marc</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=Module_3&amp;diff=698</id>
		<title>Module 3</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=Module_3&amp;diff=698"/>
		<updated>2012-09-25T01:44:52Z</updated>

		<summary type="html">&lt;p&gt;Marc: /* Grading */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In Module 3, you will learn about MySQL, a web application database.&lt;br /&gt;
&lt;br /&gt;
This article contains your assignments for Module 3.&lt;br /&gt;
&lt;br /&gt;
== Individual Assignments ==&lt;br /&gt;
&lt;br /&gt;
You will create a simple grades database containing four tables.&lt;br /&gt;
&lt;br /&gt;
'''IMPORTANT:''' The individual assignment is to be done by writing queries by hand.  (You can use phpMyAdmin to run the queries, but '''do not let phpMyAdmin write your queries for you!''')  Writing your own queries gives you a greater understanding of the underlying mechanisms and databases in general.  Additionally, having SQL knowledge and experience is a very marketable trait.&lt;br /&gt;
&lt;br /&gt;
=== Install MySQL and phpMyAdmin ===&lt;br /&gt;
&lt;br /&gt;
Before you start, '''you need to install MySQL''' on your EC2 instance.  You may also install phpMyAdmin, a web frontend to MySQL, if you choose to do so.&lt;br /&gt;
&lt;br /&gt;
You may find the following article to be very helpful: [[Introduction to MySQL]]&lt;br /&gt;
&lt;br /&gt;
=== Set Up a Database ===&lt;br /&gt;
&lt;br /&gt;
You may find the following article to be very helpful: [[Introduction to MySQL]]&lt;br /&gt;
&lt;br /&gt;
# Create a database named '''wustl''' &lt;br /&gt;
# Create a user named '''wustl_inst''' and give them the password '''wustl_pass'''&lt;br /&gt;
&lt;br /&gt;
=== Create Tables ===&lt;br /&gt;
&lt;br /&gt;
You may find the following article to be very helpful: [[MySQL Schema and State]]&lt;br /&gt;
&lt;br /&gt;
When creating tables, keep the following items in mind:&lt;br /&gt;
&lt;br /&gt;
* You should create all tables such that they use the InnoDB storage engine, since we wish to make use of its support of foreign keys. In other database engines, foreign key constraints are not enforced.  (If you mess up, you can use ALTER TABLE to change the storage engine.)&lt;br /&gt;
* Where it is appropriate, you should take advantage of the ability to define fields NOT NULL so that you do not inadvertently insert incomplete data for a row.&lt;br /&gt;
&lt;br /&gt;
Create the following tables:&lt;br /&gt;
&lt;br /&gt;
# Create a table named '''students''' with the following fields:&lt;br /&gt;
#* '''id''' of an appropriately-sized unsigned integer type (we will never need to process more than a million students)&lt;br /&gt;
#* '''first_name''' of type '''VARCHAR(50)'''&lt;br /&gt;
#* '''last_name''' of type '''VARCHAR(50)'''&lt;br /&gt;
#* '''email_address''' of type '''VARCHAR(50)'''&lt;br /&gt;
#: The primary key should be on the '''id''' field.&lt;br /&gt;
# Create a table named '''departments''' with the following fields:&lt;br /&gt;
#* '''school_code''' of type '''ENUM''' (e.g. &amp;quot;L&amp;quot; for ArtSci and &amp;quot;E&amp;quot; for Engineering).  The options are as follows:&lt;br /&gt;
#*: 'L', 'B', 'A', 'F', 'E', 'T', 'I', 'W', 'S', 'U', 'M'&lt;br /&gt;
#* '''dept_id''' of an appropriately-sized unsigned integer type (in the foreseeable future there will never be more than 200 departments in a school)&lt;br /&gt;
#* '''abbreviation''' of type '''VARCHAR(9)''' (e.g. CSE, ChemE, etc)&lt;br /&gt;
#* '''dept_name''' of type '''VARCHAR(200)''' (e.g. Computer Science and Engineering)&lt;br /&gt;
#: The primary key should be on two fields: '''school_code''' and '''dept_id'''&lt;br /&gt;
#: '''Note:''' Why not just use the department ID? The ID numbers are sometimes reused across schools. For instance, department 33 in The School of Arts and Sciences is Psychology while department 33 in The School of Engineering and Applied Sciences is Energy, Environmental and Chemical Engineering. Thus we must also include the school code to differentiate them  such that the record for  E33 is distinct from that of L33.&lt;br /&gt;
# Create a table named '''courses''' with the following fields:&lt;br /&gt;
#* '''school_code''' of type '''ENUM'''&lt;br /&gt;
#*: This should have the same letters in the same order as the '''school_code''' '''ENUM''' field in the '''departments''' table.&lt;br /&gt;
#* '''dept_id''' of the same size of integer as in the '''departments''' table&lt;br /&gt;
#* '''course_code''' of type '''CHAR(5)''' (this will hold course codes; e.g., '330S', '131', '2960')&lt;br /&gt;
#* '''name''' of type '''VARCHAR(150)'''&lt;br /&gt;
#: The appropriate fields in this table should make a foreign key reference to the corresponding fields in '''department'''.&lt;br /&gt;
#: In addition, it is up to you to determine the field(s) for the primary key.&lt;br /&gt;
#: '''Note:''' If you are unsure which fields to make the foreign keys and feel the need to beg your friends or the TAs to give you the answer, bang your head on your desk whilst repeating &amp;quot;I WILL EXERCISE REASON AND COMMON SENSE AND I WILL CURTAIL MY DESIRE TO BLINDLY FOLLOW DIRECTIONS&amp;quot;&lt;br /&gt;
#: ''Disclaimer: don't actually bang your head on your desk, the resulting head trauma may in fact make it harder for you to determine which fields should have associated foreign keys.''&lt;br /&gt;
# Create a table named '''grades''' with the following fields:&lt;br /&gt;
#* '''pk_grade_ID''' of an appropriately-sized unsigned integer type (should be larger than the one you chose for the '''students''' table)&lt;br /&gt;
#*: You should declare this field to be '''auto_increment''' and make it the primary key.&lt;br /&gt;
#*: This is called a ''surrogate key'' as opposed to a ''natural key'' because it doesn't arise &amp;quot;naturally&amp;quot; from the data; that is to say that it is not derived from application data. The use of surrogate keys vs. natural keys is a polemic issue amongst database designers.  For a decently unbiased take on the issue, see this page: http://www.agiledata.org/essays/keys.html#Comparison&lt;br /&gt;
#*: '''Food for thought:''' Aside from simply exposing you to the concept, can you think of any reasons why a surrogate key might be preferable for this table?  Alternatively, what attributes, if any, could you use as a natural key, and what might be the drawbacks of doing so?&lt;br /&gt;
#* '''student_id''' of the same integer (unsigned) type that you chose in the '''students''' table&lt;br /&gt;
#* '''grade''' of type '''decimal'''&lt;br /&gt;
#* '''school_code''' of type '''ENUM'''&lt;br /&gt;
#*: Can you guess what entries to use for the enum?&lt;br /&gt;
#* '''dept_id''' of the same integer type that you've used for this field in other tables&lt;br /&gt;
#* '''course_code''' of the same type you chose for the course code in the '''courses''' table&lt;br /&gt;
#: The '''grades''' table should have foreign keys to both the '''students''' table and the '''courses''' table.&lt;br /&gt;
&lt;br /&gt;
=== Populate Tables ===&lt;br /&gt;
&lt;br /&gt;
Now, populate the tables by downloading the text files given below and loading them into the appropriate tables.&lt;br /&gt;
&lt;br /&gt;
'''Note:''' Do not insert all the values manually; instead, use the MySQL's ability to load in data from text files.&lt;br /&gt;
&lt;br /&gt;
You may find the following article to be very helpful: [[MySQL Schema and State]]&lt;br /&gt;
&lt;br /&gt;
The files containing the data are:&lt;br /&gt;
&lt;br /&gt;
* students: https://docs.google.com/file/d/0ByHgvetJ0GJyMGFjMWI4MzAtMzljYy00Yjk3LTllMWItZjZkYmU1NzU3NWU0/edit&lt;br /&gt;
* courses: https://docs.google.com/file/d/0ByHgvetJ0GJyMGY1NGYzYmUtNGQwYi00MTY3LTkzMjgtMDYwOTM3NDNjZTg4/edit&lt;br /&gt;
* departments: https://docs.google.com/file/d/0ByHgvetJ0GJyZWY2OWE4ZWEtYzVmMC00YjBiLWEzZjgtYzdhMDczODAyNDli/edit&lt;br /&gt;
* grades: https://docs.google.com/file/d/0ByHgvetJ0GJyZmJjNzllNjAtMzdhZC00MzU5LTg3MDYtMTRmMjE5MDE2MzY2/edit&lt;br /&gt;
&lt;br /&gt;
=== Insert More Data ===&lt;br /&gt;
&lt;br /&gt;
Insert the following data into the tables that you have created and populated:&lt;br /&gt;
&lt;br /&gt;
# Insert an entry for CSE 330&lt;br /&gt;
#: ''If you don't know CSE's department code, how can you find out using the tables in the database?''&lt;br /&gt;
# Insert the grades given for the students named below.  You may choose to make the entries for whichever classes you like, with the one condition that all of the students must have a grade for CSE 330 (who wouldn't want to take that class: I hear the professor and TAs are amazing!)&lt;br /&gt;
#* '''Ben Harper'''&lt;br /&gt;
#** E-mail: '''bharper@ffym.com'''&lt;br /&gt;
#** Student ID: '''88'''&lt;br /&gt;
#** Grades:&lt;br /&gt;
#*** 5.5&lt;br /&gt;
#*** 0&lt;br /&gt;
#*** 20&lt;br /&gt;
#* '''Matt Freeman'''&lt;br /&gt;
#** E-mail: '''mfreeman@kickinbassist.net'''&lt;br /&gt;
#** Student ID: '''202'''&lt;br /&gt;
#** Grades:&lt;br /&gt;
#*** 100&lt;br /&gt;
#*** 90.5&lt;br /&gt;
#*** 94.8&lt;br /&gt;
#* '''Marc Roberge'''&lt;br /&gt;
#** E-mail: '''mroberge@ofarevolution.us'''&lt;br /&gt;
#** Student ID: '''115'''&lt;br /&gt;
#** Grades:&lt;br /&gt;
#*** 15&lt;br /&gt;
#*** 37&lt;br /&gt;
#*** 45.5&lt;br /&gt;
#: You may choose any 3 classes you'd like for them to be enrolled in, with at least one class, &amp;quot;CSE 330S&amp;quot;, in which they are all enrolled.&lt;br /&gt;
&lt;br /&gt;
=== Querying Your Database ===&lt;br /&gt;
&lt;br /&gt;
Now that you have a fully-functional, populated database, let's do some queries on it!&lt;br /&gt;
&lt;br /&gt;
Please take a screenshot of running the following '''select''' queries and show them to a TA (be sure to include your query command and the response:&lt;br /&gt;
&lt;br /&gt;
# Select the entire grades table.&lt;br /&gt;
# Select all fields describing the courses offered in the school of arts and sciences (school code L).&lt;br /&gt;
# The names, student IDs, and grades of the students who are in CSE330.&lt;br /&gt;
# The names and e-mails of any student with an average below 50 so that the dean can send them an email notification that they are now on academic probation.&lt;br /&gt;
#: ''You should be able to do this in only one query, without making any temporary tables.  You will need to use aggregation functions and the '''having''' keyword.''&lt;br /&gt;
# An individual report card for Jack Johnson, consisting of two tables (these can be done using separate queries):&lt;br /&gt;
## His student ID, e-mail address, and average grade.&lt;br /&gt;
##: ''Again, you should be able to do this in just one query, using the correct combination of aggregation functions and joins.''&lt;br /&gt;
## The classes he is in and his grades for those classes. To give you an idea, one row in the table should look like this:&lt;br /&gt;
##: &amp;lt;code&amp;gt;E	81	400	Independent Study	98.5&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Group Project ==&lt;br /&gt;
&lt;br /&gt;
You will work in pairs on this project.  You may work with the same partner from Module 2, or change to someone else.&lt;br /&gt;
&lt;br /&gt;
'''Important Reminder:''' frequently commit your work to your subversion repository as a backup!&lt;br /&gt;
&lt;br /&gt;
=== Simple News Web Site ===&lt;br /&gt;
&lt;br /&gt;
'''Examples:'''&lt;br /&gt;
* http://digg.com/&lt;br /&gt;
* http://slashdot.org/&lt;br /&gt;
&lt;br /&gt;
You should use '''PHP''' unless you get permission to use another web technology from the instructor.  You may also use phpMyAdmin to help set up databases.&lt;br /&gt;
&lt;br /&gt;
You may find this wiki article helpful: [[PHP and MySQL]]&lt;br /&gt;
&lt;br /&gt;
==== Requirements ====&lt;br /&gt;
&lt;br /&gt;
* Users can register for accounts and then log in to the website.&lt;br /&gt;
* Accounts should have both a username and a ''secure'' password.  '''NEVER store plaintext passwords in a database!'''&lt;br /&gt;
*: For more information on password security, refer to [[Web Application Security, Part 2#Password Security|the Web Application Security guide]].&lt;br /&gt;
*: You may use OpenID as a password system.  While not best practice, md5 is sufficient for points on the lab.  You may also design your own encryption system.&lt;br /&gt;
* Registered users can submit stories: either a link with summary or news text.&lt;br /&gt;
*: You do not have to make a distinction between the two types of stories, although if you want to, you could do something with this for the creative portion of your project.&lt;br /&gt;
* Registered users can comment on any story.&lt;br /&gt;
* Administrator users can delete stories and comments.&lt;br /&gt;
* Unregistered users can only view stories and comments.&lt;br /&gt;
* Registered users can edit their stories and can delete their comments.&lt;br /&gt;
* All data must be kept in a MySQL database (user information, stories, comments, and categories).&lt;br /&gt;
* As before, please check with a TA to see if your creative portion is okay or not before you proceed.&lt;br /&gt;
&lt;br /&gt;
=== Web Security and Validation ===&lt;br /&gt;
&lt;br /&gt;
Your project needs to demonstrate that thought was put into web security and best practice.  For more information, see this week's Web Application Security guide: [[Web Application Security, Part 2]]&lt;br /&gt;
&lt;br /&gt;
In particular:&lt;br /&gt;
&lt;br /&gt;
* '''Your application needs to be secure from SQL injection attacks'''. If you are using prepared queries, you should already be safe on this front.&lt;br /&gt;
* '''All of your output needs to be sanitized using htmlentities()'''.&lt;br /&gt;
&lt;br /&gt;
You shouldn't forget the practices you learned last week:&lt;br /&gt;
&lt;br /&gt;
* '''You should pass tokens in forms''' to prevent CSRF attacks.&lt;br /&gt;
* '''Your page should validate''' with no errors through the W3C validator.&lt;br /&gt;
&lt;br /&gt;
== Grading ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;font-size:2em; line-height:2em;&amp;quot;&amp;gt;'''Due Date: Wednesday October 10th, by 1pm (both individual and group)'''&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
!Assignment&lt;br /&gt;
!Points&lt;br /&gt;
|-&lt;br /&gt;
|Tables Correct&lt;br /&gt;
|2&lt;br /&gt;
|-&lt;br /&gt;
|Data Queries Correct&lt;br /&gt;
|2&lt;br /&gt;
|-&lt;br /&gt;
!colspan=&amp;quot;2&amp;quot;|Group Portion:&lt;br /&gt;
|-&lt;br /&gt;
|User Authentication&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|User Registration&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Password Encryption using a Salt&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Main page displays all stories (or most recent stories)&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Page with individual story and comments&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Story Submission&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Comment System&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Administrator Deletion of Stories/Comments&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|User Edit of Story (1 pt) and Comment (1 pt)&lt;br /&gt;
|2&lt;br /&gt;
|-&lt;br /&gt;
|Protect Against SQL Injection Attack&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Sanitize Output&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|CSRF Safe and Validation&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Creative Portion&lt;br /&gt;
|2&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Total Points = 18&lt;br /&gt;
[[Category:Module 3]]&lt;br /&gt;
[[Category:Modules]]&lt;/div&gt;</summary>
		<author><name>Marc</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=Module_3&amp;diff=697</id>
		<title>Module 3</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=Module_3&amp;diff=697"/>
		<updated>2012-09-25T01:44:42Z</updated>

		<summary type="html">&lt;p&gt;Marc: /* Grading */ total points&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In Module 3, you will learn about MySQL, a web application database.&lt;br /&gt;
&lt;br /&gt;
This article contains your assignments for Module 3.&lt;br /&gt;
&lt;br /&gt;
== Individual Assignments ==&lt;br /&gt;
&lt;br /&gt;
You will create a simple grades database containing four tables.&lt;br /&gt;
&lt;br /&gt;
'''IMPORTANT:''' The individual assignment is to be done by writing queries by hand.  (You can use phpMyAdmin to run the queries, but '''do not let phpMyAdmin write your queries for you!''')  Writing your own queries gives you a greater understanding of the underlying mechanisms and databases in general.  Additionally, having SQL knowledge and experience is a very marketable trait.&lt;br /&gt;
&lt;br /&gt;
=== Install MySQL and phpMyAdmin ===&lt;br /&gt;
&lt;br /&gt;
Before you start, '''you need to install MySQL''' on your EC2 instance.  You may also install phpMyAdmin, a web frontend to MySQL, if you choose to do so.&lt;br /&gt;
&lt;br /&gt;
You may find the following article to be very helpful: [[Introduction to MySQL]]&lt;br /&gt;
&lt;br /&gt;
=== Set Up a Database ===&lt;br /&gt;
&lt;br /&gt;
You may find the following article to be very helpful: [[Introduction to MySQL]]&lt;br /&gt;
&lt;br /&gt;
# Create a database named '''wustl''' &lt;br /&gt;
# Create a user named '''wustl_inst''' and give them the password '''wustl_pass'''&lt;br /&gt;
&lt;br /&gt;
=== Create Tables ===&lt;br /&gt;
&lt;br /&gt;
You may find the following article to be very helpful: [[MySQL Schema and State]]&lt;br /&gt;
&lt;br /&gt;
When creating tables, keep the following items in mind:&lt;br /&gt;
&lt;br /&gt;
* You should create all tables such that they use the InnoDB storage engine, since we wish to make use of its support of foreign keys. In other database engines, foreign key constraints are not enforced.  (If you mess up, you can use ALTER TABLE to change the storage engine.)&lt;br /&gt;
* Where it is appropriate, you should take advantage of the ability to define fields NOT NULL so that you do not inadvertently insert incomplete data for a row.&lt;br /&gt;
&lt;br /&gt;
Create the following tables:&lt;br /&gt;
&lt;br /&gt;
# Create a table named '''students''' with the following fields:&lt;br /&gt;
#* '''id''' of an appropriately-sized unsigned integer type (we will never need to process more than a million students)&lt;br /&gt;
#* '''first_name''' of type '''VARCHAR(50)'''&lt;br /&gt;
#* '''last_name''' of type '''VARCHAR(50)'''&lt;br /&gt;
#* '''email_address''' of type '''VARCHAR(50)'''&lt;br /&gt;
#: The primary key should be on the '''id''' field.&lt;br /&gt;
# Create a table named '''departments''' with the following fields:&lt;br /&gt;
#* '''school_code''' of type '''ENUM''' (e.g. &amp;quot;L&amp;quot; for ArtSci and &amp;quot;E&amp;quot; for Engineering).  The options are as follows:&lt;br /&gt;
#*: 'L', 'B', 'A', 'F', 'E', 'T', 'I', 'W', 'S', 'U', 'M'&lt;br /&gt;
#* '''dept_id''' of an appropriately-sized unsigned integer type (in the foreseeable future there will never be more than 200 departments in a school)&lt;br /&gt;
#* '''abbreviation''' of type '''VARCHAR(9)''' (e.g. CSE, ChemE, etc)&lt;br /&gt;
#* '''dept_name''' of type '''VARCHAR(200)''' (e.g. Computer Science and Engineering)&lt;br /&gt;
#: The primary key should be on two fields: '''school_code''' and '''dept_id'''&lt;br /&gt;
#: '''Note:''' Why not just use the department ID? The ID numbers are sometimes reused across schools. For instance, department 33 in The School of Arts and Sciences is Psychology while department 33 in The School of Engineering and Applied Sciences is Energy, Environmental and Chemical Engineering. Thus we must also include the school code to differentiate them  such that the record for  E33 is distinct from that of L33.&lt;br /&gt;
# Create a table named '''courses''' with the following fields:&lt;br /&gt;
#* '''school_code''' of type '''ENUM'''&lt;br /&gt;
#*: This should have the same letters in the same order as the '''school_code''' '''ENUM''' field in the '''departments''' table.&lt;br /&gt;
#* '''dept_id''' of the same size of integer as in the '''departments''' table&lt;br /&gt;
#* '''course_code''' of type '''CHAR(5)''' (this will hold course codes; e.g., '330S', '131', '2960')&lt;br /&gt;
#* '''name''' of type '''VARCHAR(150)'''&lt;br /&gt;
#: The appropriate fields in this table should make a foreign key reference to the corresponding fields in '''department'''.&lt;br /&gt;
#: In addition, it is up to you to determine the field(s) for the primary key.&lt;br /&gt;
#: '''Note:''' If you are unsure which fields to make the foreign keys and feel the need to beg your friends or the TAs to give you the answer, bang your head on your desk whilst repeating &amp;quot;I WILL EXERCISE REASON AND COMMON SENSE AND I WILL CURTAIL MY DESIRE TO BLINDLY FOLLOW DIRECTIONS&amp;quot;&lt;br /&gt;
#: ''Disclaimer: don't actually bang your head on your desk, the resulting head trauma may in fact make it harder for you to determine which fields should have associated foreign keys.''&lt;br /&gt;
# Create a table named '''grades''' with the following fields:&lt;br /&gt;
#* '''pk_grade_ID''' of an appropriately-sized unsigned integer type (should be larger than the one you chose for the '''students''' table)&lt;br /&gt;
#*: You should declare this field to be '''auto_increment''' and make it the primary key.&lt;br /&gt;
#*: This is called a ''surrogate key'' as opposed to a ''natural key'' because it doesn't arise &amp;quot;naturally&amp;quot; from the data; that is to say that it is not derived from application data. The use of surrogate keys vs. natural keys is a polemic issue amongst database designers.  For a decently unbiased take on the issue, see this page: http://www.agiledata.org/essays/keys.html#Comparison&lt;br /&gt;
#*: '''Food for thought:''' Aside from simply exposing you to the concept, can you think of any reasons why a surrogate key might be preferable for this table?  Alternatively, what attributes, if any, could you use as a natural key, and what might be the drawbacks of doing so?&lt;br /&gt;
#* '''student_id''' of the same integer (unsigned) type that you chose in the '''students''' table&lt;br /&gt;
#* '''grade''' of type '''decimal'''&lt;br /&gt;
#* '''school_code''' of type '''ENUM'''&lt;br /&gt;
#*: Can you guess what entries to use for the enum?&lt;br /&gt;
#* '''dept_id''' of the same integer type that you've used for this field in other tables&lt;br /&gt;
#* '''course_code''' of the same type you chose for the course code in the '''courses''' table&lt;br /&gt;
#: The '''grades''' table should have foreign keys to both the '''students''' table and the '''courses''' table.&lt;br /&gt;
&lt;br /&gt;
=== Populate Tables ===&lt;br /&gt;
&lt;br /&gt;
Now, populate the tables by downloading the text files given below and loading them into the appropriate tables.&lt;br /&gt;
&lt;br /&gt;
'''Note:''' Do not insert all the values manually; instead, use the MySQL's ability to load in data from text files.&lt;br /&gt;
&lt;br /&gt;
You may find the following article to be very helpful: [[MySQL Schema and State]]&lt;br /&gt;
&lt;br /&gt;
The files containing the data are:&lt;br /&gt;
&lt;br /&gt;
* students: https://docs.google.com/file/d/0ByHgvetJ0GJyMGFjMWI4MzAtMzljYy00Yjk3LTllMWItZjZkYmU1NzU3NWU0/edit&lt;br /&gt;
* courses: https://docs.google.com/file/d/0ByHgvetJ0GJyMGY1NGYzYmUtNGQwYi00MTY3LTkzMjgtMDYwOTM3NDNjZTg4/edit&lt;br /&gt;
* departments: https://docs.google.com/file/d/0ByHgvetJ0GJyZWY2OWE4ZWEtYzVmMC00YjBiLWEzZjgtYzdhMDczODAyNDli/edit&lt;br /&gt;
* grades: https://docs.google.com/file/d/0ByHgvetJ0GJyZmJjNzllNjAtMzdhZC00MzU5LTg3MDYtMTRmMjE5MDE2MzY2/edit&lt;br /&gt;
&lt;br /&gt;
=== Insert More Data ===&lt;br /&gt;
&lt;br /&gt;
Insert the following data into the tables that you have created and populated:&lt;br /&gt;
&lt;br /&gt;
# Insert an entry for CSE 330&lt;br /&gt;
#: ''If you don't know CSE's department code, how can you find out using the tables in the database?''&lt;br /&gt;
# Insert the grades given for the students named below.  You may choose to make the entries for whichever classes you like, with the one condition that all of the students must have a grade for CSE 330 (who wouldn't want to take that class: I hear the professor and TAs are amazing!)&lt;br /&gt;
#* '''Ben Harper'''&lt;br /&gt;
#** E-mail: '''bharper@ffym.com'''&lt;br /&gt;
#** Student ID: '''88'''&lt;br /&gt;
#** Grades:&lt;br /&gt;
#*** 5.5&lt;br /&gt;
#*** 0&lt;br /&gt;
#*** 20&lt;br /&gt;
#* '''Matt Freeman'''&lt;br /&gt;
#** E-mail: '''mfreeman@kickinbassist.net'''&lt;br /&gt;
#** Student ID: '''202'''&lt;br /&gt;
#** Grades:&lt;br /&gt;
#*** 100&lt;br /&gt;
#*** 90.5&lt;br /&gt;
#*** 94.8&lt;br /&gt;
#* '''Marc Roberge'''&lt;br /&gt;
#** E-mail: '''mroberge@ofarevolution.us'''&lt;br /&gt;
#** Student ID: '''115'''&lt;br /&gt;
#** Grades:&lt;br /&gt;
#*** 15&lt;br /&gt;
#*** 37&lt;br /&gt;
#*** 45.5&lt;br /&gt;
#: You may choose any 3 classes you'd like for them to be enrolled in, with at least one class, &amp;quot;CSE 330S&amp;quot;, in which they are all enrolled.&lt;br /&gt;
&lt;br /&gt;
=== Querying Your Database ===&lt;br /&gt;
&lt;br /&gt;
Now that you have a fully-functional, populated database, let's do some queries on it!&lt;br /&gt;
&lt;br /&gt;
Please take a screenshot of running the following '''select''' queries and show them to a TA (be sure to include your query command and the response:&lt;br /&gt;
&lt;br /&gt;
# Select the entire grades table.&lt;br /&gt;
# Select all fields describing the courses offered in the school of arts and sciences (school code L).&lt;br /&gt;
# The names, student IDs, and grades of the students who are in CSE330.&lt;br /&gt;
# The names and e-mails of any student with an average below 50 so that the dean can send them an email notification that they are now on academic probation.&lt;br /&gt;
#: ''You should be able to do this in only one query, without making any temporary tables.  You will need to use aggregation functions and the '''having''' keyword.''&lt;br /&gt;
# An individual report card for Jack Johnson, consisting of two tables (these can be done using separate queries):&lt;br /&gt;
## His student ID, e-mail address, and average grade.&lt;br /&gt;
##: ''Again, you should be able to do this in just one query, using the correct combination of aggregation functions and joins.''&lt;br /&gt;
## The classes he is in and his grades for those classes. To give you an idea, one row in the table should look like this:&lt;br /&gt;
##: &amp;lt;code&amp;gt;E	81	400	Independent Study	98.5&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Group Project ==&lt;br /&gt;
&lt;br /&gt;
You will work in pairs on this project.  You may work with the same partner from Module 2, or change to someone else.&lt;br /&gt;
&lt;br /&gt;
'''Important Reminder:''' frequently commit your work to your subversion repository as a backup!&lt;br /&gt;
&lt;br /&gt;
=== Simple News Web Site ===&lt;br /&gt;
&lt;br /&gt;
'''Examples:'''&lt;br /&gt;
* http://digg.com/&lt;br /&gt;
* http://slashdot.org/&lt;br /&gt;
&lt;br /&gt;
You should use '''PHP''' unless you get permission to use another web technology from the instructor.  You may also use phpMyAdmin to help set up databases.&lt;br /&gt;
&lt;br /&gt;
You may find this wiki article helpful: [[PHP and MySQL]]&lt;br /&gt;
&lt;br /&gt;
==== Requirements ====&lt;br /&gt;
&lt;br /&gt;
* Users can register for accounts and then log in to the website.&lt;br /&gt;
* Accounts should have both a username and a ''secure'' password.  '''NEVER store plaintext passwords in a database!'''&lt;br /&gt;
*: For more information on password security, refer to [[Web Application Security, Part 2#Password Security|the Web Application Security guide]].&lt;br /&gt;
*: You may use OpenID as a password system.  While not best practice, md5 is sufficient for points on the lab.  You may also design your own encryption system.&lt;br /&gt;
* Registered users can submit stories: either a link with summary or news text.&lt;br /&gt;
*: You do not have to make a distinction between the two types of stories, although if you want to, you could do something with this for the creative portion of your project.&lt;br /&gt;
* Registered users can comment on any story.&lt;br /&gt;
* Administrator users can delete stories and comments.&lt;br /&gt;
* Unregistered users can only view stories and comments.&lt;br /&gt;
* Registered users can edit their stories and can delete their comments.&lt;br /&gt;
* All data must be kept in a MySQL database (user information, stories, comments, and categories).&lt;br /&gt;
* As before, please check with a TA to see if your creative portion is okay or not before you proceed.&lt;br /&gt;
&lt;br /&gt;
=== Web Security and Validation ===&lt;br /&gt;
&lt;br /&gt;
Your project needs to demonstrate that thought was put into web security and best practice.  For more information, see this week's Web Application Security guide: [[Web Application Security, Part 2]]&lt;br /&gt;
&lt;br /&gt;
In particular:&lt;br /&gt;
&lt;br /&gt;
* '''Your application needs to be secure from SQL injection attacks'''. If you are using prepared queries, you should already be safe on this front.&lt;br /&gt;
* '''All of your output needs to be sanitized using htmlentities()'''.&lt;br /&gt;
&lt;br /&gt;
You shouldn't forget the practices you learned last week:&lt;br /&gt;
&lt;br /&gt;
* '''You should pass tokens in forms''' to prevent CSRF attacks.&lt;br /&gt;
* '''Your page should validate''' with no errors through the W3C validator.&lt;br /&gt;
&lt;br /&gt;
== Grading ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;font-size:2em; line-height:2em;&amp;quot;&amp;gt;'''Due Date: Wednesday October 10th, by 1pm (both individual and group)'''&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
!Assignment&lt;br /&gt;
!Points&lt;br /&gt;
|-&lt;br /&gt;
|Tables Correct&lt;br /&gt;
|2&lt;br /&gt;
|-&lt;br /&gt;
|Data Queries Correct&lt;br /&gt;
|2&lt;br /&gt;
|-&lt;br /&gt;
!colspan=&amp;quot;2&amp;quot;|Group Portion:&lt;br /&gt;
|-&lt;br /&gt;
|User Authentication&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|User Registration&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Password Encryption using a Salt&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Main page displays all stories (or most recent stories)&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Page with individual story and comments&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Story Submission&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Comment System&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Administrator Deletion of Stories/Comments&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|User Edit of Story (1 pt) and Comment (1 pt)&lt;br /&gt;
|2&lt;br /&gt;
|-&lt;br /&gt;
|Protect Against SQL Injection Attack&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Sanitize Output&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|CSRF Safe and Validation&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Creative Portion&lt;br /&gt;
|2&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Total Points = 18&lt;br /&gt;
[[Category:Module 3]]&lt;br /&gt;
[[Category:Modules]]&lt;/div&gt;</summary>
		<author><name>Marc</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=Module_3&amp;diff=696</id>
		<title>Module 3</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=Module_3&amp;diff=696"/>
		<updated>2012-09-25T01:43:37Z</updated>

		<summary type="html">&lt;p&gt;Marc: /* Requirements */ FINAL CHANGE on encryption requirement&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In Module 3, you will learn about MySQL, a web application database.&lt;br /&gt;
&lt;br /&gt;
This article contains your assignments for Module 3.&lt;br /&gt;
&lt;br /&gt;
== Individual Assignments ==&lt;br /&gt;
&lt;br /&gt;
You will create a simple grades database containing four tables.&lt;br /&gt;
&lt;br /&gt;
'''IMPORTANT:''' The individual assignment is to be done by writing queries by hand.  (You can use phpMyAdmin to run the queries, but '''do not let phpMyAdmin write your queries for you!''')  Writing your own queries gives you a greater understanding of the underlying mechanisms and databases in general.  Additionally, having SQL knowledge and experience is a very marketable trait.&lt;br /&gt;
&lt;br /&gt;
=== Install MySQL and phpMyAdmin ===&lt;br /&gt;
&lt;br /&gt;
Before you start, '''you need to install MySQL''' on your EC2 instance.  You may also install phpMyAdmin, a web frontend to MySQL, if you choose to do so.&lt;br /&gt;
&lt;br /&gt;
You may find the following article to be very helpful: [[Introduction to MySQL]]&lt;br /&gt;
&lt;br /&gt;
=== Set Up a Database ===&lt;br /&gt;
&lt;br /&gt;
You may find the following article to be very helpful: [[Introduction to MySQL]]&lt;br /&gt;
&lt;br /&gt;
# Create a database named '''wustl''' &lt;br /&gt;
# Create a user named '''wustl_inst''' and give them the password '''wustl_pass'''&lt;br /&gt;
&lt;br /&gt;
=== Create Tables ===&lt;br /&gt;
&lt;br /&gt;
You may find the following article to be very helpful: [[MySQL Schema and State]]&lt;br /&gt;
&lt;br /&gt;
When creating tables, keep the following items in mind:&lt;br /&gt;
&lt;br /&gt;
* You should create all tables such that they use the InnoDB storage engine, since we wish to make use of its support of foreign keys. In other database engines, foreign key constraints are not enforced.  (If you mess up, you can use ALTER TABLE to change the storage engine.)&lt;br /&gt;
* Where it is appropriate, you should take advantage of the ability to define fields NOT NULL so that you do not inadvertently insert incomplete data for a row.&lt;br /&gt;
&lt;br /&gt;
Create the following tables:&lt;br /&gt;
&lt;br /&gt;
# Create a table named '''students''' with the following fields:&lt;br /&gt;
#* '''id''' of an appropriately-sized unsigned integer type (we will never need to process more than a million students)&lt;br /&gt;
#* '''first_name''' of type '''VARCHAR(50)'''&lt;br /&gt;
#* '''last_name''' of type '''VARCHAR(50)'''&lt;br /&gt;
#* '''email_address''' of type '''VARCHAR(50)'''&lt;br /&gt;
#: The primary key should be on the '''id''' field.&lt;br /&gt;
# Create a table named '''departments''' with the following fields:&lt;br /&gt;
#* '''school_code''' of type '''ENUM''' (e.g. &amp;quot;L&amp;quot; for ArtSci and &amp;quot;E&amp;quot; for Engineering).  The options are as follows:&lt;br /&gt;
#*: 'L', 'B', 'A', 'F', 'E', 'T', 'I', 'W', 'S', 'U', 'M'&lt;br /&gt;
#* '''dept_id''' of an appropriately-sized unsigned integer type (in the foreseeable future there will never be more than 200 departments in a school)&lt;br /&gt;
#* '''abbreviation''' of type '''VARCHAR(9)''' (e.g. CSE, ChemE, etc)&lt;br /&gt;
#* '''dept_name''' of type '''VARCHAR(200)''' (e.g. Computer Science and Engineering)&lt;br /&gt;
#: The primary key should be on two fields: '''school_code''' and '''dept_id'''&lt;br /&gt;
#: '''Note:''' Why not just use the department ID? The ID numbers are sometimes reused across schools. For instance, department 33 in The School of Arts and Sciences is Psychology while department 33 in The School of Engineering and Applied Sciences is Energy, Environmental and Chemical Engineering. Thus we must also include the school code to differentiate them  such that the record for  E33 is distinct from that of L33.&lt;br /&gt;
# Create a table named '''courses''' with the following fields:&lt;br /&gt;
#* '''school_code''' of type '''ENUM'''&lt;br /&gt;
#*: This should have the same letters in the same order as the '''school_code''' '''ENUM''' field in the '''departments''' table.&lt;br /&gt;
#* '''dept_id''' of the same size of integer as in the '''departments''' table&lt;br /&gt;
#* '''course_code''' of type '''CHAR(5)''' (this will hold course codes; e.g., '330S', '131', '2960')&lt;br /&gt;
#* '''name''' of type '''VARCHAR(150)'''&lt;br /&gt;
#: The appropriate fields in this table should make a foreign key reference to the corresponding fields in '''department'''.&lt;br /&gt;
#: In addition, it is up to you to determine the field(s) for the primary key.&lt;br /&gt;
#: '''Note:''' If you are unsure which fields to make the foreign keys and feel the need to beg your friends or the TAs to give you the answer, bang your head on your desk whilst repeating &amp;quot;I WILL EXERCISE REASON AND COMMON SENSE AND I WILL CURTAIL MY DESIRE TO BLINDLY FOLLOW DIRECTIONS&amp;quot;&lt;br /&gt;
#: ''Disclaimer: don't actually bang your head on your desk, the resulting head trauma may in fact make it harder for you to determine which fields should have associated foreign keys.''&lt;br /&gt;
# Create a table named '''grades''' with the following fields:&lt;br /&gt;
#* '''pk_grade_ID''' of an appropriately-sized unsigned integer type (should be larger than the one you chose for the '''students''' table)&lt;br /&gt;
#*: You should declare this field to be '''auto_increment''' and make it the primary key.&lt;br /&gt;
#*: This is called a ''surrogate key'' as opposed to a ''natural key'' because it doesn't arise &amp;quot;naturally&amp;quot; from the data; that is to say that it is not derived from application data. The use of surrogate keys vs. natural keys is a polemic issue amongst database designers.  For a decently unbiased take on the issue, see this page: http://www.agiledata.org/essays/keys.html#Comparison&lt;br /&gt;
#*: '''Food for thought:''' Aside from simply exposing you to the concept, can you think of any reasons why a surrogate key might be preferable for this table?  Alternatively, what attributes, if any, could you use as a natural key, and what might be the drawbacks of doing so?&lt;br /&gt;
#* '''student_id''' of the same integer (unsigned) type that you chose in the '''students''' table&lt;br /&gt;
#* '''grade''' of type '''decimal'''&lt;br /&gt;
#* '''school_code''' of type '''ENUM'''&lt;br /&gt;
#*: Can you guess what entries to use for the enum?&lt;br /&gt;
#* '''dept_id''' of the same integer type that you've used for this field in other tables&lt;br /&gt;
#* '''course_code''' of the same type you chose for the course code in the '''courses''' table&lt;br /&gt;
#: The '''grades''' table should have foreign keys to both the '''students''' table and the '''courses''' table.&lt;br /&gt;
&lt;br /&gt;
=== Populate Tables ===&lt;br /&gt;
&lt;br /&gt;
Now, populate the tables by downloading the text files given below and loading them into the appropriate tables.&lt;br /&gt;
&lt;br /&gt;
'''Note:''' Do not insert all the values manually; instead, use the MySQL's ability to load in data from text files.&lt;br /&gt;
&lt;br /&gt;
You may find the following article to be very helpful: [[MySQL Schema and State]]&lt;br /&gt;
&lt;br /&gt;
The files containing the data are:&lt;br /&gt;
&lt;br /&gt;
* students: https://docs.google.com/file/d/0ByHgvetJ0GJyMGFjMWI4MzAtMzljYy00Yjk3LTllMWItZjZkYmU1NzU3NWU0/edit&lt;br /&gt;
* courses: https://docs.google.com/file/d/0ByHgvetJ0GJyMGY1NGYzYmUtNGQwYi00MTY3LTkzMjgtMDYwOTM3NDNjZTg4/edit&lt;br /&gt;
* departments: https://docs.google.com/file/d/0ByHgvetJ0GJyZWY2OWE4ZWEtYzVmMC00YjBiLWEzZjgtYzdhMDczODAyNDli/edit&lt;br /&gt;
* grades: https://docs.google.com/file/d/0ByHgvetJ0GJyZmJjNzllNjAtMzdhZC00MzU5LTg3MDYtMTRmMjE5MDE2MzY2/edit&lt;br /&gt;
&lt;br /&gt;
=== Insert More Data ===&lt;br /&gt;
&lt;br /&gt;
Insert the following data into the tables that you have created and populated:&lt;br /&gt;
&lt;br /&gt;
# Insert an entry for CSE 330&lt;br /&gt;
#: ''If you don't know CSE's department code, how can you find out using the tables in the database?''&lt;br /&gt;
# Insert the grades given for the students named below.  You may choose to make the entries for whichever classes you like, with the one condition that all of the students must have a grade for CSE 330 (who wouldn't want to take that class: I hear the professor and TAs are amazing!)&lt;br /&gt;
#* '''Ben Harper'''&lt;br /&gt;
#** E-mail: '''bharper@ffym.com'''&lt;br /&gt;
#** Student ID: '''88'''&lt;br /&gt;
#** Grades:&lt;br /&gt;
#*** 5.5&lt;br /&gt;
#*** 0&lt;br /&gt;
#*** 20&lt;br /&gt;
#* '''Matt Freeman'''&lt;br /&gt;
#** E-mail: '''mfreeman@kickinbassist.net'''&lt;br /&gt;
#** Student ID: '''202'''&lt;br /&gt;
#** Grades:&lt;br /&gt;
#*** 100&lt;br /&gt;
#*** 90.5&lt;br /&gt;
#*** 94.8&lt;br /&gt;
#* '''Marc Roberge'''&lt;br /&gt;
#** E-mail: '''mroberge@ofarevolution.us'''&lt;br /&gt;
#** Student ID: '''115'''&lt;br /&gt;
#** Grades:&lt;br /&gt;
#*** 15&lt;br /&gt;
#*** 37&lt;br /&gt;
#*** 45.5&lt;br /&gt;
#: You may choose any 3 classes you'd like for them to be enrolled in, with at least one class, &amp;quot;CSE 330S&amp;quot;, in which they are all enrolled.&lt;br /&gt;
&lt;br /&gt;
=== Querying Your Database ===&lt;br /&gt;
&lt;br /&gt;
Now that you have a fully-functional, populated database, let's do some queries on it!&lt;br /&gt;
&lt;br /&gt;
Please take a screenshot of running the following '''select''' queries and show them to a TA (be sure to include your query command and the response:&lt;br /&gt;
&lt;br /&gt;
# Select the entire grades table.&lt;br /&gt;
# Select all fields describing the courses offered in the school of arts and sciences (school code L).&lt;br /&gt;
# The names, student IDs, and grades of the students who are in CSE330.&lt;br /&gt;
# The names and e-mails of any student with an average below 50 so that the dean can send them an email notification that they are now on academic probation.&lt;br /&gt;
#: ''You should be able to do this in only one query, without making any temporary tables.  You will need to use aggregation functions and the '''having''' keyword.''&lt;br /&gt;
# An individual report card for Jack Johnson, consisting of two tables (these can be done using separate queries):&lt;br /&gt;
## His student ID, e-mail address, and average grade.&lt;br /&gt;
##: ''Again, you should be able to do this in just one query, using the correct combination of aggregation functions and joins.''&lt;br /&gt;
## The classes he is in and his grades for those classes. To give you an idea, one row in the table should look like this:&lt;br /&gt;
##: &amp;lt;code&amp;gt;E	81	400	Independent Study	98.5&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Group Project ==&lt;br /&gt;
&lt;br /&gt;
You will work in pairs on this project.  You may work with the same partner from Module 2, or change to someone else.&lt;br /&gt;
&lt;br /&gt;
'''Important Reminder:''' frequently commit your work to your subversion repository as a backup!&lt;br /&gt;
&lt;br /&gt;
=== Simple News Web Site ===&lt;br /&gt;
&lt;br /&gt;
'''Examples:'''&lt;br /&gt;
* http://digg.com/&lt;br /&gt;
* http://slashdot.org/&lt;br /&gt;
&lt;br /&gt;
You should use '''PHP''' unless you get permission to use another web technology from the instructor.  You may also use phpMyAdmin to help set up databases.&lt;br /&gt;
&lt;br /&gt;
You may find this wiki article helpful: [[PHP and MySQL]]&lt;br /&gt;
&lt;br /&gt;
==== Requirements ====&lt;br /&gt;
&lt;br /&gt;
* Users can register for accounts and then log in to the website.&lt;br /&gt;
* Accounts should have both a username and a ''secure'' password.  '''NEVER store plaintext passwords in a database!'''&lt;br /&gt;
*: For more information on password security, refer to [[Web Application Security, Part 2#Password Security|the Web Application Security guide]].&lt;br /&gt;
*: You may use OpenID as a password system.  While not best practice, md5 is sufficient for points on the lab.  You may also design your own encryption system.&lt;br /&gt;
* Registered users can submit stories: either a link with summary or news text.&lt;br /&gt;
*: You do not have to make a distinction between the two types of stories, although if you want to, you could do something with this for the creative portion of your project.&lt;br /&gt;
* Registered users can comment on any story.&lt;br /&gt;
* Administrator users can delete stories and comments.&lt;br /&gt;
* Unregistered users can only view stories and comments.&lt;br /&gt;
* Registered users can edit their stories and can delete their comments.&lt;br /&gt;
* All data must be kept in a MySQL database (user information, stories, comments, and categories).&lt;br /&gt;
* As before, please check with a TA to see if your creative portion is okay or not before you proceed.&lt;br /&gt;
&lt;br /&gt;
=== Web Security and Validation ===&lt;br /&gt;
&lt;br /&gt;
Your project needs to demonstrate that thought was put into web security and best practice.  For more information, see this week's Web Application Security guide: [[Web Application Security, Part 2]]&lt;br /&gt;
&lt;br /&gt;
In particular:&lt;br /&gt;
&lt;br /&gt;
* '''Your application needs to be secure from SQL injection attacks'''. If you are using prepared queries, you should already be safe on this front.&lt;br /&gt;
* '''All of your output needs to be sanitized using htmlentities()'''.&lt;br /&gt;
&lt;br /&gt;
You shouldn't forget the practices you learned last week:&lt;br /&gt;
&lt;br /&gt;
* '''You should pass tokens in forms''' to prevent CSRF attacks.&lt;br /&gt;
* '''Your page should validate''' with no errors through the W3C validator.&lt;br /&gt;
&lt;br /&gt;
== Grading ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;font-size:2em; line-height:2em;&amp;quot;&amp;gt;'''Due Date: Wednesday October 10th, by 1pm (both individual and group)'''&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
!Assignment&lt;br /&gt;
!Points&lt;br /&gt;
|-&lt;br /&gt;
|Tables Correct&lt;br /&gt;
|2&lt;br /&gt;
|-&lt;br /&gt;
|Data Queries Correct&lt;br /&gt;
|2&lt;br /&gt;
|-&lt;br /&gt;
!colspan=&amp;quot;2&amp;quot;|Group Portion:&lt;br /&gt;
|-&lt;br /&gt;
|User Authentication&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|User Registration&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Password Encryption using a Salt&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Main page displays all stories (or most recent stories)&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Page with individual story and comments&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Story Submission&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Comment System&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Administrator Deletion of Stories/Comments&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|User Edit of Story (1 pt) and Comment (1 pt)&lt;br /&gt;
|2&lt;br /&gt;
|-&lt;br /&gt;
|Protect Against SQL Injection Attack&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Sanitize Output&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|CSRF Safe and Validation&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Creative Portion&lt;br /&gt;
|2&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
[[Category:Module 3]]&lt;br /&gt;
[[Category:Modules]]&lt;/div&gt;</summary>
		<author><name>Marc</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=Module_3&amp;diff=683</id>
		<title>Module 3</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=Module_3&amp;diff=683"/>
		<updated>2012-09-21T15:37:11Z</updated>

		<summary type="html">&lt;p&gt;Marc: /* Grading */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In Module 3, you will learn about MySQL, a web application database.&lt;br /&gt;
&lt;br /&gt;
This article contains your assignments for Module 3.&lt;br /&gt;
&lt;br /&gt;
== Individual Assignments ==&lt;br /&gt;
&lt;br /&gt;
You will create a simple grades database containing four tables.&lt;br /&gt;
&lt;br /&gt;
'''IMPORTANT:''' The individual assignment is to be done by writing queries by hand.  (You can use phpMyAdmin to run the queries, but '''do not let phpMyAdmin write your queries for you!''')  Writing your own queries gives you a greater understanding of the underlying mechanisms and databases in general.  Additionally, having SQL knowledge and experience is a very marketable trait.&lt;br /&gt;
&lt;br /&gt;
=== Install MySQL and phpMyAdmin ===&lt;br /&gt;
&lt;br /&gt;
Before you start, '''you need to install MySQL''' on your EC2 instance.  You may also install phpMyAdmin, a web frontend to MySQL, if you choose to do so.&lt;br /&gt;
&lt;br /&gt;
You may find the following article to be very helpful: [[Introduction to MySQL]]&lt;br /&gt;
&lt;br /&gt;
=== Set Up a Database ===&lt;br /&gt;
&lt;br /&gt;
You may find the following article to be very helpful: [[Introduction to MySQL]]&lt;br /&gt;
&lt;br /&gt;
# Create a database named '''wustl''' &lt;br /&gt;
# Create a user named '''wustl_inst''' and give them the password '''wustl_pass'''&lt;br /&gt;
&lt;br /&gt;
=== Create Tables ===&lt;br /&gt;
&lt;br /&gt;
You may find the following article to be very helpful: [[MySQL Schema and State]]&lt;br /&gt;
&lt;br /&gt;
When creating tables, keep the following items in mind:&lt;br /&gt;
&lt;br /&gt;
* You should create all tables such that they use the InnoDB storage engine, since we wish to make use of its support of foreign keys. In other database engines, foreign key constraints are not enforced.  (If you mess up, you can use ALTER TABLE to change the storage engine.)&lt;br /&gt;
* Where it is appropriate, you should take advantage of the ability to define fields NOT NULL so that you do not inadvertently insert incomplete data for a row.&lt;br /&gt;
&lt;br /&gt;
Create the following tables:&lt;br /&gt;
&lt;br /&gt;
# Create a table named '''students''' with the following fields:&lt;br /&gt;
#* '''id''' of an appropriately-sized unsigned integer type (we will never need to process more than a million students)&lt;br /&gt;
#* '''first_name''' of type '''VARCHAR(50)'''&lt;br /&gt;
#* '''last_name''' of type '''VARCHAR(50)'''&lt;br /&gt;
#* '''email_address''' of type '''VARCHAR(50)'''&lt;br /&gt;
#: The primary key should be on the '''id''' field.&lt;br /&gt;
# Create a table named '''departments''' with the following fields:&lt;br /&gt;
#* '''school_code''' of type '''ENUM''' (e.g. &amp;quot;L&amp;quot; for ArtSci and &amp;quot;E&amp;quot; for Engineering).  The options are as follows:&lt;br /&gt;
#*: 'L', 'B', 'A', 'F', 'E', 'T', 'I', 'W', 'S', 'U', 'M'&lt;br /&gt;
#* '''dept_id''' of an appropriately-sized unsigned integer type (in the foreseeable future there will never be more than 200 departments in a school)&lt;br /&gt;
#* '''abbreviation''' of type '''VARCHAR(9)''' (e.g. CSE, ChemE, etc)&lt;br /&gt;
#* '''dept_name''' of type '''VARCHAR(200)''' (e.g. Computer Science and Engineering)&lt;br /&gt;
#: The primary key should be on two fields: '''school_code''' and '''dept_id'''&lt;br /&gt;
#: '''Note:''' Why not just use the department ID? The ID numbers are sometimes reused across schools. For instance, department 33 in The School of Arts and Sciences is Psychology while department 33 in The School of Engineering and Applied Sciences is Energy, Environmental and Chemical Engineering. Thus we must also include the school code to differentiate them  such that the record for  E33 is distinct from that of L33.&lt;br /&gt;
# Create a table named '''courses''' with the following fields:&lt;br /&gt;
#* '''school_code''' of type '''ENUM'''&lt;br /&gt;
#*: This should have the same letters in the same order as the '''school_code''' '''ENUM''' field in the '''departments''' table.&lt;br /&gt;
#* '''dept_id''' of the same size of integer as in the '''departments''' table&lt;br /&gt;
#* '''course_code''' of type '''CHAR(5)''' (this will hold course codes; e.g., '330S', '131', '2960')&lt;br /&gt;
#* '''name''' of type '''VARCHAR(150)'''&lt;br /&gt;
#: The appropriate fields in this table should make a foreign key reference to the corresponding fields in '''department'''.&lt;br /&gt;
#: In addition, it is up to you to determine the field(s) for the primary key.&lt;br /&gt;
#: '''Note:''' If you are unsure which fields to make the foreign keys and feel the need to beg your friends or the TAs to give you the answer, bang your head on your desk whilst repeating &amp;quot;I WILL EXERCISE REASON AND COMMON SENSE AND I WILL CURTAIL MY DESIRE TO BLINDLY FOLLOW DIRECTIONS&amp;quot;&lt;br /&gt;
#: ''Disclaimer: don't actually bang your head on your desk, the resulting head trauma may in fact make it harder for you to determine which fields should have associated foreign keys.''&lt;br /&gt;
# Create a table named '''grades''' with the following fields:&lt;br /&gt;
#* '''pk_grade_ID''' of an appropriately-sized unsigned integer type (should be larger than the one you chose for the '''students''' table)&lt;br /&gt;
#*: You should declare this field to be '''auto_increment''' and make it the primary key.&lt;br /&gt;
#*: This is called a ''surrogate key'' as opposed to a ''natural key'' because it doesn't arise &amp;quot;naturally&amp;quot; from the data; that is to say that it is not derived from application data. The use of surrogate keys vs. natural keys is a polemic issue amongst database designers.  For a decently unbiased take on the issue, see this page: http://www.agiledata.org/essays/keys.html#Comparison&lt;br /&gt;
#*: '''Food for thought:''' Aside from simply exposing you to the concept, can you think of any reasons why a surrogate key might be preferable for this table?  Alternatively, what attributes, if any, could you use as a natural key, and what might be the drawbacks of doing so?&lt;br /&gt;
#* '''student_id''' of the same integer (unsigned) type that you chose in the '''students''' table&lt;br /&gt;
#* '''grade''' of type '''decimal'''&lt;br /&gt;
#* '''school_code''' of type '''ENUM'''&lt;br /&gt;
#*: Can you guess what entries to use for the enum?&lt;br /&gt;
#* '''dept_id''' of the same integer type that you've used for this field in other tables&lt;br /&gt;
#* '''course_code''' of the same type you chose for the course code in the '''courses''' table&lt;br /&gt;
#: The '''grades''' table should have foreign keys to both the '''students''' table and the '''courses''' table.&lt;br /&gt;
&lt;br /&gt;
=== Populate Tables ===&lt;br /&gt;
&lt;br /&gt;
Now, populate the tables by downloading the text files given below and loading them into the appropriate tables.&lt;br /&gt;
&lt;br /&gt;
'''Note:''' Do not insert all the values manually; instead, use the MySQL's ability to load in data from text files.&lt;br /&gt;
&lt;br /&gt;
You may find the following article to be very helpful: [[MySQL Schema and State]]&lt;br /&gt;
&lt;br /&gt;
The files containing the data are:&lt;br /&gt;
&lt;br /&gt;
* students: https://docs.google.com/file/d/0ByHgvetJ0GJyMGFjMWI4MzAtMzljYy00Yjk3LTllMWItZjZkYmU1NzU3NWU0/edit&lt;br /&gt;
* courses: https://docs.google.com/file/d/0ByHgvetJ0GJyMGY1NGYzYmUtNGQwYi00MTY3LTkzMjgtMDYwOTM3NDNjZTg4/edit&lt;br /&gt;
* departments: https://docs.google.com/file/d/0ByHgvetJ0GJyZWY2OWE4ZWEtYzVmMC00YjBiLWEzZjgtYzdhMDczODAyNDli/edit&lt;br /&gt;
* grades: https://docs.google.com/file/d/0ByHgvetJ0GJyZmJjNzllNjAtMzdhZC00MzU5LTg3MDYtMTRmMjE5MDE2MzY2/edit&lt;br /&gt;
&lt;br /&gt;
=== Insert More Data ===&lt;br /&gt;
&lt;br /&gt;
Insert the following data into the tables that you have created and populated:&lt;br /&gt;
&lt;br /&gt;
# Insert an entry for CSE 330&lt;br /&gt;
#: ''If you don't know CSE's department code, how can you find out using the tables in the database?''&lt;br /&gt;
# Insert the grades given for the students named below.  You may choose to make the entries for whichever classes you like, with the one condition that all of the students must have a grade for CSE 330 (who wouldn't want to take that class: I hear the professor and TAs are amazing!)&lt;br /&gt;
#* '''Ben Harper'''&lt;br /&gt;
#** E-mail: '''bharper@ffym.com'''&lt;br /&gt;
#** Student ID: '''88'''&lt;br /&gt;
#** Grades:&lt;br /&gt;
#*** 5.5&lt;br /&gt;
#*** 0&lt;br /&gt;
#*** 20&lt;br /&gt;
#* '''Matt Freeman'''&lt;br /&gt;
#** E-mail: '''mfreeman@kickinbassist.net'''&lt;br /&gt;
#** Student ID: '''202'''&lt;br /&gt;
#** Grades:&lt;br /&gt;
#*** 100&lt;br /&gt;
#*** 90.5&lt;br /&gt;
#*** 94.8&lt;br /&gt;
#* '''Marc Roberge'''&lt;br /&gt;
#** E-mail: '''mroberge@ofarevolution.us'''&lt;br /&gt;
#** Student ID: '''115'''&lt;br /&gt;
#** Grades:&lt;br /&gt;
#*** 15&lt;br /&gt;
#*** 37&lt;br /&gt;
#*** 45.5&lt;br /&gt;
#: You may choose any 3 classes you'd like for them to be enrolled in, with at least one class, &amp;quot;CSE 330S&amp;quot;, in which they are all enrolled.&lt;br /&gt;
&lt;br /&gt;
=== Querying Your Database ===&lt;br /&gt;
&lt;br /&gt;
Now that you have a fully-functional, populated database, let's do some queries on it!&lt;br /&gt;
&lt;br /&gt;
Please take a screenshot of running the following '''select''' queries and show them to a TA (be sure to include your query command and the response:&lt;br /&gt;
&lt;br /&gt;
# Select the entire grades table.&lt;br /&gt;
# Select all fields describing the courses offered in the school of arts and sciences (school code L).&lt;br /&gt;
# The names, student IDs, and grades of the students who are in CSE330.&lt;br /&gt;
# The names and e-mails of any student with an average below 50 so that the dean can send them an email notification that they are now on academic probation.&lt;br /&gt;
#: ''You should be able to do this in only one query, without making any temporary tables.  You will need to use aggregation functions and the '''having''' keyword.''&lt;br /&gt;
# An individual report card for Jack Johnson, consisting of two tables (these can be done using separate queries):&lt;br /&gt;
## His student ID, e-mail address, and average grade.&lt;br /&gt;
##: ''Again, you should be able to do this in just one query, using the correct combination of aggregation functions and joins.''&lt;br /&gt;
## The classes he is in and his grades for those classes. To give you an idea, one row in the table should look like this:&lt;br /&gt;
##: &amp;lt;code&amp;gt;E	81	400	Independent Study	98.5&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Group Project ==&lt;br /&gt;
&lt;br /&gt;
You will work in pairs on this project.  You may work with the same partner from Module 2, or change to someone else.&lt;br /&gt;
&lt;br /&gt;
'''Important Reminder:''' frequently commit your work to your subversion repository as a backup!&lt;br /&gt;
&lt;br /&gt;
=== Simple News Web Site ===&lt;br /&gt;
&lt;br /&gt;
'''Examples:'''&lt;br /&gt;
* http://digg.com/&lt;br /&gt;
* http://slashdot.org/&lt;br /&gt;
&lt;br /&gt;
You should use '''PHP''' unless you get permission to use another web technology from the instructor.  You may also use phpMyAdmin to help set up databases.&lt;br /&gt;
&lt;br /&gt;
You may find this wiki article helpful: [[PHP and MySQL]]&lt;br /&gt;
&lt;br /&gt;
==== Requirements ====&lt;br /&gt;
&lt;br /&gt;
* Users can register for accounts and then log in to the website.&lt;br /&gt;
* Accounts should have both a username and a ''secure'' password.  '''NEVER store plaintext passwords in a database!'''&lt;br /&gt;
*: For more information on password security, refer to [[Web Application Security, Part 2#Password Security|the Web Application Security guide]].&lt;br /&gt;
*: You may also want to refer to http://php.net/manual/en/function.md5.php for information on md5.  &lt;br /&gt;
* Registered users can submit stories: either a link with summary or news text.&lt;br /&gt;
*: You do not have to make a distinction between the two types of stories, although if you want to, you could do something with this for the creative portion of your project.&lt;br /&gt;
* Registered users can comment on any story.&lt;br /&gt;
* Administrator users can delete stories and comments.&lt;br /&gt;
* Unregistered users can only view stories and comments.&lt;br /&gt;
* Registered users can edit their stories and can delete their comments.&lt;br /&gt;
* All data must be kept in a MySQL database (user information, stories, comments, and categories).&lt;br /&gt;
* As before, please check with a TA to see if your creative portion is okay or not before you proceed.&lt;br /&gt;
&lt;br /&gt;
=== Web Security and Validation ===&lt;br /&gt;
&lt;br /&gt;
Your project needs to demonstrate that thought was put into web security and best practice.  For more information, see this week's Web Application Security guide: [[Web Application Security, Part 2]]&lt;br /&gt;
&lt;br /&gt;
In particular:&lt;br /&gt;
&lt;br /&gt;
* '''Your application needs to be secure from SQL injection attacks'''. If you are using prepared queries, you should already be safe on this front.&lt;br /&gt;
* '''All of your output needs to be sanitized using htmlentities()'''.&lt;br /&gt;
&lt;br /&gt;
You shouldn't forget the practices you learned last week:&lt;br /&gt;
&lt;br /&gt;
* '''You should pass tokens in forms''' to prevent CSRF attacks.&lt;br /&gt;
* '''Your page should validate''' with no errors through the W3C validator.&lt;br /&gt;
&lt;br /&gt;
== Grading ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;font-size:2em; line-height:2em;&amp;quot;&amp;gt;'''Due Date: Wednesday October 10th, by 1pm (both individual and group)'''&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
!Assignment&lt;br /&gt;
!Points&lt;br /&gt;
|-&lt;br /&gt;
|Tables Correct&lt;br /&gt;
|2&lt;br /&gt;
|-&lt;br /&gt;
|Data Queries Correct&lt;br /&gt;
|2&lt;br /&gt;
|-&lt;br /&gt;
!colspan=&amp;quot;2&amp;quot;|Group Portion:&lt;br /&gt;
|-&lt;br /&gt;
|User Authentication&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|User Registration&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Secure Password&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Main page displays all stories (or most recent stories)&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Page with individual story and comments&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Story Submission&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Comment System&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Administrator Deletion of Stories/Comments&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|User Edit of Story/Comment&lt;br /&gt;
|2&lt;br /&gt;
|-&lt;br /&gt;
|Protect Against SQL Injection Attack&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Sanitize Output&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Web Security Practices and Validation (See module 2)&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Creative Portion&lt;br /&gt;
|2&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
[[Category:Module 3]]&lt;br /&gt;
[[Category:Modules]]&lt;/div&gt;</summary>
		<author><name>Marc</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=Module_3&amp;diff=682</id>
		<title>Module 3</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=Module_3&amp;diff=682"/>
		<updated>2012-09-21T15:35:56Z</updated>

		<summary type="html">&lt;p&gt;Marc: /* Querying Your Database */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In Module 3, you will learn about MySQL, a web application database.&lt;br /&gt;
&lt;br /&gt;
This article contains your assignments for Module 3.&lt;br /&gt;
&lt;br /&gt;
== Individual Assignments ==&lt;br /&gt;
&lt;br /&gt;
You will create a simple grades database containing four tables.&lt;br /&gt;
&lt;br /&gt;
'''IMPORTANT:''' The individual assignment is to be done by writing queries by hand.  (You can use phpMyAdmin to run the queries, but '''do not let phpMyAdmin write your queries for you!''')  Writing your own queries gives you a greater understanding of the underlying mechanisms and databases in general.  Additionally, having SQL knowledge and experience is a very marketable trait.&lt;br /&gt;
&lt;br /&gt;
=== Install MySQL and phpMyAdmin ===&lt;br /&gt;
&lt;br /&gt;
Before you start, '''you need to install MySQL''' on your EC2 instance.  You may also install phpMyAdmin, a web frontend to MySQL, if you choose to do so.&lt;br /&gt;
&lt;br /&gt;
You may find the following article to be very helpful: [[Introduction to MySQL]]&lt;br /&gt;
&lt;br /&gt;
=== Set Up a Database ===&lt;br /&gt;
&lt;br /&gt;
You may find the following article to be very helpful: [[Introduction to MySQL]]&lt;br /&gt;
&lt;br /&gt;
# Create a database named '''wustl''' &lt;br /&gt;
# Create a user named '''wustl_inst''' and give them the password '''wustl_pass'''&lt;br /&gt;
&lt;br /&gt;
=== Create Tables ===&lt;br /&gt;
&lt;br /&gt;
You may find the following article to be very helpful: [[MySQL Schema and State]]&lt;br /&gt;
&lt;br /&gt;
When creating tables, keep the following items in mind:&lt;br /&gt;
&lt;br /&gt;
* You should create all tables such that they use the InnoDB storage engine, since we wish to make use of its support of foreign keys. In other database engines, foreign key constraints are not enforced.  (If you mess up, you can use ALTER TABLE to change the storage engine.)&lt;br /&gt;
* Where it is appropriate, you should take advantage of the ability to define fields NOT NULL so that you do not inadvertently insert incomplete data for a row.&lt;br /&gt;
&lt;br /&gt;
Create the following tables:&lt;br /&gt;
&lt;br /&gt;
# Create a table named '''students''' with the following fields:&lt;br /&gt;
#* '''id''' of an appropriately-sized unsigned integer type (we will never need to process more than a million students)&lt;br /&gt;
#* '''first_name''' of type '''VARCHAR(50)'''&lt;br /&gt;
#* '''last_name''' of type '''VARCHAR(50)'''&lt;br /&gt;
#* '''email_address''' of type '''VARCHAR(50)'''&lt;br /&gt;
#: The primary key should be on the '''id''' field.&lt;br /&gt;
# Create a table named '''departments''' with the following fields:&lt;br /&gt;
#* '''school_code''' of type '''ENUM''' (e.g. &amp;quot;L&amp;quot; for ArtSci and &amp;quot;E&amp;quot; for Engineering).  The options are as follows:&lt;br /&gt;
#*: 'L', 'B', 'A', 'F', 'E', 'T', 'I', 'W', 'S', 'U', 'M'&lt;br /&gt;
#* '''dept_id''' of an appropriately-sized unsigned integer type (in the foreseeable future there will never be more than 200 departments in a school)&lt;br /&gt;
#* '''abbreviation''' of type '''VARCHAR(9)''' (e.g. CSE, ChemE, etc)&lt;br /&gt;
#* '''dept_name''' of type '''VARCHAR(200)''' (e.g. Computer Science and Engineering)&lt;br /&gt;
#: The primary key should be on two fields: '''school_code''' and '''dept_id'''&lt;br /&gt;
#: '''Note:''' Why not just use the department ID? The ID numbers are sometimes reused across schools. For instance, department 33 in The School of Arts and Sciences is Psychology while department 33 in The School of Engineering and Applied Sciences is Energy, Environmental and Chemical Engineering. Thus we must also include the school code to differentiate them  such that the record for  E33 is distinct from that of L33.&lt;br /&gt;
# Create a table named '''courses''' with the following fields:&lt;br /&gt;
#* '''school_code''' of type '''ENUM'''&lt;br /&gt;
#*: This should have the same letters in the same order as the '''school_code''' '''ENUM''' field in the '''departments''' table.&lt;br /&gt;
#* '''dept_id''' of the same size of integer as in the '''departments''' table&lt;br /&gt;
#* '''course_code''' of type '''CHAR(5)''' (this will hold course codes; e.g., '330S', '131', '2960')&lt;br /&gt;
#* '''name''' of type '''VARCHAR(150)'''&lt;br /&gt;
#: The appropriate fields in this table should make a foreign key reference to the corresponding fields in '''department'''.&lt;br /&gt;
#: In addition, it is up to you to determine the field(s) for the primary key.&lt;br /&gt;
#: '''Note:''' If you are unsure which fields to make the foreign keys and feel the need to beg your friends or the TAs to give you the answer, bang your head on your desk whilst repeating &amp;quot;I WILL EXERCISE REASON AND COMMON SENSE AND I WILL CURTAIL MY DESIRE TO BLINDLY FOLLOW DIRECTIONS&amp;quot;&lt;br /&gt;
#: ''Disclaimer: don't actually bang your head on your desk, the resulting head trauma may in fact make it harder for you to determine which fields should have associated foreign keys.''&lt;br /&gt;
# Create a table named '''grades''' with the following fields:&lt;br /&gt;
#* '''pk_grade_ID''' of an appropriately-sized unsigned integer type (should be larger than the one you chose for the '''students''' table)&lt;br /&gt;
#*: You should declare this field to be '''auto_increment''' and make it the primary key.&lt;br /&gt;
#*: This is called a ''surrogate key'' as opposed to a ''natural key'' because it doesn't arise &amp;quot;naturally&amp;quot; from the data; that is to say that it is not derived from application data. The use of surrogate keys vs. natural keys is a polemic issue amongst database designers.  For a decently unbiased take on the issue, see this page: http://www.agiledata.org/essays/keys.html#Comparison&lt;br /&gt;
#*: '''Food for thought:''' Aside from simply exposing you to the concept, can you think of any reasons why a surrogate key might be preferable for this table?  Alternatively, what attributes, if any, could you use as a natural key, and what might be the drawbacks of doing so?&lt;br /&gt;
#* '''student_id''' of the same integer (unsigned) type that you chose in the '''students''' table&lt;br /&gt;
#* '''grade''' of type '''decimal'''&lt;br /&gt;
#* '''school_code''' of type '''ENUM'''&lt;br /&gt;
#*: Can you guess what entries to use for the enum?&lt;br /&gt;
#* '''dept_id''' of the same integer type that you've used for this field in other tables&lt;br /&gt;
#* '''course_code''' of the same type you chose for the course code in the '''courses''' table&lt;br /&gt;
#: The '''grades''' table should have foreign keys to both the '''students''' table and the '''courses''' table.&lt;br /&gt;
&lt;br /&gt;
=== Populate Tables ===&lt;br /&gt;
&lt;br /&gt;
Now, populate the tables by downloading the text files given below and loading them into the appropriate tables.&lt;br /&gt;
&lt;br /&gt;
'''Note:''' Do not insert all the values manually; instead, use the MySQL's ability to load in data from text files.&lt;br /&gt;
&lt;br /&gt;
You may find the following article to be very helpful: [[MySQL Schema and State]]&lt;br /&gt;
&lt;br /&gt;
The files containing the data are:&lt;br /&gt;
&lt;br /&gt;
* students: https://docs.google.com/file/d/0ByHgvetJ0GJyMGFjMWI4MzAtMzljYy00Yjk3LTllMWItZjZkYmU1NzU3NWU0/edit&lt;br /&gt;
* courses: https://docs.google.com/file/d/0ByHgvetJ0GJyMGY1NGYzYmUtNGQwYi00MTY3LTkzMjgtMDYwOTM3NDNjZTg4/edit&lt;br /&gt;
* departments: https://docs.google.com/file/d/0ByHgvetJ0GJyZWY2OWE4ZWEtYzVmMC00YjBiLWEzZjgtYzdhMDczODAyNDli/edit&lt;br /&gt;
* grades: https://docs.google.com/file/d/0ByHgvetJ0GJyZmJjNzllNjAtMzdhZC00MzU5LTg3MDYtMTRmMjE5MDE2MzY2/edit&lt;br /&gt;
&lt;br /&gt;
=== Insert More Data ===&lt;br /&gt;
&lt;br /&gt;
Insert the following data into the tables that you have created and populated:&lt;br /&gt;
&lt;br /&gt;
# Insert an entry for CSE 330&lt;br /&gt;
#: ''If you don't know CSE's department code, how can you find out using the tables in the database?''&lt;br /&gt;
# Insert the grades given for the students named below.  You may choose to make the entries for whichever classes you like, with the one condition that all of the students must have a grade for CSE 330 (who wouldn't want to take that class: I hear the professor and TAs are amazing!)&lt;br /&gt;
#* '''Ben Harper'''&lt;br /&gt;
#** E-mail: '''bharper@ffym.com'''&lt;br /&gt;
#** Student ID: '''88'''&lt;br /&gt;
#** Grades:&lt;br /&gt;
#*** 5.5&lt;br /&gt;
#*** 0&lt;br /&gt;
#*** 20&lt;br /&gt;
#* '''Matt Freeman'''&lt;br /&gt;
#** E-mail: '''mfreeman@kickinbassist.net'''&lt;br /&gt;
#** Student ID: '''202'''&lt;br /&gt;
#** Grades:&lt;br /&gt;
#*** 100&lt;br /&gt;
#*** 90.5&lt;br /&gt;
#*** 94.8&lt;br /&gt;
#* '''Marc Roberge'''&lt;br /&gt;
#** E-mail: '''mroberge@ofarevolution.us'''&lt;br /&gt;
#** Student ID: '''115'''&lt;br /&gt;
#** Grades:&lt;br /&gt;
#*** 15&lt;br /&gt;
#*** 37&lt;br /&gt;
#*** 45.5&lt;br /&gt;
#: You may choose any 3 classes you'd like for them to be enrolled in, with at least one class, &amp;quot;CSE 330S&amp;quot;, in which they are all enrolled.&lt;br /&gt;
&lt;br /&gt;
=== Querying Your Database ===&lt;br /&gt;
&lt;br /&gt;
Now that you have a fully-functional, populated database, let's do some queries on it!&lt;br /&gt;
&lt;br /&gt;
Please take a screenshot of running the following '''select''' queries and show them to a TA (be sure to include your query command and the response:&lt;br /&gt;
&lt;br /&gt;
# Select the entire grades table.&lt;br /&gt;
# Select all fields describing the courses offered in the school of arts and sciences (school code L).&lt;br /&gt;
# The names, student IDs, and grades of the students who are in CSE330.&lt;br /&gt;
# The names and e-mails of any student with an average below 50 so that the dean can send them an email notification that they are now on academic probation.&lt;br /&gt;
#: ''You should be able to do this in only one query, without making any temporary tables.  You will need to use aggregation functions and the '''having''' keyword.''&lt;br /&gt;
# An individual report card for Jack Johnson, consisting of two tables (these can be done using separate queries):&lt;br /&gt;
## His student ID, e-mail address, and average grade.&lt;br /&gt;
##: ''Again, you should be able to do this in just one query, using the correct combination of aggregation functions and joins.''&lt;br /&gt;
## The classes he is in and his grades for those classes. To give you an idea, one row in the table should look like this:&lt;br /&gt;
##: &amp;lt;code&amp;gt;E	81	400	Independent Study	98.5&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Group Project ==&lt;br /&gt;
&lt;br /&gt;
You will work in pairs on this project.  You may work with the same partner from Module 2, or change to someone else.&lt;br /&gt;
&lt;br /&gt;
'''Important Reminder:''' frequently commit your work to your subversion repository as a backup!&lt;br /&gt;
&lt;br /&gt;
=== Simple News Web Site ===&lt;br /&gt;
&lt;br /&gt;
'''Examples:'''&lt;br /&gt;
* http://digg.com/&lt;br /&gt;
* http://slashdot.org/&lt;br /&gt;
&lt;br /&gt;
You should use '''PHP''' unless you get permission to use another web technology from the instructor.  You may also use phpMyAdmin to help set up databases.&lt;br /&gt;
&lt;br /&gt;
You may find this wiki article helpful: [[PHP and MySQL]]&lt;br /&gt;
&lt;br /&gt;
==== Requirements ====&lt;br /&gt;
&lt;br /&gt;
* Users can register for accounts and then log in to the website.&lt;br /&gt;
* Accounts should have both a username and a ''secure'' password.  '''NEVER store plaintext passwords in a database!'''&lt;br /&gt;
*: For more information on password security, refer to [[Web Application Security, Part 2#Password Security|the Web Application Security guide]].&lt;br /&gt;
*: You may also want to refer to http://php.net/manual/en/function.md5.php for information on md5.  &lt;br /&gt;
* Registered users can submit stories: either a link with summary or news text.&lt;br /&gt;
*: You do not have to make a distinction between the two types of stories, although if you want to, you could do something with this for the creative portion of your project.&lt;br /&gt;
* Registered users can comment on any story.&lt;br /&gt;
* Administrator users can delete stories and comments.&lt;br /&gt;
* Unregistered users can only view stories and comments.&lt;br /&gt;
* Registered users can edit their stories and can delete their comments.&lt;br /&gt;
* All data must be kept in a MySQL database (user information, stories, comments, and categories).&lt;br /&gt;
* As before, please check with a TA to see if your creative portion is okay or not before you proceed.&lt;br /&gt;
&lt;br /&gt;
=== Web Security and Validation ===&lt;br /&gt;
&lt;br /&gt;
Your project needs to demonstrate that thought was put into web security and best practice.  For more information, see this week's Web Application Security guide: [[Web Application Security, Part 2]]&lt;br /&gt;
&lt;br /&gt;
In particular:&lt;br /&gt;
&lt;br /&gt;
* '''Your application needs to be secure from SQL injection attacks'''. If you are using prepared queries, you should already be safe on this front.&lt;br /&gt;
* '''All of your output needs to be sanitized using htmlentities()'''.&lt;br /&gt;
&lt;br /&gt;
You shouldn't forget the practices you learned last week:&lt;br /&gt;
&lt;br /&gt;
* '''You should pass tokens in forms''' to prevent CSRF attacks.&lt;br /&gt;
* '''Your page should validate''' with no errors through the W3C validator.&lt;br /&gt;
&lt;br /&gt;
== Grading ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;font-size:2em; line-height:2em;&amp;quot;&amp;gt;'''Due Date: Wednesday October 10th, by 1pm (both individual and group)'''&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
!Assignment&lt;br /&gt;
!Points&lt;br /&gt;
|-&lt;br /&gt;
|Tables Correct&lt;br /&gt;
|2&lt;br /&gt;
|-&lt;br /&gt;
|Data Queries Correct&lt;br /&gt;
|2&lt;br /&gt;
|-&lt;br /&gt;
!colspan=&amp;quot;2&amp;quot;|Group Portion:&lt;br /&gt;
|-&lt;br /&gt;
|User Authentication&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|User Registration&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Secure Password&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Main page displays all stories (or most recent stories)&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Page with individual story and comments&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Story Submission&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Comment System&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Administrator Deletion of Stories/Comments&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|User Edit of Story/Comment&lt;br /&gt;
|2&lt;br /&gt;
|-&lt;br /&gt;
|Protect Against SQL Injection Attack&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Sanitize Output&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Older Web Security Practices and Validation&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Creative Portion&lt;br /&gt;
|2&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
[[Category:Module 3]]&lt;br /&gt;
[[Category:Modules]]&lt;/div&gt;</summary>
		<author><name>Marc</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=Module_3&amp;diff=681</id>
		<title>Module 3</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=Module_3&amp;diff=681"/>
		<updated>2012-09-21T15:35:12Z</updated>

		<summary type="html">&lt;p&gt;Marc: /* Querying Your Database */  Screenshots for individual portion to save time during demo&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In Module 3, you will learn about MySQL, a web application database.&lt;br /&gt;
&lt;br /&gt;
This article contains your assignments for Module 3.&lt;br /&gt;
&lt;br /&gt;
== Individual Assignments ==&lt;br /&gt;
&lt;br /&gt;
You will create a simple grades database containing four tables.&lt;br /&gt;
&lt;br /&gt;
'''IMPORTANT:''' The individual assignment is to be done by writing queries by hand.  (You can use phpMyAdmin to run the queries, but '''do not let phpMyAdmin write your queries for you!''')  Writing your own queries gives you a greater understanding of the underlying mechanisms and databases in general.  Additionally, having SQL knowledge and experience is a very marketable trait.&lt;br /&gt;
&lt;br /&gt;
=== Install MySQL and phpMyAdmin ===&lt;br /&gt;
&lt;br /&gt;
Before you start, '''you need to install MySQL''' on your EC2 instance.  You may also install phpMyAdmin, a web frontend to MySQL, if you choose to do so.&lt;br /&gt;
&lt;br /&gt;
You may find the following article to be very helpful: [[Introduction to MySQL]]&lt;br /&gt;
&lt;br /&gt;
=== Set Up a Database ===&lt;br /&gt;
&lt;br /&gt;
You may find the following article to be very helpful: [[Introduction to MySQL]]&lt;br /&gt;
&lt;br /&gt;
# Create a database named '''wustl''' &lt;br /&gt;
# Create a user named '''wustl_inst''' and give them the password '''wustl_pass'''&lt;br /&gt;
&lt;br /&gt;
=== Create Tables ===&lt;br /&gt;
&lt;br /&gt;
You may find the following article to be very helpful: [[MySQL Schema and State]]&lt;br /&gt;
&lt;br /&gt;
When creating tables, keep the following items in mind:&lt;br /&gt;
&lt;br /&gt;
* You should create all tables such that they use the InnoDB storage engine, since we wish to make use of its support of foreign keys. In other database engines, foreign key constraints are not enforced.  (If you mess up, you can use ALTER TABLE to change the storage engine.)&lt;br /&gt;
* Where it is appropriate, you should take advantage of the ability to define fields NOT NULL so that you do not inadvertently insert incomplete data for a row.&lt;br /&gt;
&lt;br /&gt;
Create the following tables:&lt;br /&gt;
&lt;br /&gt;
# Create a table named '''students''' with the following fields:&lt;br /&gt;
#* '''id''' of an appropriately-sized unsigned integer type (we will never need to process more than a million students)&lt;br /&gt;
#* '''first_name''' of type '''VARCHAR(50)'''&lt;br /&gt;
#* '''last_name''' of type '''VARCHAR(50)'''&lt;br /&gt;
#* '''email_address''' of type '''VARCHAR(50)'''&lt;br /&gt;
#: The primary key should be on the '''id''' field.&lt;br /&gt;
# Create a table named '''departments''' with the following fields:&lt;br /&gt;
#* '''school_code''' of type '''ENUM''' (e.g. &amp;quot;L&amp;quot; for ArtSci and &amp;quot;E&amp;quot; for Engineering).  The options are as follows:&lt;br /&gt;
#*: 'L', 'B', 'A', 'F', 'E', 'T', 'I', 'W', 'S', 'U', 'M'&lt;br /&gt;
#* '''dept_id''' of an appropriately-sized unsigned integer type (in the foreseeable future there will never be more than 200 departments in a school)&lt;br /&gt;
#* '''abbreviation''' of type '''VARCHAR(9)''' (e.g. CSE, ChemE, etc)&lt;br /&gt;
#* '''dept_name''' of type '''VARCHAR(200)''' (e.g. Computer Science and Engineering)&lt;br /&gt;
#: The primary key should be on two fields: '''school_code''' and '''dept_id'''&lt;br /&gt;
#: '''Note:''' Why not just use the department ID? The ID numbers are sometimes reused across schools. For instance, department 33 in The School of Arts and Sciences is Psychology while department 33 in The School of Engineering and Applied Sciences is Energy, Environmental and Chemical Engineering. Thus we must also include the school code to differentiate them  such that the record for  E33 is distinct from that of L33.&lt;br /&gt;
# Create a table named '''courses''' with the following fields:&lt;br /&gt;
#* '''school_code''' of type '''ENUM'''&lt;br /&gt;
#*: This should have the same letters in the same order as the '''school_code''' '''ENUM''' field in the '''departments''' table.&lt;br /&gt;
#* '''dept_id''' of the same size of integer as in the '''departments''' table&lt;br /&gt;
#* '''course_code''' of type '''CHAR(5)''' (this will hold course codes; e.g., '330S', '131', '2960')&lt;br /&gt;
#* '''name''' of type '''VARCHAR(150)'''&lt;br /&gt;
#: The appropriate fields in this table should make a foreign key reference to the corresponding fields in '''department'''.&lt;br /&gt;
#: In addition, it is up to you to determine the field(s) for the primary key.&lt;br /&gt;
#: '''Note:''' If you are unsure which fields to make the foreign keys and feel the need to beg your friends or the TAs to give you the answer, bang your head on your desk whilst repeating &amp;quot;I WILL EXERCISE REASON AND COMMON SENSE AND I WILL CURTAIL MY DESIRE TO BLINDLY FOLLOW DIRECTIONS&amp;quot;&lt;br /&gt;
#: ''Disclaimer: don't actually bang your head on your desk, the resulting head trauma may in fact make it harder for you to determine which fields should have associated foreign keys.''&lt;br /&gt;
# Create a table named '''grades''' with the following fields:&lt;br /&gt;
#* '''pk_grade_ID''' of an appropriately-sized unsigned integer type (should be larger than the one you chose for the '''students''' table)&lt;br /&gt;
#*: You should declare this field to be '''auto_increment''' and make it the primary key.&lt;br /&gt;
#*: This is called a ''surrogate key'' as opposed to a ''natural key'' because it doesn't arise &amp;quot;naturally&amp;quot; from the data; that is to say that it is not derived from application data. The use of surrogate keys vs. natural keys is a polemic issue amongst database designers.  For a decently unbiased take on the issue, see this page: http://www.agiledata.org/essays/keys.html#Comparison&lt;br /&gt;
#*: '''Food for thought:''' Aside from simply exposing you to the concept, can you think of any reasons why a surrogate key might be preferable for this table?  Alternatively, what attributes, if any, could you use as a natural key, and what might be the drawbacks of doing so?&lt;br /&gt;
#* '''student_id''' of the same integer (unsigned) type that you chose in the '''students''' table&lt;br /&gt;
#* '''grade''' of type '''decimal'''&lt;br /&gt;
#* '''school_code''' of type '''ENUM'''&lt;br /&gt;
#*: Can you guess what entries to use for the enum?&lt;br /&gt;
#* '''dept_id''' of the same integer type that you've used for this field in other tables&lt;br /&gt;
#* '''course_code''' of the same type you chose for the course code in the '''courses''' table&lt;br /&gt;
#: The '''grades''' table should have foreign keys to both the '''students''' table and the '''courses''' table.&lt;br /&gt;
&lt;br /&gt;
=== Populate Tables ===&lt;br /&gt;
&lt;br /&gt;
Now, populate the tables by downloading the text files given below and loading them into the appropriate tables.&lt;br /&gt;
&lt;br /&gt;
'''Note:''' Do not insert all the values manually; instead, use the MySQL's ability to load in data from text files.&lt;br /&gt;
&lt;br /&gt;
You may find the following article to be very helpful: [[MySQL Schema and State]]&lt;br /&gt;
&lt;br /&gt;
The files containing the data are:&lt;br /&gt;
&lt;br /&gt;
* students: https://docs.google.com/file/d/0ByHgvetJ0GJyMGFjMWI4MzAtMzljYy00Yjk3LTllMWItZjZkYmU1NzU3NWU0/edit&lt;br /&gt;
* courses: https://docs.google.com/file/d/0ByHgvetJ0GJyMGY1NGYzYmUtNGQwYi00MTY3LTkzMjgtMDYwOTM3NDNjZTg4/edit&lt;br /&gt;
* departments: https://docs.google.com/file/d/0ByHgvetJ0GJyZWY2OWE4ZWEtYzVmMC00YjBiLWEzZjgtYzdhMDczODAyNDli/edit&lt;br /&gt;
* grades: https://docs.google.com/file/d/0ByHgvetJ0GJyZmJjNzllNjAtMzdhZC00MzU5LTg3MDYtMTRmMjE5MDE2MzY2/edit&lt;br /&gt;
&lt;br /&gt;
=== Insert More Data ===&lt;br /&gt;
&lt;br /&gt;
Insert the following data into the tables that you have created and populated:&lt;br /&gt;
&lt;br /&gt;
# Insert an entry for CSE 330&lt;br /&gt;
#: ''If you don't know CSE's department code, how can you find out using the tables in the database?''&lt;br /&gt;
# Insert the grades given for the students named below.  You may choose to make the entries for whichever classes you like, with the one condition that all of the students must have a grade for CSE 330 (who wouldn't want to take that class: I hear the professor and TAs are amazing!)&lt;br /&gt;
#* '''Ben Harper'''&lt;br /&gt;
#** E-mail: '''bharper@ffym.com'''&lt;br /&gt;
#** Student ID: '''88'''&lt;br /&gt;
#** Grades:&lt;br /&gt;
#*** 5.5&lt;br /&gt;
#*** 0&lt;br /&gt;
#*** 20&lt;br /&gt;
#* '''Matt Freeman'''&lt;br /&gt;
#** E-mail: '''mfreeman@kickinbassist.net'''&lt;br /&gt;
#** Student ID: '''202'''&lt;br /&gt;
#** Grades:&lt;br /&gt;
#*** 100&lt;br /&gt;
#*** 90.5&lt;br /&gt;
#*** 94.8&lt;br /&gt;
#* '''Marc Roberge'''&lt;br /&gt;
#** E-mail: '''mroberge@ofarevolution.us'''&lt;br /&gt;
#** Student ID: '''115'''&lt;br /&gt;
#** Grades:&lt;br /&gt;
#*** 15&lt;br /&gt;
#*** 37&lt;br /&gt;
#*** 45.5&lt;br /&gt;
#: You may choose any 3 classes you'd like for them to be enrolled in, with at least one class, &amp;quot;CSE 330S&amp;quot;, in which they are all enrolled.&lt;br /&gt;
&lt;br /&gt;
=== Querying Your Database ===&lt;br /&gt;
&lt;br /&gt;
Now that you have a fully-functional, populated database, let's do some queries on it!&lt;br /&gt;
&lt;br /&gt;
Please take a screenshot of the following '''select''' queries and show them to a TA:&lt;br /&gt;
&lt;br /&gt;
# Select the entire grades table.&lt;br /&gt;
# Select all fields describing the courses offered in the school of arts and sciences (school code L).&lt;br /&gt;
# The names, student IDs, and grades of the students who are in CSE330.&lt;br /&gt;
# The names and e-mails of any student with an average below 50 so that the dean can send them an email notification that they are now on academic probation.&lt;br /&gt;
#: ''You should be able to do this in only one query, without making any temporary tables.  You will need to use aggregation functions and the '''having''' keyword.''&lt;br /&gt;
# An individual report card for Jack Johnson, consisting of two tables (these can be done using separate queries):&lt;br /&gt;
## His student ID, e-mail address, and average grade.&lt;br /&gt;
##: ''Again, you should be able to do this in just one query, using the correct combination of aggregation functions and joins.''&lt;br /&gt;
## The classes he is in and his grades for those classes. To give you an idea, one row in the table should look like this:&lt;br /&gt;
##: &amp;lt;code&amp;gt;E	81	400	Independent Study	98.5&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Group Project ==&lt;br /&gt;
&lt;br /&gt;
You will work in pairs on this project.  You may work with the same partner from Module 2, or change to someone else.&lt;br /&gt;
&lt;br /&gt;
'''Important Reminder:''' frequently commit your work to your subversion repository as a backup!&lt;br /&gt;
&lt;br /&gt;
=== Simple News Web Site ===&lt;br /&gt;
&lt;br /&gt;
'''Examples:'''&lt;br /&gt;
* http://digg.com/&lt;br /&gt;
* http://slashdot.org/&lt;br /&gt;
&lt;br /&gt;
You should use '''PHP''' unless you get permission to use another web technology from the instructor.  You may also use phpMyAdmin to help set up databases.&lt;br /&gt;
&lt;br /&gt;
You may find this wiki article helpful: [[PHP and MySQL]]&lt;br /&gt;
&lt;br /&gt;
==== Requirements ====&lt;br /&gt;
&lt;br /&gt;
* Users can register for accounts and then log in to the website.&lt;br /&gt;
* Accounts should have both a username and a ''secure'' password.  '''NEVER store plaintext passwords in a database!'''&lt;br /&gt;
*: For more information on password security, refer to [[Web Application Security, Part 2#Password Security|the Web Application Security guide]].&lt;br /&gt;
*: You may also want to refer to http://php.net/manual/en/function.md5.php for information on md5.  &lt;br /&gt;
* Registered users can submit stories: either a link with summary or news text.&lt;br /&gt;
*: You do not have to make a distinction between the two types of stories, although if you want to, you could do something with this for the creative portion of your project.&lt;br /&gt;
* Registered users can comment on any story.&lt;br /&gt;
* Administrator users can delete stories and comments.&lt;br /&gt;
* Unregistered users can only view stories and comments.&lt;br /&gt;
* Registered users can edit their stories and can delete their comments.&lt;br /&gt;
* All data must be kept in a MySQL database (user information, stories, comments, and categories).&lt;br /&gt;
* As before, please check with a TA to see if your creative portion is okay or not before you proceed.&lt;br /&gt;
&lt;br /&gt;
=== Web Security and Validation ===&lt;br /&gt;
&lt;br /&gt;
Your project needs to demonstrate that thought was put into web security and best practice.  For more information, see this week's Web Application Security guide: [[Web Application Security, Part 2]]&lt;br /&gt;
&lt;br /&gt;
In particular:&lt;br /&gt;
&lt;br /&gt;
* '''Your application needs to be secure from SQL injection attacks'''. If you are using prepared queries, you should already be safe on this front.&lt;br /&gt;
* '''All of your output needs to be sanitized using htmlentities()'''.&lt;br /&gt;
&lt;br /&gt;
You shouldn't forget the practices you learned last week:&lt;br /&gt;
&lt;br /&gt;
* '''You should pass tokens in forms''' to prevent CSRF attacks.&lt;br /&gt;
* '''Your page should validate''' with no errors through the W3C validator.&lt;br /&gt;
&lt;br /&gt;
== Grading ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;font-size:2em; line-height:2em;&amp;quot;&amp;gt;'''Due Date: Wednesday October 10th, by 1pm (both individual and group)'''&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
!Assignment&lt;br /&gt;
!Points&lt;br /&gt;
|-&lt;br /&gt;
|Tables Correct&lt;br /&gt;
|2&lt;br /&gt;
|-&lt;br /&gt;
|Data Queries Correct&lt;br /&gt;
|2&lt;br /&gt;
|-&lt;br /&gt;
!colspan=&amp;quot;2&amp;quot;|Group Portion:&lt;br /&gt;
|-&lt;br /&gt;
|User Authentication&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|User Registration&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Secure Password&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Main page displays all stories (or most recent stories)&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Page with individual story and comments&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Story Submission&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Comment System&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Administrator Deletion of Stories/Comments&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|User Edit of Story/Comment&lt;br /&gt;
|2&lt;br /&gt;
|-&lt;br /&gt;
|Protect Against SQL Injection Attack&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Sanitize Output&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Older Web Security Practices and Validation&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Creative Portion&lt;br /&gt;
|2&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
[[Category:Module 3]]&lt;br /&gt;
[[Category:Modules]]&lt;/div&gt;</summary>
		<author><name>Marc</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=Module_3&amp;diff=680</id>
		<title>Module 3</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=Module_3&amp;diff=680"/>
		<updated>2012-09-21T15:33:19Z</updated>

		<summary type="html">&lt;p&gt;Marc: /* Requirements */  creative portion&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In Module 3, you will learn about MySQL, a web application database.&lt;br /&gt;
&lt;br /&gt;
This article contains your assignments for Module 3.&lt;br /&gt;
&lt;br /&gt;
== Individual Assignments ==&lt;br /&gt;
&lt;br /&gt;
You will create a simple grades database containing four tables.&lt;br /&gt;
&lt;br /&gt;
'''IMPORTANT:''' The individual assignment is to be done by writing queries by hand.  (You can use phpMyAdmin to run the queries, but '''do not let phpMyAdmin write your queries for you!''')  Writing your own queries gives you a greater understanding of the underlying mechanisms and databases in general.  Additionally, having SQL knowledge and experience is a very marketable trait.&lt;br /&gt;
&lt;br /&gt;
=== Install MySQL and phpMyAdmin ===&lt;br /&gt;
&lt;br /&gt;
Before you start, '''you need to install MySQL''' on your EC2 instance.  You may also install phpMyAdmin, a web frontend to MySQL, if you choose to do so.&lt;br /&gt;
&lt;br /&gt;
You may find the following article to be very helpful: [[Introduction to MySQL]]&lt;br /&gt;
&lt;br /&gt;
=== Set Up a Database ===&lt;br /&gt;
&lt;br /&gt;
You may find the following article to be very helpful: [[Introduction to MySQL]]&lt;br /&gt;
&lt;br /&gt;
# Create a database named '''wustl''' &lt;br /&gt;
# Create a user named '''wustl_inst''' and give them the password '''wustl_pass'''&lt;br /&gt;
&lt;br /&gt;
=== Create Tables ===&lt;br /&gt;
&lt;br /&gt;
You may find the following article to be very helpful: [[MySQL Schema and State]]&lt;br /&gt;
&lt;br /&gt;
When creating tables, keep the following items in mind:&lt;br /&gt;
&lt;br /&gt;
* You should create all tables such that they use the InnoDB storage engine, since we wish to make use of its support of foreign keys. In other database engines, foreign key constraints are not enforced.  (If you mess up, you can use ALTER TABLE to change the storage engine.)&lt;br /&gt;
* Where it is appropriate, you should take advantage of the ability to define fields NOT NULL so that you do not inadvertently insert incomplete data for a row.&lt;br /&gt;
&lt;br /&gt;
Create the following tables:&lt;br /&gt;
&lt;br /&gt;
# Create a table named '''students''' with the following fields:&lt;br /&gt;
#* '''id''' of an appropriately-sized unsigned integer type (we will never need to process more than a million students)&lt;br /&gt;
#* '''first_name''' of type '''VARCHAR(50)'''&lt;br /&gt;
#* '''last_name''' of type '''VARCHAR(50)'''&lt;br /&gt;
#* '''email_address''' of type '''VARCHAR(50)'''&lt;br /&gt;
#: The primary key should be on the '''id''' field.&lt;br /&gt;
# Create a table named '''departments''' with the following fields:&lt;br /&gt;
#* '''school_code''' of type '''ENUM''' (e.g. &amp;quot;L&amp;quot; for ArtSci and &amp;quot;E&amp;quot; for Engineering).  The options are as follows:&lt;br /&gt;
#*: 'L', 'B', 'A', 'F', 'E', 'T', 'I', 'W', 'S', 'U', 'M'&lt;br /&gt;
#* '''dept_id''' of an appropriately-sized unsigned integer type (in the foreseeable future there will never be more than 200 departments in a school)&lt;br /&gt;
#* '''abbreviation''' of type '''VARCHAR(9)''' (e.g. CSE, ChemE, etc)&lt;br /&gt;
#* '''dept_name''' of type '''VARCHAR(200)''' (e.g. Computer Science and Engineering)&lt;br /&gt;
#: The primary key should be on two fields: '''school_code''' and '''dept_id'''&lt;br /&gt;
#: '''Note:''' Why not just use the department ID? The ID numbers are sometimes reused across schools. For instance, department 33 in The School of Arts and Sciences is Psychology while department 33 in The School of Engineering and Applied Sciences is Energy, Environmental and Chemical Engineering. Thus we must also include the school code to differentiate them  such that the record for  E33 is distinct from that of L33.&lt;br /&gt;
# Create a table named '''courses''' with the following fields:&lt;br /&gt;
#* '''school_code''' of type '''ENUM'''&lt;br /&gt;
#*: This should have the same letters in the same order as the '''school_code''' '''ENUM''' field in the '''departments''' table.&lt;br /&gt;
#* '''dept_id''' of the same size of integer as in the '''departments''' table&lt;br /&gt;
#* '''course_code''' of type '''CHAR(5)''' (this will hold course codes; e.g., '330S', '131', '2960')&lt;br /&gt;
#* '''name''' of type '''VARCHAR(150)'''&lt;br /&gt;
#: The appropriate fields in this table should make a foreign key reference to the corresponding fields in '''department'''.&lt;br /&gt;
#: In addition, it is up to you to determine the field(s) for the primary key.&lt;br /&gt;
#: '''Note:''' If you are unsure which fields to make the foreign keys and feel the need to beg your friends or the TAs to give you the answer, bang your head on your desk whilst repeating &amp;quot;I WILL EXERCISE REASON AND COMMON SENSE AND I WILL CURTAIL MY DESIRE TO BLINDLY FOLLOW DIRECTIONS&amp;quot;&lt;br /&gt;
#: ''Disclaimer: don't actually bang your head on your desk, the resulting head trauma may in fact make it harder for you to determine which fields should have associated foreign keys.''&lt;br /&gt;
# Create a table named '''grades''' with the following fields:&lt;br /&gt;
#* '''pk_grade_ID''' of an appropriately-sized unsigned integer type (should be larger than the one you chose for the '''students''' table)&lt;br /&gt;
#*: You should declare this field to be '''auto_increment''' and make it the primary key.&lt;br /&gt;
#*: This is called a ''surrogate key'' as opposed to a ''natural key'' because it doesn't arise &amp;quot;naturally&amp;quot; from the data; that is to say that it is not derived from application data. The use of surrogate keys vs. natural keys is a polemic issue amongst database designers.  For a decently unbiased take on the issue, see this page: http://www.agiledata.org/essays/keys.html#Comparison&lt;br /&gt;
#*: '''Food for thought:''' Aside from simply exposing you to the concept, can you think of any reasons why a surrogate key might be preferable for this table?  Alternatively, what attributes, if any, could you use as a natural key, and what might be the drawbacks of doing so?&lt;br /&gt;
#* '''student_id''' of the same integer (unsigned) type that you chose in the '''students''' table&lt;br /&gt;
#* '''grade''' of type '''decimal'''&lt;br /&gt;
#* '''school_code''' of type '''ENUM'''&lt;br /&gt;
#*: Can you guess what entries to use for the enum?&lt;br /&gt;
#* '''dept_id''' of the same integer type that you've used for this field in other tables&lt;br /&gt;
#* '''course_code''' of the same type you chose for the course code in the '''courses''' table&lt;br /&gt;
#: The '''grades''' table should have foreign keys to both the '''students''' table and the '''courses''' table.&lt;br /&gt;
&lt;br /&gt;
=== Populate Tables ===&lt;br /&gt;
&lt;br /&gt;
Now, populate the tables by downloading the text files given below and loading them into the appropriate tables.&lt;br /&gt;
&lt;br /&gt;
'''Note:''' Do not insert all the values manually; instead, use the MySQL's ability to load in data from text files.&lt;br /&gt;
&lt;br /&gt;
You may find the following article to be very helpful: [[MySQL Schema and State]]&lt;br /&gt;
&lt;br /&gt;
The files containing the data are:&lt;br /&gt;
&lt;br /&gt;
* students: https://docs.google.com/file/d/0ByHgvetJ0GJyMGFjMWI4MzAtMzljYy00Yjk3LTllMWItZjZkYmU1NzU3NWU0/edit&lt;br /&gt;
* courses: https://docs.google.com/file/d/0ByHgvetJ0GJyMGY1NGYzYmUtNGQwYi00MTY3LTkzMjgtMDYwOTM3NDNjZTg4/edit&lt;br /&gt;
* departments: https://docs.google.com/file/d/0ByHgvetJ0GJyZWY2OWE4ZWEtYzVmMC00YjBiLWEzZjgtYzdhMDczODAyNDli/edit&lt;br /&gt;
* grades: https://docs.google.com/file/d/0ByHgvetJ0GJyZmJjNzllNjAtMzdhZC00MzU5LTg3MDYtMTRmMjE5MDE2MzY2/edit&lt;br /&gt;
&lt;br /&gt;
=== Insert More Data ===&lt;br /&gt;
&lt;br /&gt;
Insert the following data into the tables that you have created and populated:&lt;br /&gt;
&lt;br /&gt;
# Insert an entry for CSE 330&lt;br /&gt;
#: ''If you don't know CSE's department code, how can you find out using the tables in the database?''&lt;br /&gt;
# Insert the grades given for the students named below.  You may choose to make the entries for whichever classes you like, with the one condition that all of the students must have a grade for CSE 330 (who wouldn't want to take that class: I hear the professor and TAs are amazing!)&lt;br /&gt;
#* '''Ben Harper'''&lt;br /&gt;
#** E-mail: '''bharper@ffym.com'''&lt;br /&gt;
#** Student ID: '''88'''&lt;br /&gt;
#** Grades:&lt;br /&gt;
#*** 5.5&lt;br /&gt;
#*** 0&lt;br /&gt;
#*** 20&lt;br /&gt;
#* '''Matt Freeman'''&lt;br /&gt;
#** E-mail: '''mfreeman@kickinbassist.net'''&lt;br /&gt;
#** Student ID: '''202'''&lt;br /&gt;
#** Grades:&lt;br /&gt;
#*** 100&lt;br /&gt;
#*** 90.5&lt;br /&gt;
#*** 94.8&lt;br /&gt;
#* '''Marc Roberge'''&lt;br /&gt;
#** E-mail: '''mroberge@ofarevolution.us'''&lt;br /&gt;
#** Student ID: '''115'''&lt;br /&gt;
#** Grades:&lt;br /&gt;
#*** 15&lt;br /&gt;
#*** 37&lt;br /&gt;
#*** 45.5&lt;br /&gt;
#: You may choose any 3 classes you'd like for them to be enrolled in, with at least one class, &amp;quot;CSE 330S&amp;quot;, in which they are all enrolled.&lt;br /&gt;
&lt;br /&gt;
=== Querying Your Database ===&lt;br /&gt;
&lt;br /&gt;
Now that you have a fully-functional, populated database, let's do some queries on it!&lt;br /&gt;
&lt;br /&gt;
Write the following '''select''' queries and then run them for a TA:&lt;br /&gt;
&lt;br /&gt;
# Select the entire grades table.&lt;br /&gt;
# Select all fields describing the courses offered in the school of arts and sciences (school code L).&lt;br /&gt;
# The names, student IDs, and grades of the students who are in CSE330.&lt;br /&gt;
# The names and e-mails of any student with an average below 50 so that the dean can send them an email notification that they are now on academic probation.&lt;br /&gt;
#: ''You should be able to do this in only one query, without making any temporary tables.  You will need to use aggregation functions and the '''having''' keyword.''&lt;br /&gt;
# An individual report card for Jack Johnson, consisting of two tables (these can be done using separate queries):&lt;br /&gt;
## His student ID, e-mail address, and average grade.&lt;br /&gt;
##: ''Again, you should be able to do this in just one query, using the correct combination of aggregation functions and joins.''&lt;br /&gt;
## The classes he is in and his grades for those classes. To give you an idea, one row in the table should look like this:&lt;br /&gt;
##: &amp;lt;code&amp;gt;E	81	400	Independent Study	98.5&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Group Project ==&lt;br /&gt;
&lt;br /&gt;
You will work in pairs on this project.  You may work with the same partner from Module 2, or change to someone else.&lt;br /&gt;
&lt;br /&gt;
'''Important Reminder:''' frequently commit your work to your subversion repository as a backup!&lt;br /&gt;
&lt;br /&gt;
=== Simple News Web Site ===&lt;br /&gt;
&lt;br /&gt;
'''Examples:'''&lt;br /&gt;
* http://digg.com/&lt;br /&gt;
* http://slashdot.org/&lt;br /&gt;
&lt;br /&gt;
You should use '''PHP''' unless you get permission to use another web technology from the instructor.  You may also use phpMyAdmin to help set up databases.&lt;br /&gt;
&lt;br /&gt;
You may find this wiki article helpful: [[PHP and MySQL]]&lt;br /&gt;
&lt;br /&gt;
==== Requirements ====&lt;br /&gt;
&lt;br /&gt;
* Users can register for accounts and then log in to the website.&lt;br /&gt;
* Accounts should have both a username and a ''secure'' password.  '''NEVER store plaintext passwords in a database!'''&lt;br /&gt;
*: For more information on password security, refer to [[Web Application Security, Part 2#Password Security|the Web Application Security guide]].&lt;br /&gt;
*: You may also want to refer to http://php.net/manual/en/function.md5.php for information on md5.  &lt;br /&gt;
* Registered users can submit stories: either a link with summary or news text.&lt;br /&gt;
*: You do not have to make a distinction between the two types of stories, although if you want to, you could do something with this for the creative portion of your project.&lt;br /&gt;
* Registered users can comment on any story.&lt;br /&gt;
* Administrator users can delete stories and comments.&lt;br /&gt;
* Unregistered users can only view stories and comments.&lt;br /&gt;
* Registered users can edit their stories and can delete their comments.&lt;br /&gt;
* All data must be kept in a MySQL database (user information, stories, comments, and categories).&lt;br /&gt;
* As before, please check with a TA to see if your creative portion is okay or not before you proceed.&lt;br /&gt;
&lt;br /&gt;
=== Web Security and Validation ===&lt;br /&gt;
&lt;br /&gt;
Your project needs to demonstrate that thought was put into web security and best practice.  For more information, see this week's Web Application Security guide: [[Web Application Security, Part 2]]&lt;br /&gt;
&lt;br /&gt;
In particular:&lt;br /&gt;
&lt;br /&gt;
* '''Your application needs to be secure from SQL injection attacks'''. If you are using prepared queries, you should already be safe on this front.&lt;br /&gt;
* '''All of your output needs to be sanitized using htmlentities()'''.&lt;br /&gt;
&lt;br /&gt;
You shouldn't forget the practices you learned last week:&lt;br /&gt;
&lt;br /&gt;
* '''You should pass tokens in forms''' to prevent CSRF attacks.&lt;br /&gt;
* '''Your page should validate''' with no errors through the W3C validator.&lt;br /&gt;
&lt;br /&gt;
== Grading ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;font-size:2em; line-height:2em;&amp;quot;&amp;gt;'''Due Date: Wednesday October 10th, by 1pm (both individual and group)'''&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
!Assignment&lt;br /&gt;
!Points&lt;br /&gt;
|-&lt;br /&gt;
|Tables Correct&lt;br /&gt;
|2&lt;br /&gt;
|-&lt;br /&gt;
|Data Queries Correct&lt;br /&gt;
|2&lt;br /&gt;
|-&lt;br /&gt;
!colspan=&amp;quot;2&amp;quot;|Group Portion:&lt;br /&gt;
|-&lt;br /&gt;
|User Authentication&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|User Registration&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Secure Password&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Main page displays all stories (or most recent stories)&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Page with individual story and comments&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Story Submission&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Comment System&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Administrator Deletion of Stories/Comments&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|User Edit of Story/Comment&lt;br /&gt;
|2&lt;br /&gt;
|-&lt;br /&gt;
|Protect Against SQL Injection Attack&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Sanitize Output&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Older Web Security Practices and Validation&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Creative Portion&lt;br /&gt;
|2&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
[[Category:Module 3]]&lt;br /&gt;
[[Category:Modules]]&lt;/div&gt;</summary>
		<author><name>Marc</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=Module_3&amp;diff=679</id>
		<title>Module 3</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=Module_3&amp;diff=679"/>
		<updated>2012-09-21T15:32:28Z</updated>

		<summary type="html">&lt;p&gt;Marc: /* Grading */ due date&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In Module 3, you will learn about MySQL, a web application database.&lt;br /&gt;
&lt;br /&gt;
This article contains your assignments for Module 3.&lt;br /&gt;
&lt;br /&gt;
== Individual Assignments ==&lt;br /&gt;
&lt;br /&gt;
You will create a simple grades database containing four tables.&lt;br /&gt;
&lt;br /&gt;
'''IMPORTANT:''' The individual assignment is to be done by writing queries by hand.  (You can use phpMyAdmin to run the queries, but '''do not let phpMyAdmin write your queries for you!''')  Writing your own queries gives you a greater understanding of the underlying mechanisms and databases in general.  Additionally, having SQL knowledge and experience is a very marketable trait.&lt;br /&gt;
&lt;br /&gt;
=== Install MySQL and phpMyAdmin ===&lt;br /&gt;
&lt;br /&gt;
Before you start, '''you need to install MySQL''' on your EC2 instance.  You may also install phpMyAdmin, a web frontend to MySQL, if you choose to do so.&lt;br /&gt;
&lt;br /&gt;
You may find the following article to be very helpful: [[Introduction to MySQL]]&lt;br /&gt;
&lt;br /&gt;
=== Set Up a Database ===&lt;br /&gt;
&lt;br /&gt;
You may find the following article to be very helpful: [[Introduction to MySQL]]&lt;br /&gt;
&lt;br /&gt;
# Create a database named '''wustl''' &lt;br /&gt;
# Create a user named '''wustl_inst''' and give them the password '''wustl_pass'''&lt;br /&gt;
&lt;br /&gt;
=== Create Tables ===&lt;br /&gt;
&lt;br /&gt;
You may find the following article to be very helpful: [[MySQL Schema and State]]&lt;br /&gt;
&lt;br /&gt;
When creating tables, keep the following items in mind:&lt;br /&gt;
&lt;br /&gt;
* You should create all tables such that they use the InnoDB storage engine, since we wish to make use of its support of foreign keys. In other database engines, foreign key constraints are not enforced.  (If you mess up, you can use ALTER TABLE to change the storage engine.)&lt;br /&gt;
* Where it is appropriate, you should take advantage of the ability to define fields NOT NULL so that you do not inadvertently insert incomplete data for a row.&lt;br /&gt;
&lt;br /&gt;
Create the following tables:&lt;br /&gt;
&lt;br /&gt;
# Create a table named '''students''' with the following fields:&lt;br /&gt;
#* '''id''' of an appropriately-sized unsigned integer type (we will never need to process more than a million students)&lt;br /&gt;
#* '''first_name''' of type '''VARCHAR(50)'''&lt;br /&gt;
#* '''last_name''' of type '''VARCHAR(50)'''&lt;br /&gt;
#* '''email_address''' of type '''VARCHAR(50)'''&lt;br /&gt;
#: The primary key should be on the '''id''' field.&lt;br /&gt;
# Create a table named '''departments''' with the following fields:&lt;br /&gt;
#* '''school_code''' of type '''ENUM''' (e.g. &amp;quot;L&amp;quot; for ArtSci and &amp;quot;E&amp;quot; for Engineering).  The options are as follows:&lt;br /&gt;
#*: 'L', 'B', 'A', 'F', 'E', 'T', 'I', 'W', 'S', 'U', 'M'&lt;br /&gt;
#* '''dept_id''' of an appropriately-sized unsigned integer type (in the foreseeable future there will never be more than 200 departments in a school)&lt;br /&gt;
#* '''abbreviation''' of type '''VARCHAR(9)''' (e.g. CSE, ChemE, etc)&lt;br /&gt;
#* '''dept_name''' of type '''VARCHAR(200)''' (e.g. Computer Science and Engineering)&lt;br /&gt;
#: The primary key should be on two fields: '''school_code''' and '''dept_id'''&lt;br /&gt;
#: '''Note:''' Why not just use the department ID? The ID numbers are sometimes reused across schools. For instance, department 33 in The School of Arts and Sciences is Psychology while department 33 in The School of Engineering and Applied Sciences is Energy, Environmental and Chemical Engineering. Thus we must also include the school code to differentiate them  such that the record for  E33 is distinct from that of L33.&lt;br /&gt;
# Create a table named '''courses''' with the following fields:&lt;br /&gt;
#* '''school_code''' of type '''ENUM'''&lt;br /&gt;
#*: This should have the same letters in the same order as the '''school_code''' '''ENUM''' field in the '''departments''' table.&lt;br /&gt;
#* '''dept_id''' of the same size of integer as in the '''departments''' table&lt;br /&gt;
#* '''course_code''' of type '''CHAR(5)''' (this will hold course codes; e.g., '330S', '131', '2960')&lt;br /&gt;
#* '''name''' of type '''VARCHAR(150)'''&lt;br /&gt;
#: The appropriate fields in this table should make a foreign key reference to the corresponding fields in '''department'''.&lt;br /&gt;
#: In addition, it is up to you to determine the field(s) for the primary key.&lt;br /&gt;
#: '''Note:''' If you are unsure which fields to make the foreign keys and feel the need to beg your friends or the TAs to give you the answer, bang your head on your desk whilst repeating &amp;quot;I WILL EXERCISE REASON AND COMMON SENSE AND I WILL CURTAIL MY DESIRE TO BLINDLY FOLLOW DIRECTIONS&amp;quot;&lt;br /&gt;
#: ''Disclaimer: don't actually bang your head on your desk, the resulting head trauma may in fact make it harder for you to determine which fields should have associated foreign keys.''&lt;br /&gt;
# Create a table named '''grades''' with the following fields:&lt;br /&gt;
#* '''pk_grade_ID''' of an appropriately-sized unsigned integer type (should be larger than the one you chose for the '''students''' table)&lt;br /&gt;
#*: You should declare this field to be '''auto_increment''' and make it the primary key.&lt;br /&gt;
#*: This is called a ''surrogate key'' as opposed to a ''natural key'' because it doesn't arise &amp;quot;naturally&amp;quot; from the data; that is to say that it is not derived from application data. The use of surrogate keys vs. natural keys is a polemic issue amongst database designers.  For a decently unbiased take on the issue, see this page: http://www.agiledata.org/essays/keys.html#Comparison&lt;br /&gt;
#*: '''Food for thought:''' Aside from simply exposing you to the concept, can you think of any reasons why a surrogate key might be preferable for this table?  Alternatively, what attributes, if any, could you use as a natural key, and what might be the drawbacks of doing so?&lt;br /&gt;
#* '''student_id''' of the same integer (unsigned) type that you chose in the '''students''' table&lt;br /&gt;
#* '''grade''' of type '''decimal'''&lt;br /&gt;
#* '''school_code''' of type '''ENUM'''&lt;br /&gt;
#*: Can you guess what entries to use for the enum?&lt;br /&gt;
#* '''dept_id''' of the same integer type that you've used for this field in other tables&lt;br /&gt;
#* '''course_code''' of the same type you chose for the course code in the '''courses''' table&lt;br /&gt;
#: The '''grades''' table should have foreign keys to both the '''students''' table and the '''courses''' table.&lt;br /&gt;
&lt;br /&gt;
=== Populate Tables ===&lt;br /&gt;
&lt;br /&gt;
Now, populate the tables by downloading the text files given below and loading them into the appropriate tables.&lt;br /&gt;
&lt;br /&gt;
'''Note:''' Do not insert all the values manually; instead, use the MySQL's ability to load in data from text files.&lt;br /&gt;
&lt;br /&gt;
You may find the following article to be very helpful: [[MySQL Schema and State]]&lt;br /&gt;
&lt;br /&gt;
The files containing the data are:&lt;br /&gt;
&lt;br /&gt;
* students: https://docs.google.com/file/d/0ByHgvetJ0GJyMGFjMWI4MzAtMzljYy00Yjk3LTllMWItZjZkYmU1NzU3NWU0/edit&lt;br /&gt;
* courses: https://docs.google.com/file/d/0ByHgvetJ0GJyMGY1NGYzYmUtNGQwYi00MTY3LTkzMjgtMDYwOTM3NDNjZTg4/edit&lt;br /&gt;
* departments: https://docs.google.com/file/d/0ByHgvetJ0GJyZWY2OWE4ZWEtYzVmMC00YjBiLWEzZjgtYzdhMDczODAyNDli/edit&lt;br /&gt;
* grades: https://docs.google.com/file/d/0ByHgvetJ0GJyZmJjNzllNjAtMzdhZC00MzU5LTg3MDYtMTRmMjE5MDE2MzY2/edit&lt;br /&gt;
&lt;br /&gt;
=== Insert More Data ===&lt;br /&gt;
&lt;br /&gt;
Insert the following data into the tables that you have created and populated:&lt;br /&gt;
&lt;br /&gt;
# Insert an entry for CSE 330&lt;br /&gt;
#: ''If you don't know CSE's department code, how can you find out using the tables in the database?''&lt;br /&gt;
# Insert the grades given for the students named below.  You may choose to make the entries for whichever classes you like, with the one condition that all of the students must have a grade for CSE 330 (who wouldn't want to take that class: I hear the professor and TAs are amazing!)&lt;br /&gt;
#* '''Ben Harper'''&lt;br /&gt;
#** E-mail: '''bharper@ffym.com'''&lt;br /&gt;
#** Student ID: '''88'''&lt;br /&gt;
#** Grades:&lt;br /&gt;
#*** 5.5&lt;br /&gt;
#*** 0&lt;br /&gt;
#*** 20&lt;br /&gt;
#* '''Matt Freeman'''&lt;br /&gt;
#** E-mail: '''mfreeman@kickinbassist.net'''&lt;br /&gt;
#** Student ID: '''202'''&lt;br /&gt;
#** Grades:&lt;br /&gt;
#*** 100&lt;br /&gt;
#*** 90.5&lt;br /&gt;
#*** 94.8&lt;br /&gt;
#* '''Marc Roberge'''&lt;br /&gt;
#** E-mail: '''mroberge@ofarevolution.us'''&lt;br /&gt;
#** Student ID: '''115'''&lt;br /&gt;
#** Grades:&lt;br /&gt;
#*** 15&lt;br /&gt;
#*** 37&lt;br /&gt;
#*** 45.5&lt;br /&gt;
#: You may choose any 3 classes you'd like for them to be enrolled in, with at least one class, &amp;quot;CSE 330S&amp;quot;, in which they are all enrolled.&lt;br /&gt;
&lt;br /&gt;
=== Querying Your Database ===&lt;br /&gt;
&lt;br /&gt;
Now that you have a fully-functional, populated database, let's do some queries on it!&lt;br /&gt;
&lt;br /&gt;
Write the following '''select''' queries and then run them for a TA:&lt;br /&gt;
&lt;br /&gt;
# Select the entire grades table.&lt;br /&gt;
# Select all fields describing the courses offered in the school of arts and sciences (school code L).&lt;br /&gt;
# The names, student IDs, and grades of the students who are in CSE330.&lt;br /&gt;
# The names and e-mails of any student with an average below 50 so that the dean can send them an email notification that they are now on academic probation.&lt;br /&gt;
#: ''You should be able to do this in only one query, without making any temporary tables.  You will need to use aggregation functions and the '''having''' keyword.''&lt;br /&gt;
# An individual report card for Jack Johnson, consisting of two tables (these can be done using separate queries):&lt;br /&gt;
## His student ID, e-mail address, and average grade.&lt;br /&gt;
##: ''Again, you should be able to do this in just one query, using the correct combination of aggregation functions and joins.''&lt;br /&gt;
## The classes he is in and his grades for those classes. To give you an idea, one row in the table should look like this:&lt;br /&gt;
##: &amp;lt;code&amp;gt;E	81	400	Independent Study	98.5&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Group Project ==&lt;br /&gt;
&lt;br /&gt;
You will work in pairs on this project.  You may work with the same partner from Module 2, or change to someone else.&lt;br /&gt;
&lt;br /&gt;
'''Important Reminder:''' frequently commit your work to your subversion repository as a backup!&lt;br /&gt;
&lt;br /&gt;
=== Simple News Web Site ===&lt;br /&gt;
&lt;br /&gt;
'''Examples:'''&lt;br /&gt;
* http://digg.com/&lt;br /&gt;
* http://slashdot.org/&lt;br /&gt;
&lt;br /&gt;
You should use '''PHP''' unless you get permission to use another web technology from the instructor.  You may also use phpMyAdmin to help set up databases.&lt;br /&gt;
&lt;br /&gt;
You may find this wiki article helpful: [[PHP and MySQL]]&lt;br /&gt;
&lt;br /&gt;
==== Requirements ====&lt;br /&gt;
&lt;br /&gt;
* Users can register for accounts and then log in to the website.&lt;br /&gt;
* Accounts should have both a username and a ''secure'' password.  '''NEVER store plaintext passwords in a database!'''&lt;br /&gt;
*: For more information on password security, refer to [[Web Application Security, Part 2#Password Security|the Web Application Security guide]].&lt;br /&gt;
*: You may also want to refer to http://php.net/manual/en/function.md5.php for information on md5.  &lt;br /&gt;
* Registered users can submit stories: either a link with summary or news text.&lt;br /&gt;
*: You do not have to make a distinction between the two types of stories, although if you want to, you could do something with this for the creative portion of your project.&lt;br /&gt;
* Registered users can comment on any story.&lt;br /&gt;
* Administrator users can delete stories and comments.&lt;br /&gt;
* Unregistered users can only view stories and comments.&lt;br /&gt;
* Registered users can edit their stories and can delete their comments.&lt;br /&gt;
* All data must be kept in a MySQL database (user information, stories, comments, and categories).&lt;br /&gt;
&lt;br /&gt;
=== Web Security and Validation ===&lt;br /&gt;
&lt;br /&gt;
Your project needs to demonstrate that thought was put into web security and best practice.  For more information, see this week's Web Application Security guide: [[Web Application Security, Part 2]]&lt;br /&gt;
&lt;br /&gt;
In particular:&lt;br /&gt;
&lt;br /&gt;
* '''Your application needs to be secure from SQL injection attacks'''. If you are using prepared queries, you should already be safe on this front.&lt;br /&gt;
* '''All of your output needs to be sanitized using htmlentities()'''.&lt;br /&gt;
&lt;br /&gt;
You shouldn't forget the practices you learned last week:&lt;br /&gt;
&lt;br /&gt;
* '''You should pass tokens in forms''' to prevent CSRF attacks.&lt;br /&gt;
* '''Your page should validate''' with no errors through the W3C validator.&lt;br /&gt;
&lt;br /&gt;
== Grading ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;font-size:2em; line-height:2em;&amp;quot;&amp;gt;'''Due Date: Wednesday October 10th, by 1pm (both individual and group)'''&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
!Assignment&lt;br /&gt;
!Points&lt;br /&gt;
|-&lt;br /&gt;
|Tables Correct&lt;br /&gt;
|2&lt;br /&gt;
|-&lt;br /&gt;
|Data Queries Correct&lt;br /&gt;
|2&lt;br /&gt;
|-&lt;br /&gt;
!colspan=&amp;quot;2&amp;quot;|Group Portion:&lt;br /&gt;
|-&lt;br /&gt;
|User Authentication&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|User Registration&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Secure Password&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Main page displays all stories (or most recent stories)&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Page with individual story and comments&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Story Submission&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Comment System&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Administrator Deletion of Stories/Comments&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|User Edit of Story/Comment&lt;br /&gt;
|2&lt;br /&gt;
|-&lt;br /&gt;
|Protect Against SQL Injection Attack&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Sanitize Output&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Older Web Security Practices and Validation&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Creative Portion&lt;br /&gt;
|2&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
[[Category:Module 3]]&lt;br /&gt;
[[Category:Modules]]&lt;/div&gt;</summary>
		<author><name>Marc</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=Module_3&amp;diff=678</id>
		<title>Module 3</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=Module_3&amp;diff=678"/>
		<updated>2012-09-21T15:31:57Z</updated>

		<summary type="html">&lt;p&gt;Marc: /* Requirements */  Added link to MD5 page&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In Module 3, you will learn about MySQL, a web application database.&lt;br /&gt;
&lt;br /&gt;
This article contains your assignments for Module 3.&lt;br /&gt;
&lt;br /&gt;
== Individual Assignments ==&lt;br /&gt;
&lt;br /&gt;
You will create a simple grades database containing four tables.&lt;br /&gt;
&lt;br /&gt;
'''IMPORTANT:''' The individual assignment is to be done by writing queries by hand.  (You can use phpMyAdmin to run the queries, but '''do not let phpMyAdmin write your queries for you!''')  Writing your own queries gives you a greater understanding of the underlying mechanisms and databases in general.  Additionally, having SQL knowledge and experience is a very marketable trait.&lt;br /&gt;
&lt;br /&gt;
=== Install MySQL and phpMyAdmin ===&lt;br /&gt;
&lt;br /&gt;
Before you start, '''you need to install MySQL''' on your EC2 instance.  You may also install phpMyAdmin, a web frontend to MySQL, if you choose to do so.&lt;br /&gt;
&lt;br /&gt;
You may find the following article to be very helpful: [[Introduction to MySQL]]&lt;br /&gt;
&lt;br /&gt;
=== Set Up a Database ===&lt;br /&gt;
&lt;br /&gt;
You may find the following article to be very helpful: [[Introduction to MySQL]]&lt;br /&gt;
&lt;br /&gt;
# Create a database named '''wustl''' &lt;br /&gt;
# Create a user named '''wustl_inst''' and give them the password '''wustl_pass'''&lt;br /&gt;
&lt;br /&gt;
=== Create Tables ===&lt;br /&gt;
&lt;br /&gt;
You may find the following article to be very helpful: [[MySQL Schema and State]]&lt;br /&gt;
&lt;br /&gt;
When creating tables, keep the following items in mind:&lt;br /&gt;
&lt;br /&gt;
* You should create all tables such that they use the InnoDB storage engine, since we wish to make use of its support of foreign keys. In other database engines, foreign key constraints are not enforced.  (If you mess up, you can use ALTER TABLE to change the storage engine.)&lt;br /&gt;
* Where it is appropriate, you should take advantage of the ability to define fields NOT NULL so that you do not inadvertently insert incomplete data for a row.&lt;br /&gt;
&lt;br /&gt;
Create the following tables:&lt;br /&gt;
&lt;br /&gt;
# Create a table named '''students''' with the following fields:&lt;br /&gt;
#* '''id''' of an appropriately-sized unsigned integer type (we will never need to process more than a million students)&lt;br /&gt;
#* '''first_name''' of type '''VARCHAR(50)'''&lt;br /&gt;
#* '''last_name''' of type '''VARCHAR(50)'''&lt;br /&gt;
#* '''email_address''' of type '''VARCHAR(50)'''&lt;br /&gt;
#: The primary key should be on the '''id''' field.&lt;br /&gt;
# Create a table named '''departments''' with the following fields:&lt;br /&gt;
#* '''school_code''' of type '''ENUM''' (e.g. &amp;quot;L&amp;quot; for ArtSci and &amp;quot;E&amp;quot; for Engineering).  The options are as follows:&lt;br /&gt;
#*: 'L', 'B', 'A', 'F', 'E', 'T', 'I', 'W', 'S', 'U', 'M'&lt;br /&gt;
#* '''dept_id''' of an appropriately-sized unsigned integer type (in the foreseeable future there will never be more than 200 departments in a school)&lt;br /&gt;
#* '''abbreviation''' of type '''VARCHAR(9)''' (e.g. CSE, ChemE, etc)&lt;br /&gt;
#* '''dept_name''' of type '''VARCHAR(200)''' (e.g. Computer Science and Engineering)&lt;br /&gt;
#: The primary key should be on two fields: '''school_code''' and '''dept_id'''&lt;br /&gt;
#: '''Note:''' Why not just use the department ID? The ID numbers are sometimes reused across schools. For instance, department 33 in The School of Arts and Sciences is Psychology while department 33 in The School of Engineering and Applied Sciences is Energy, Environmental and Chemical Engineering. Thus we must also include the school code to differentiate them  such that the record for  E33 is distinct from that of L33.&lt;br /&gt;
# Create a table named '''courses''' with the following fields:&lt;br /&gt;
#* '''school_code''' of type '''ENUM'''&lt;br /&gt;
#*: This should have the same letters in the same order as the '''school_code''' '''ENUM''' field in the '''departments''' table.&lt;br /&gt;
#* '''dept_id''' of the same size of integer as in the '''departments''' table&lt;br /&gt;
#* '''course_code''' of type '''CHAR(5)''' (this will hold course codes; e.g., '330S', '131', '2960')&lt;br /&gt;
#* '''name''' of type '''VARCHAR(150)'''&lt;br /&gt;
#: The appropriate fields in this table should make a foreign key reference to the corresponding fields in '''department'''.&lt;br /&gt;
#: In addition, it is up to you to determine the field(s) for the primary key.&lt;br /&gt;
#: '''Note:''' If you are unsure which fields to make the foreign keys and feel the need to beg your friends or the TAs to give you the answer, bang your head on your desk whilst repeating &amp;quot;I WILL EXERCISE REASON AND COMMON SENSE AND I WILL CURTAIL MY DESIRE TO BLINDLY FOLLOW DIRECTIONS&amp;quot;&lt;br /&gt;
#: ''Disclaimer: don't actually bang your head on your desk, the resulting head trauma may in fact make it harder for you to determine which fields should have associated foreign keys.''&lt;br /&gt;
# Create a table named '''grades''' with the following fields:&lt;br /&gt;
#* '''pk_grade_ID''' of an appropriately-sized unsigned integer type (should be larger than the one you chose for the '''students''' table)&lt;br /&gt;
#*: You should declare this field to be '''auto_increment''' and make it the primary key.&lt;br /&gt;
#*: This is called a ''surrogate key'' as opposed to a ''natural key'' because it doesn't arise &amp;quot;naturally&amp;quot; from the data; that is to say that it is not derived from application data. The use of surrogate keys vs. natural keys is a polemic issue amongst database designers.  For a decently unbiased take on the issue, see this page: http://www.agiledata.org/essays/keys.html#Comparison&lt;br /&gt;
#*: '''Food for thought:''' Aside from simply exposing you to the concept, can you think of any reasons why a surrogate key might be preferable for this table?  Alternatively, what attributes, if any, could you use as a natural key, and what might be the drawbacks of doing so?&lt;br /&gt;
#* '''student_id''' of the same integer (unsigned) type that you chose in the '''students''' table&lt;br /&gt;
#* '''grade''' of type '''decimal'''&lt;br /&gt;
#* '''school_code''' of type '''ENUM'''&lt;br /&gt;
#*: Can you guess what entries to use for the enum?&lt;br /&gt;
#* '''dept_id''' of the same integer type that you've used for this field in other tables&lt;br /&gt;
#* '''course_code''' of the same type you chose for the course code in the '''courses''' table&lt;br /&gt;
#: The '''grades''' table should have foreign keys to both the '''students''' table and the '''courses''' table.&lt;br /&gt;
&lt;br /&gt;
=== Populate Tables ===&lt;br /&gt;
&lt;br /&gt;
Now, populate the tables by downloading the text files given below and loading them into the appropriate tables.&lt;br /&gt;
&lt;br /&gt;
'''Note:''' Do not insert all the values manually; instead, use the MySQL's ability to load in data from text files.&lt;br /&gt;
&lt;br /&gt;
You may find the following article to be very helpful: [[MySQL Schema and State]]&lt;br /&gt;
&lt;br /&gt;
The files containing the data are:&lt;br /&gt;
&lt;br /&gt;
* students: https://docs.google.com/file/d/0ByHgvetJ0GJyMGFjMWI4MzAtMzljYy00Yjk3LTllMWItZjZkYmU1NzU3NWU0/edit&lt;br /&gt;
* courses: https://docs.google.com/file/d/0ByHgvetJ0GJyMGY1NGYzYmUtNGQwYi00MTY3LTkzMjgtMDYwOTM3NDNjZTg4/edit&lt;br /&gt;
* departments: https://docs.google.com/file/d/0ByHgvetJ0GJyZWY2OWE4ZWEtYzVmMC00YjBiLWEzZjgtYzdhMDczODAyNDli/edit&lt;br /&gt;
* grades: https://docs.google.com/file/d/0ByHgvetJ0GJyZmJjNzllNjAtMzdhZC00MzU5LTg3MDYtMTRmMjE5MDE2MzY2/edit&lt;br /&gt;
&lt;br /&gt;
=== Insert More Data ===&lt;br /&gt;
&lt;br /&gt;
Insert the following data into the tables that you have created and populated:&lt;br /&gt;
&lt;br /&gt;
# Insert an entry for CSE 330&lt;br /&gt;
#: ''If you don't know CSE's department code, how can you find out using the tables in the database?''&lt;br /&gt;
# Insert the grades given for the students named below.  You may choose to make the entries for whichever classes you like, with the one condition that all of the students must have a grade for CSE 330 (who wouldn't want to take that class: I hear the professor and TAs are amazing!)&lt;br /&gt;
#* '''Ben Harper'''&lt;br /&gt;
#** E-mail: '''bharper@ffym.com'''&lt;br /&gt;
#** Student ID: '''88'''&lt;br /&gt;
#** Grades:&lt;br /&gt;
#*** 5.5&lt;br /&gt;
#*** 0&lt;br /&gt;
#*** 20&lt;br /&gt;
#* '''Matt Freeman'''&lt;br /&gt;
#** E-mail: '''mfreeman@kickinbassist.net'''&lt;br /&gt;
#** Student ID: '''202'''&lt;br /&gt;
#** Grades:&lt;br /&gt;
#*** 100&lt;br /&gt;
#*** 90.5&lt;br /&gt;
#*** 94.8&lt;br /&gt;
#* '''Marc Roberge'''&lt;br /&gt;
#** E-mail: '''mroberge@ofarevolution.us'''&lt;br /&gt;
#** Student ID: '''115'''&lt;br /&gt;
#** Grades:&lt;br /&gt;
#*** 15&lt;br /&gt;
#*** 37&lt;br /&gt;
#*** 45.5&lt;br /&gt;
#: You may choose any 3 classes you'd like for them to be enrolled in, with at least one class, &amp;quot;CSE 330S&amp;quot;, in which they are all enrolled.&lt;br /&gt;
&lt;br /&gt;
=== Querying Your Database ===&lt;br /&gt;
&lt;br /&gt;
Now that you have a fully-functional, populated database, let's do some queries on it!&lt;br /&gt;
&lt;br /&gt;
Write the following '''select''' queries and then run them for a TA:&lt;br /&gt;
&lt;br /&gt;
# Select the entire grades table.&lt;br /&gt;
# Select all fields describing the courses offered in the school of arts and sciences (school code L).&lt;br /&gt;
# The names, student IDs, and grades of the students who are in CSE330.&lt;br /&gt;
# The names and e-mails of any student with an average below 50 so that the dean can send them an email notification that they are now on academic probation.&lt;br /&gt;
#: ''You should be able to do this in only one query, without making any temporary tables.  You will need to use aggregation functions and the '''having''' keyword.''&lt;br /&gt;
# An individual report card for Jack Johnson, consisting of two tables (these can be done using separate queries):&lt;br /&gt;
## His student ID, e-mail address, and average grade.&lt;br /&gt;
##: ''Again, you should be able to do this in just one query, using the correct combination of aggregation functions and joins.''&lt;br /&gt;
## The classes he is in and his grades for those classes. To give you an idea, one row in the table should look like this:&lt;br /&gt;
##: &amp;lt;code&amp;gt;E	81	400	Independent Study	98.5&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Group Project ==&lt;br /&gt;
&lt;br /&gt;
You will work in pairs on this project.  You may work with the same partner from Module 2, or change to someone else.&lt;br /&gt;
&lt;br /&gt;
'''Important Reminder:''' frequently commit your work to your subversion repository as a backup!&lt;br /&gt;
&lt;br /&gt;
=== Simple News Web Site ===&lt;br /&gt;
&lt;br /&gt;
'''Examples:'''&lt;br /&gt;
* http://digg.com/&lt;br /&gt;
* http://slashdot.org/&lt;br /&gt;
&lt;br /&gt;
You should use '''PHP''' unless you get permission to use another web technology from the instructor.  You may also use phpMyAdmin to help set up databases.&lt;br /&gt;
&lt;br /&gt;
You may find this wiki article helpful: [[PHP and MySQL]]&lt;br /&gt;
&lt;br /&gt;
==== Requirements ====&lt;br /&gt;
&lt;br /&gt;
* Users can register for accounts and then log in to the website.&lt;br /&gt;
* Accounts should have both a username and a ''secure'' password.  '''NEVER store plaintext passwords in a database!'''&lt;br /&gt;
*: For more information on password security, refer to [[Web Application Security, Part 2#Password Security|the Web Application Security guide]].&lt;br /&gt;
*: You may also want to refer to http://php.net/manual/en/function.md5.php for information on md5.  &lt;br /&gt;
* Registered users can submit stories: either a link with summary or news text.&lt;br /&gt;
*: You do not have to make a distinction between the two types of stories, although if you want to, you could do something with this for the creative portion of your project.&lt;br /&gt;
* Registered users can comment on any story.&lt;br /&gt;
* Administrator users can delete stories and comments.&lt;br /&gt;
* Unregistered users can only view stories and comments.&lt;br /&gt;
* Registered users can edit their stories and can delete their comments.&lt;br /&gt;
* All data must be kept in a MySQL database (user information, stories, comments, and categories).&lt;br /&gt;
&lt;br /&gt;
=== Web Security and Validation ===&lt;br /&gt;
&lt;br /&gt;
Your project needs to demonstrate that thought was put into web security and best practice.  For more information, see this week's Web Application Security guide: [[Web Application Security, Part 2]]&lt;br /&gt;
&lt;br /&gt;
In particular:&lt;br /&gt;
&lt;br /&gt;
* '''Your application needs to be secure from SQL injection attacks'''. If you are using prepared queries, you should already be safe on this front.&lt;br /&gt;
* '''All of your output needs to be sanitized using htmlentities()'''.&lt;br /&gt;
&lt;br /&gt;
You shouldn't forget the practices you learned last week:&lt;br /&gt;
&lt;br /&gt;
* '''You should pass tokens in forms''' to prevent CSRF attacks.&lt;br /&gt;
* '''Your page should validate''' with no errors through the W3C validator.&lt;br /&gt;
&lt;br /&gt;
== Grading ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;font-size:2em; line-height:2em;&amp;quot;&amp;gt;'''Due Date: _____ (both individual and group)'''&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
!Assignment&lt;br /&gt;
!Points&lt;br /&gt;
|-&lt;br /&gt;
|Tables Correct&lt;br /&gt;
|2&lt;br /&gt;
|-&lt;br /&gt;
|Data Queries Correct&lt;br /&gt;
|2&lt;br /&gt;
|-&lt;br /&gt;
!colspan=&amp;quot;2&amp;quot;|Group Portion:&lt;br /&gt;
|-&lt;br /&gt;
|User Authentication&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|User Registration&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Secure Password&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Main page displays all stories (or most recent stories)&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Page with individual story and comments&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Story Submission&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Comment System&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Administrator Deletion of Stories/Comments&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|User Edit of Story/Comment&lt;br /&gt;
|2&lt;br /&gt;
|-&lt;br /&gt;
|Protect Against SQL Injection Attack&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Sanitize Output&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Older Web Security Practices and Validation&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Creative Portion&lt;br /&gt;
|2&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
[[Category:Module 3]]&lt;br /&gt;
[[Category:Modules]]&lt;/div&gt;</summary>
		<author><name>Marc</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=Module_3&amp;diff=677</id>
		<title>Module 3</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=Module_3&amp;diff=677"/>
		<updated>2012-09-21T15:26:03Z</updated>

		<summary type="html">&lt;p&gt;Marc: /* Grading */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In Module 3, you will learn about MySQL, a web application database.&lt;br /&gt;
&lt;br /&gt;
This article contains your assignments for Module 3.&lt;br /&gt;
&lt;br /&gt;
== Individual Assignments ==&lt;br /&gt;
&lt;br /&gt;
You will create a simple grades database containing four tables.&lt;br /&gt;
&lt;br /&gt;
'''IMPORTANT:''' The individual assignment is to be done by writing queries by hand.  (You can use phpMyAdmin to run the queries, but '''do not let phpMyAdmin write your queries for you!''')  Writing your own queries gives you a greater understanding of the underlying mechanisms and databases in general.  Additionally, having SQL knowledge and experience is a very marketable trait.&lt;br /&gt;
&lt;br /&gt;
=== Install MySQL and phpMyAdmin ===&lt;br /&gt;
&lt;br /&gt;
Before you start, '''you need to install MySQL''' on your EC2 instance.  You may also install phpMyAdmin, a web frontend to MySQL, if you choose to do so.&lt;br /&gt;
&lt;br /&gt;
You may find the following article to be very helpful: [[Introduction to MySQL]]&lt;br /&gt;
&lt;br /&gt;
=== Set Up a Database ===&lt;br /&gt;
&lt;br /&gt;
You may find the following article to be very helpful: [[Introduction to MySQL]]&lt;br /&gt;
&lt;br /&gt;
# Create a database named '''wustl''' &lt;br /&gt;
# Create a user named '''wustl_inst''' and give them the password '''wustl_pass'''&lt;br /&gt;
&lt;br /&gt;
=== Create Tables ===&lt;br /&gt;
&lt;br /&gt;
You may find the following article to be very helpful: [[MySQL Schema and State]]&lt;br /&gt;
&lt;br /&gt;
When creating tables, keep the following items in mind:&lt;br /&gt;
&lt;br /&gt;
* You should create all tables such that they use the InnoDB storage engine, since we wish to make use of its support of foreign keys. In other database engines, foreign key constraints are not enforced.  (If you mess up, you can use ALTER TABLE to change the storage engine.)&lt;br /&gt;
* Where it is appropriate, you should take advantage of the ability to define fields NOT NULL so that you do not inadvertently insert incomplete data for a row.&lt;br /&gt;
&lt;br /&gt;
Create the following tables:&lt;br /&gt;
&lt;br /&gt;
# Create a table named '''students''' with the following fields:&lt;br /&gt;
#* '''id''' of an appropriately-sized unsigned integer type (we will never need to process more than a million students)&lt;br /&gt;
#* '''first_name''' of type '''VARCHAR(50)'''&lt;br /&gt;
#* '''last_name''' of type '''VARCHAR(50)'''&lt;br /&gt;
#* '''email_address''' of type '''VARCHAR(50)'''&lt;br /&gt;
#: The primary key should be on the '''id''' field.&lt;br /&gt;
# Create a table named '''departments''' with the following fields:&lt;br /&gt;
#* '''school_code''' of type '''ENUM''' (e.g. &amp;quot;L&amp;quot; for ArtSci and &amp;quot;E&amp;quot; for Engineering).  The options are as follows:&lt;br /&gt;
#*: 'L', 'B', 'A', 'F', 'E', 'T', 'I', 'W', 'S', 'U', 'M'&lt;br /&gt;
#* '''dept_id''' of an appropriately-sized unsigned integer type (in the foreseeable future there will never be more than 200 departments in a school)&lt;br /&gt;
#* '''abbreviation''' of type '''VARCHAR(9)''' (e.g. CSE, ChemE, etc)&lt;br /&gt;
#* '''dept_name''' of type '''VARCHAR(200)''' (e.g. Computer Science and Engineering)&lt;br /&gt;
#: The primary key should be on two fields: '''school_code''' and '''dept_id'''&lt;br /&gt;
#: '''Note:''' Why not just use the department ID? The ID numbers are sometimes reused across schools. For instance, department 33 in The School of Arts and Sciences is Psychology while department 33 in The School of Engineering and Applied Sciences is Energy, Environmental and Chemical Engineering. Thus we must also include the school code to differentiate them  such that the record for  E33 is distinct from that of L33.&lt;br /&gt;
# Create a table named '''courses''' with the following fields:&lt;br /&gt;
#* '''school_code''' of type '''ENUM'''&lt;br /&gt;
#*: This should have the same letters in the same order as the '''school_code''' '''ENUM''' field in the '''departments''' table.&lt;br /&gt;
#* '''dept_id''' of the same size of integer as in the '''departments''' table&lt;br /&gt;
#* '''course_code''' of type '''CHAR(5)''' (this will hold course codes; e.g., '330S', '131', '2960')&lt;br /&gt;
#* '''name''' of type '''VARCHAR(150)'''&lt;br /&gt;
#: The appropriate fields in this table should make a foreign key reference to the corresponding fields in '''department'''.&lt;br /&gt;
#: In addition, it is up to you to determine the field(s) for the primary key.&lt;br /&gt;
#: '''Note:''' If you are unsure which fields to make the foreign keys and feel the need to beg your friends or the TAs to give you the answer, bang your head on your desk whilst repeating &amp;quot;I WILL EXERCISE REASON AND COMMON SENSE AND I WILL CURTAIL MY DESIRE TO BLINDLY FOLLOW DIRECTIONS&amp;quot;&lt;br /&gt;
#: ''Disclaimer: don't actually bang your head on your desk, the resulting head trauma may in fact make it harder for you to determine which fields should have associated foreign keys.''&lt;br /&gt;
# Create a table named '''grades''' with the following fields:&lt;br /&gt;
#* '''pk_grade_ID''' of an appropriately-sized unsigned integer type (should be larger than the one you chose for the '''students''' table)&lt;br /&gt;
#*: You should declare this field to be '''auto_increment''' and make it the primary key.&lt;br /&gt;
#*: This is called a ''surrogate key'' as opposed to a ''natural key'' because it doesn't arise &amp;quot;naturally&amp;quot; from the data; that is to say that it is not derived from application data. The use of surrogate keys vs. natural keys is a polemic issue amongst database designers.  For a decently unbiased take on the issue, see this page: http://www.agiledata.org/essays/keys.html#Comparison&lt;br /&gt;
#*: '''Food for thought:''' Aside from simply exposing you to the concept, can you think of any reasons why a surrogate key might be preferable for this table?  Alternatively, what attributes, if any, could you use as a natural key, and what might be the drawbacks of doing so?&lt;br /&gt;
#* '''student_id''' of the same integer (unsigned) type that you chose in the '''students''' table&lt;br /&gt;
#* '''grade''' of type '''decimal'''&lt;br /&gt;
#* '''school_code''' of type '''ENUM'''&lt;br /&gt;
#*: Can you guess what entries to use for the enum?&lt;br /&gt;
#* '''dept_id''' of the same integer type that you've used for this field in other tables&lt;br /&gt;
#* '''course_code''' of the same type you chose for the course code in the '''courses''' table&lt;br /&gt;
#: The '''grades''' table should have foreign keys to both the '''students''' table and the '''courses''' table.&lt;br /&gt;
&lt;br /&gt;
=== Populate Tables ===&lt;br /&gt;
&lt;br /&gt;
Now, populate the tables by downloading the text files given below and loading them into the appropriate tables.&lt;br /&gt;
&lt;br /&gt;
'''Note:''' Do not insert all the values manually; instead, use the MySQL's ability to load in data from text files.&lt;br /&gt;
&lt;br /&gt;
You may find the following article to be very helpful: [[MySQL Schema and State]]&lt;br /&gt;
&lt;br /&gt;
The files containing the data are:&lt;br /&gt;
&lt;br /&gt;
* students: https://docs.google.com/file/d/0ByHgvetJ0GJyMGFjMWI4MzAtMzljYy00Yjk3LTllMWItZjZkYmU1NzU3NWU0/edit&lt;br /&gt;
* courses: https://docs.google.com/file/d/0ByHgvetJ0GJyMGY1NGYzYmUtNGQwYi00MTY3LTkzMjgtMDYwOTM3NDNjZTg4/edit&lt;br /&gt;
* departments: https://docs.google.com/file/d/0ByHgvetJ0GJyZWY2OWE4ZWEtYzVmMC00YjBiLWEzZjgtYzdhMDczODAyNDli/edit&lt;br /&gt;
* grades: https://docs.google.com/file/d/0ByHgvetJ0GJyZmJjNzllNjAtMzdhZC00MzU5LTg3MDYtMTRmMjE5MDE2MzY2/edit&lt;br /&gt;
&lt;br /&gt;
=== Insert More Data ===&lt;br /&gt;
&lt;br /&gt;
Insert the following data into the tables that you have created and populated:&lt;br /&gt;
&lt;br /&gt;
# Insert an entry for CSE 330&lt;br /&gt;
#: ''If you don't know CSE's department code, how can you find out using the tables in the database?''&lt;br /&gt;
# Insert the grades given for the students named below.  You may choose to make the entries for whichever classes you like, with the one condition that all of the students must have a grade for CSE 330 (who wouldn't want to take that class: I hear the professor and TAs are amazing!)&lt;br /&gt;
#* '''Ben Harper'''&lt;br /&gt;
#** E-mail: '''bharper@ffym.com'''&lt;br /&gt;
#** Student ID: '''88'''&lt;br /&gt;
#** Grades:&lt;br /&gt;
#*** 5.5&lt;br /&gt;
#*** 0&lt;br /&gt;
#*** 20&lt;br /&gt;
#* '''Matt Freeman'''&lt;br /&gt;
#** E-mail: '''mfreeman@kickinbassist.net'''&lt;br /&gt;
#** Student ID: '''202'''&lt;br /&gt;
#** Grades:&lt;br /&gt;
#*** 100&lt;br /&gt;
#*** 90.5&lt;br /&gt;
#*** 94.8&lt;br /&gt;
#* '''Marc Roberge'''&lt;br /&gt;
#** E-mail: '''mroberge@ofarevolution.us'''&lt;br /&gt;
#** Student ID: '''115'''&lt;br /&gt;
#** Grades:&lt;br /&gt;
#*** 15&lt;br /&gt;
#*** 37&lt;br /&gt;
#*** 45.5&lt;br /&gt;
#: You may choose any 3 classes you'd like for them to be enrolled in, with at least one class, &amp;quot;CSE 330S&amp;quot;, in which they are all enrolled.&lt;br /&gt;
&lt;br /&gt;
=== Querying Your Database ===&lt;br /&gt;
&lt;br /&gt;
Now that you have a fully-functional, populated database, let's do some queries on it!&lt;br /&gt;
&lt;br /&gt;
Write the following '''select''' queries and then run them for a TA:&lt;br /&gt;
&lt;br /&gt;
# Select the entire grades table.&lt;br /&gt;
# Select all fields describing the courses offered in the school of arts and sciences (school code L).&lt;br /&gt;
# The names, student IDs, and grades of the students who are in CSE330.&lt;br /&gt;
# The names and e-mails of any student with an average below 50 so that the dean can send them an email notification that they are now on academic probation.&lt;br /&gt;
#: ''You should be able to do this in only one query, without making any temporary tables.  You will need to use aggregation functions and the '''having''' keyword.''&lt;br /&gt;
# An individual report card for Jack Johnson, consisting of two tables (these can be done using separate queries):&lt;br /&gt;
## His student ID, e-mail address, and average grade.&lt;br /&gt;
##: ''Again, you should be able to do this in just one query, using the correct combination of aggregation functions and joins.''&lt;br /&gt;
## The classes he is in and his grades for those classes. To give you an idea, one row in the table should look like this:&lt;br /&gt;
##: &amp;lt;code&amp;gt;E	81	400	Independent Study	98.5&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Group Project ==&lt;br /&gt;
&lt;br /&gt;
You will work in pairs on this project.  You may work with the same partner from Module 2, or change to someone else.&lt;br /&gt;
&lt;br /&gt;
'''Important Reminder:''' frequently commit your work to your subversion repository as a backup!&lt;br /&gt;
&lt;br /&gt;
=== Simple News Web Site ===&lt;br /&gt;
&lt;br /&gt;
'''Examples:'''&lt;br /&gt;
* http://digg.com/&lt;br /&gt;
* http://slashdot.org/&lt;br /&gt;
&lt;br /&gt;
You should use '''PHP''' unless you get permission to use another web technology from the instructor.  You may also use phpMyAdmin to help set up databases.&lt;br /&gt;
&lt;br /&gt;
You may find this wiki article helpful: [[PHP and MySQL]]&lt;br /&gt;
&lt;br /&gt;
==== Requirements ====&lt;br /&gt;
&lt;br /&gt;
* Users can register for accounts and then log in to the website.&lt;br /&gt;
* Accounts should have both a username and a ''secure'' password.  '''NEVER store plaintext passwords in a database!'''&lt;br /&gt;
*: For more information on password security, refer to [[Web Application Security, Part 2#Password Security|the Web Application Security guide]].&lt;br /&gt;
* Registered users can submit stories: either a link with summary or news text.&lt;br /&gt;
*: You do not have to make a distinction between the two types of stories, although if you want to, you could do something with this for the creative portion of your project.&lt;br /&gt;
* Registered users can comment on any story.&lt;br /&gt;
* Administrator users can delete stories and comments.&lt;br /&gt;
* Unregistered users can only view stories and comments.&lt;br /&gt;
* Registered users can edit their stories and can delete their comments.&lt;br /&gt;
* All data must be kept in a MySQL database (user information, stories, comments, and categories).&lt;br /&gt;
&lt;br /&gt;
=== Web Security and Validation ===&lt;br /&gt;
&lt;br /&gt;
Your project needs to demonstrate that thought was put into web security and best practice.  For more information, see this week's Web Application Security guide: [[Web Application Security, Part 2]]&lt;br /&gt;
&lt;br /&gt;
In particular:&lt;br /&gt;
&lt;br /&gt;
* '''Your application needs to be secure from SQL injection attacks'''. If you are using prepared queries, you should already be safe on this front.&lt;br /&gt;
* '''All of your output needs to be sanitized using htmlentities()'''.&lt;br /&gt;
&lt;br /&gt;
You shouldn't forget the practices you learned last week:&lt;br /&gt;
&lt;br /&gt;
* '''You should pass tokens in forms''' to prevent CSRF attacks.&lt;br /&gt;
* '''Your page should validate''' with no errors through the W3C validator.&lt;br /&gt;
&lt;br /&gt;
== Grading ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;font-size:2em; line-height:2em;&amp;quot;&amp;gt;'''Due Date: _____ (both individual and group)'''&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
!Assignment&lt;br /&gt;
!Points&lt;br /&gt;
|-&lt;br /&gt;
|Tables Correct&lt;br /&gt;
|2&lt;br /&gt;
|-&lt;br /&gt;
|Data Queries Correct&lt;br /&gt;
|2&lt;br /&gt;
|-&lt;br /&gt;
!colspan=&amp;quot;2&amp;quot;|Group Portion:&lt;br /&gt;
|-&lt;br /&gt;
|User Authentication&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|User Registration&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Secure Password&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Main page displays all stories (or most recent stories)&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Page with individual story and comments&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Story Submission&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Comment System&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Administrator Deletion of Stories/Comments&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|User Edit of Story/Comment&lt;br /&gt;
|2&lt;br /&gt;
|-&lt;br /&gt;
|Protect Against SQL Injection Attack&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Sanitize Output&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Older Web Security Practices and Validation&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Creative Portion&lt;br /&gt;
|2&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
[[Category:Module 3]]&lt;br /&gt;
[[Category:Modules]]&lt;/div&gt;</summary>
		<author><name>Marc</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=Module_3&amp;diff=676</id>
		<title>Module 3</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=Module_3&amp;diff=676"/>
		<updated>2012-09-21T15:25:12Z</updated>

		<summary type="html">&lt;p&gt;Marc: /* Requirements */   removed requirement to implement your own authentication system&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In Module 3, you will learn about MySQL, a web application database.&lt;br /&gt;
&lt;br /&gt;
This article contains your assignments for Module 3.&lt;br /&gt;
&lt;br /&gt;
== Individual Assignments ==&lt;br /&gt;
&lt;br /&gt;
You will create a simple grades database containing four tables.&lt;br /&gt;
&lt;br /&gt;
'''IMPORTANT:''' The individual assignment is to be done by writing queries by hand.  (You can use phpMyAdmin to run the queries, but '''do not let phpMyAdmin write your queries for you!''')  Writing your own queries gives you a greater understanding of the underlying mechanisms and databases in general.  Additionally, having SQL knowledge and experience is a very marketable trait.&lt;br /&gt;
&lt;br /&gt;
=== Install MySQL and phpMyAdmin ===&lt;br /&gt;
&lt;br /&gt;
Before you start, '''you need to install MySQL''' on your EC2 instance.  You may also install phpMyAdmin, a web frontend to MySQL, if you choose to do so.&lt;br /&gt;
&lt;br /&gt;
You may find the following article to be very helpful: [[Introduction to MySQL]]&lt;br /&gt;
&lt;br /&gt;
=== Set Up a Database ===&lt;br /&gt;
&lt;br /&gt;
You may find the following article to be very helpful: [[Introduction to MySQL]]&lt;br /&gt;
&lt;br /&gt;
# Create a database named '''wustl''' &lt;br /&gt;
# Create a user named '''wustl_inst''' and give them the password '''wustl_pass'''&lt;br /&gt;
&lt;br /&gt;
=== Create Tables ===&lt;br /&gt;
&lt;br /&gt;
You may find the following article to be very helpful: [[MySQL Schema and State]]&lt;br /&gt;
&lt;br /&gt;
When creating tables, keep the following items in mind:&lt;br /&gt;
&lt;br /&gt;
* You should create all tables such that they use the InnoDB storage engine, since we wish to make use of its support of foreign keys. In other database engines, foreign key constraints are not enforced.  (If you mess up, you can use ALTER TABLE to change the storage engine.)&lt;br /&gt;
* Where it is appropriate, you should take advantage of the ability to define fields NOT NULL so that you do not inadvertently insert incomplete data for a row.&lt;br /&gt;
&lt;br /&gt;
Create the following tables:&lt;br /&gt;
&lt;br /&gt;
# Create a table named '''students''' with the following fields:&lt;br /&gt;
#* '''id''' of an appropriately-sized unsigned integer type (we will never need to process more than a million students)&lt;br /&gt;
#* '''first_name''' of type '''VARCHAR(50)'''&lt;br /&gt;
#* '''last_name''' of type '''VARCHAR(50)'''&lt;br /&gt;
#* '''email_address''' of type '''VARCHAR(50)'''&lt;br /&gt;
#: The primary key should be on the '''id''' field.&lt;br /&gt;
# Create a table named '''departments''' with the following fields:&lt;br /&gt;
#* '''school_code''' of type '''ENUM''' (e.g. &amp;quot;L&amp;quot; for ArtSci and &amp;quot;E&amp;quot; for Engineering).  The options are as follows:&lt;br /&gt;
#*: 'L', 'B', 'A', 'F', 'E', 'T', 'I', 'W', 'S', 'U', 'M'&lt;br /&gt;
#* '''dept_id''' of an appropriately-sized unsigned integer type (in the foreseeable future there will never be more than 200 departments in a school)&lt;br /&gt;
#* '''abbreviation''' of type '''VARCHAR(9)''' (e.g. CSE, ChemE, etc)&lt;br /&gt;
#* '''dept_name''' of type '''VARCHAR(200)''' (e.g. Computer Science and Engineering)&lt;br /&gt;
#: The primary key should be on two fields: '''school_code''' and '''dept_id'''&lt;br /&gt;
#: '''Note:''' Why not just use the department ID? The ID numbers are sometimes reused across schools. For instance, department 33 in The School of Arts and Sciences is Psychology while department 33 in The School of Engineering and Applied Sciences is Energy, Environmental and Chemical Engineering. Thus we must also include the school code to differentiate them  such that the record for  E33 is distinct from that of L33.&lt;br /&gt;
# Create a table named '''courses''' with the following fields:&lt;br /&gt;
#* '''school_code''' of type '''ENUM'''&lt;br /&gt;
#*: This should have the same letters in the same order as the '''school_code''' '''ENUM''' field in the '''departments''' table.&lt;br /&gt;
#* '''dept_id''' of the same size of integer as in the '''departments''' table&lt;br /&gt;
#* '''course_code''' of type '''CHAR(5)''' (this will hold course codes; e.g., '330S', '131', '2960')&lt;br /&gt;
#* '''name''' of type '''VARCHAR(150)'''&lt;br /&gt;
#: The appropriate fields in this table should make a foreign key reference to the corresponding fields in '''department'''.&lt;br /&gt;
#: In addition, it is up to you to determine the field(s) for the primary key.&lt;br /&gt;
#: '''Note:''' If you are unsure which fields to make the foreign keys and feel the need to beg your friends or the TAs to give you the answer, bang your head on your desk whilst repeating &amp;quot;I WILL EXERCISE REASON AND COMMON SENSE AND I WILL CURTAIL MY DESIRE TO BLINDLY FOLLOW DIRECTIONS&amp;quot;&lt;br /&gt;
#: ''Disclaimer: don't actually bang your head on your desk, the resulting head trauma may in fact make it harder for you to determine which fields should have associated foreign keys.''&lt;br /&gt;
# Create a table named '''grades''' with the following fields:&lt;br /&gt;
#* '''pk_grade_ID''' of an appropriately-sized unsigned integer type (should be larger than the one you chose for the '''students''' table)&lt;br /&gt;
#*: You should declare this field to be '''auto_increment''' and make it the primary key.&lt;br /&gt;
#*: This is called a ''surrogate key'' as opposed to a ''natural key'' because it doesn't arise &amp;quot;naturally&amp;quot; from the data; that is to say that it is not derived from application data. The use of surrogate keys vs. natural keys is a polemic issue amongst database designers.  For a decently unbiased take on the issue, see this page: http://www.agiledata.org/essays/keys.html#Comparison&lt;br /&gt;
#*: '''Food for thought:''' Aside from simply exposing you to the concept, can you think of any reasons why a surrogate key might be preferable for this table?  Alternatively, what attributes, if any, could you use as a natural key, and what might be the drawbacks of doing so?&lt;br /&gt;
#* '''student_id''' of the same integer (unsigned) type that you chose in the '''students''' table&lt;br /&gt;
#* '''grade''' of type '''decimal'''&lt;br /&gt;
#* '''school_code''' of type '''ENUM'''&lt;br /&gt;
#*: Can you guess what entries to use for the enum?&lt;br /&gt;
#* '''dept_id''' of the same integer type that you've used for this field in other tables&lt;br /&gt;
#* '''course_code''' of the same type you chose for the course code in the '''courses''' table&lt;br /&gt;
#: The '''grades''' table should have foreign keys to both the '''students''' table and the '''courses''' table.&lt;br /&gt;
&lt;br /&gt;
=== Populate Tables ===&lt;br /&gt;
&lt;br /&gt;
Now, populate the tables by downloading the text files given below and loading them into the appropriate tables.&lt;br /&gt;
&lt;br /&gt;
'''Note:''' Do not insert all the values manually; instead, use the MySQL's ability to load in data from text files.&lt;br /&gt;
&lt;br /&gt;
You may find the following article to be very helpful: [[MySQL Schema and State]]&lt;br /&gt;
&lt;br /&gt;
The files containing the data are:&lt;br /&gt;
&lt;br /&gt;
* students: https://docs.google.com/file/d/0ByHgvetJ0GJyMGFjMWI4MzAtMzljYy00Yjk3LTllMWItZjZkYmU1NzU3NWU0/edit&lt;br /&gt;
* courses: https://docs.google.com/file/d/0ByHgvetJ0GJyMGY1NGYzYmUtNGQwYi00MTY3LTkzMjgtMDYwOTM3NDNjZTg4/edit&lt;br /&gt;
* departments: https://docs.google.com/file/d/0ByHgvetJ0GJyZWY2OWE4ZWEtYzVmMC00YjBiLWEzZjgtYzdhMDczODAyNDli/edit&lt;br /&gt;
* grades: https://docs.google.com/file/d/0ByHgvetJ0GJyZmJjNzllNjAtMzdhZC00MzU5LTg3MDYtMTRmMjE5MDE2MzY2/edit&lt;br /&gt;
&lt;br /&gt;
=== Insert More Data ===&lt;br /&gt;
&lt;br /&gt;
Insert the following data into the tables that you have created and populated:&lt;br /&gt;
&lt;br /&gt;
# Insert an entry for CSE 330&lt;br /&gt;
#: ''If you don't know CSE's department code, how can you find out using the tables in the database?''&lt;br /&gt;
# Insert the grades given for the students named below.  You may choose to make the entries for whichever classes you like, with the one condition that all of the students must have a grade for CSE 330 (who wouldn't want to take that class: I hear the professor and TAs are amazing!)&lt;br /&gt;
#* '''Ben Harper'''&lt;br /&gt;
#** E-mail: '''bharper@ffym.com'''&lt;br /&gt;
#** Student ID: '''88'''&lt;br /&gt;
#** Grades:&lt;br /&gt;
#*** 5.5&lt;br /&gt;
#*** 0&lt;br /&gt;
#*** 20&lt;br /&gt;
#* '''Matt Freeman'''&lt;br /&gt;
#** E-mail: '''mfreeman@kickinbassist.net'''&lt;br /&gt;
#** Student ID: '''202'''&lt;br /&gt;
#** Grades:&lt;br /&gt;
#*** 100&lt;br /&gt;
#*** 90.5&lt;br /&gt;
#*** 94.8&lt;br /&gt;
#* '''Marc Roberge'''&lt;br /&gt;
#** E-mail: '''mroberge@ofarevolution.us'''&lt;br /&gt;
#** Student ID: '''115'''&lt;br /&gt;
#** Grades:&lt;br /&gt;
#*** 15&lt;br /&gt;
#*** 37&lt;br /&gt;
#*** 45.5&lt;br /&gt;
#: You may choose any 3 classes you'd like for them to be enrolled in, with at least one class, &amp;quot;CSE 330S&amp;quot;, in which they are all enrolled.&lt;br /&gt;
&lt;br /&gt;
=== Querying Your Database ===&lt;br /&gt;
&lt;br /&gt;
Now that you have a fully-functional, populated database, let's do some queries on it!&lt;br /&gt;
&lt;br /&gt;
Write the following '''select''' queries and then run them for a TA:&lt;br /&gt;
&lt;br /&gt;
# Select the entire grades table.&lt;br /&gt;
# Select all fields describing the courses offered in the school of arts and sciences (school code L).&lt;br /&gt;
# The names, student IDs, and grades of the students who are in CSE330.&lt;br /&gt;
# The names and e-mails of any student with an average below 50 so that the dean can send them an email notification that they are now on academic probation.&lt;br /&gt;
#: ''You should be able to do this in only one query, without making any temporary tables.  You will need to use aggregation functions and the '''having''' keyword.''&lt;br /&gt;
# An individual report card for Jack Johnson, consisting of two tables (these can be done using separate queries):&lt;br /&gt;
## His student ID, e-mail address, and average grade.&lt;br /&gt;
##: ''Again, you should be able to do this in just one query, using the correct combination of aggregation functions and joins.''&lt;br /&gt;
## The classes he is in and his grades for those classes. To give you an idea, one row in the table should look like this:&lt;br /&gt;
##: &amp;lt;code&amp;gt;E	81	400	Independent Study	98.5&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Group Project ==&lt;br /&gt;
&lt;br /&gt;
You will work in pairs on this project.  You may work with the same partner from Module 2, or change to someone else.&lt;br /&gt;
&lt;br /&gt;
'''Important Reminder:''' frequently commit your work to your subversion repository as a backup!&lt;br /&gt;
&lt;br /&gt;
=== Simple News Web Site ===&lt;br /&gt;
&lt;br /&gt;
'''Examples:'''&lt;br /&gt;
* http://digg.com/&lt;br /&gt;
* http://slashdot.org/&lt;br /&gt;
&lt;br /&gt;
You should use '''PHP''' unless you get permission to use another web technology from the instructor.  You may also use phpMyAdmin to help set up databases.&lt;br /&gt;
&lt;br /&gt;
You may find this wiki article helpful: [[PHP and MySQL]]&lt;br /&gt;
&lt;br /&gt;
==== Requirements ====&lt;br /&gt;
&lt;br /&gt;
* Users can register for accounts and then log in to the website.&lt;br /&gt;
* Accounts should have both a username and a ''secure'' password.  '''NEVER store plaintext passwords in a database!'''&lt;br /&gt;
*: For more information on password security, refer to [[Web Application Security, Part 2#Password Security|the Web Application Security guide]].&lt;br /&gt;
* Registered users can submit stories: either a link with summary or news text.&lt;br /&gt;
*: You do not have to make a distinction between the two types of stories, although if you want to, you could do something with this for the creative portion of your project.&lt;br /&gt;
* Registered users can comment on any story.&lt;br /&gt;
* Administrator users can delete stories and comments.&lt;br /&gt;
* Unregistered users can only view stories and comments.&lt;br /&gt;
* Registered users can edit their stories and can delete their comments.&lt;br /&gt;
* All data must be kept in a MySQL database (user information, stories, comments, and categories).&lt;br /&gt;
&lt;br /&gt;
=== Web Security and Validation ===&lt;br /&gt;
&lt;br /&gt;
Your project needs to demonstrate that thought was put into web security and best practice.  For more information, see this week's Web Application Security guide: [[Web Application Security, Part 2]]&lt;br /&gt;
&lt;br /&gt;
In particular:&lt;br /&gt;
&lt;br /&gt;
* '''Your application needs to be secure from SQL injection attacks'''. If you are using prepared queries, you should already be safe on this front.&lt;br /&gt;
* '''All of your output needs to be sanitized using htmlentities()'''.&lt;br /&gt;
&lt;br /&gt;
You shouldn't forget the practices you learned last week:&lt;br /&gt;
&lt;br /&gt;
* '''You should pass tokens in forms''' to prevent CSRF attacks.&lt;br /&gt;
* '''Your page should validate''' with no errors through the W3C validator.&lt;br /&gt;
&lt;br /&gt;
== Grading ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;font-size:2em; line-height:2em;&amp;quot;&amp;gt;'''Due Date: _____ (both individual and group)'''&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
!Assignment&lt;br /&gt;
!Points&lt;br /&gt;
|-&lt;br /&gt;
|Tables Correct&lt;br /&gt;
|2&lt;br /&gt;
|-&lt;br /&gt;
|Data Queries Correct&lt;br /&gt;
|2&lt;br /&gt;
|-&lt;br /&gt;
!colspan=&amp;quot;2&amp;quot;|Group Portion:&lt;br /&gt;
|-&lt;br /&gt;
|User Authentication&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|User Registration&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Secure Password&lt;br /&gt;
|2&lt;br /&gt;
|-&lt;br /&gt;
|Main page displays all stories (or most recent stories)&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Page with individual story and comments&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Story Submission&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Comment System&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Administrator Deletion of Stories/Comments&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|User Edit of Story/Comment&lt;br /&gt;
|2&lt;br /&gt;
|-&lt;br /&gt;
|Protect Against SQL Injection Attack&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Sanitize Output&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Older Web Security Practices and Validation&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Creative Portion&lt;br /&gt;
|2&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
[[Category:Module 3]]&lt;br /&gt;
[[Category:Modules]]&lt;/div&gt;</summary>
		<author><name>Marc</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=Module_3&amp;diff=675</id>
		<title>Module 3</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=Module_3&amp;diff=675"/>
		<updated>2012-09-21T15:23:05Z</updated>

		<summary type="html">&lt;p&gt;Marc: /* Group Project */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In Module 3, you will learn about MySQL, a web application database.&lt;br /&gt;
&lt;br /&gt;
This article contains your assignments for Module 3.&lt;br /&gt;
&lt;br /&gt;
== Individual Assignments ==&lt;br /&gt;
&lt;br /&gt;
You will create a simple grades database containing four tables.&lt;br /&gt;
&lt;br /&gt;
'''IMPORTANT:''' The individual assignment is to be done by writing queries by hand.  (You can use phpMyAdmin to run the queries, but '''do not let phpMyAdmin write your queries for you!''')  Writing your own queries gives you a greater understanding of the underlying mechanisms and databases in general.  Additionally, having SQL knowledge and experience is a very marketable trait.&lt;br /&gt;
&lt;br /&gt;
=== Install MySQL and phpMyAdmin ===&lt;br /&gt;
&lt;br /&gt;
Before you start, '''you need to install MySQL''' on your EC2 instance.  You may also install phpMyAdmin, a web frontend to MySQL, if you choose to do so.&lt;br /&gt;
&lt;br /&gt;
You may find the following article to be very helpful: [[Introduction to MySQL]]&lt;br /&gt;
&lt;br /&gt;
=== Set Up a Database ===&lt;br /&gt;
&lt;br /&gt;
You may find the following article to be very helpful: [[Introduction to MySQL]]&lt;br /&gt;
&lt;br /&gt;
# Create a database named '''wustl''' &lt;br /&gt;
# Create a user named '''wustl_inst''' and give them the password '''wustl_pass'''&lt;br /&gt;
&lt;br /&gt;
=== Create Tables ===&lt;br /&gt;
&lt;br /&gt;
You may find the following article to be very helpful: [[MySQL Schema and State]]&lt;br /&gt;
&lt;br /&gt;
When creating tables, keep the following items in mind:&lt;br /&gt;
&lt;br /&gt;
* You should create all tables such that they use the InnoDB storage engine, since we wish to make use of its support of foreign keys. In other database engines, foreign key constraints are not enforced.  (If you mess up, you can use ALTER TABLE to change the storage engine.)&lt;br /&gt;
* Where it is appropriate, you should take advantage of the ability to define fields NOT NULL so that you do not inadvertently insert incomplete data for a row.&lt;br /&gt;
&lt;br /&gt;
Create the following tables:&lt;br /&gt;
&lt;br /&gt;
# Create a table named '''students''' with the following fields:&lt;br /&gt;
#* '''id''' of an appropriately-sized unsigned integer type (we will never need to process more than a million students)&lt;br /&gt;
#* '''first_name''' of type '''VARCHAR(50)'''&lt;br /&gt;
#* '''last_name''' of type '''VARCHAR(50)'''&lt;br /&gt;
#* '''email_address''' of type '''VARCHAR(50)'''&lt;br /&gt;
#: The primary key should be on the '''id''' field.&lt;br /&gt;
# Create a table named '''departments''' with the following fields:&lt;br /&gt;
#* '''school_code''' of type '''ENUM''' (e.g. &amp;quot;L&amp;quot; for ArtSci and &amp;quot;E&amp;quot; for Engineering).  The options are as follows:&lt;br /&gt;
#*: 'L', 'B', 'A', 'F', 'E', 'T', 'I', 'W', 'S', 'U', 'M'&lt;br /&gt;
#* '''dept_id''' of an appropriately-sized unsigned integer type (in the foreseeable future there will never be more than 200 departments in a school)&lt;br /&gt;
#* '''abbreviation''' of type '''VARCHAR(9)''' (e.g. CSE, ChemE, etc)&lt;br /&gt;
#* '''dept_name''' of type '''VARCHAR(200)''' (e.g. Computer Science and Engineering)&lt;br /&gt;
#: The primary key should be on two fields: '''school_code''' and '''dept_id'''&lt;br /&gt;
#: '''Note:''' Why not just use the department ID? The ID numbers are sometimes reused across schools. For instance, department 33 in The School of Arts and Sciences is Psychology while department 33 in The School of Engineering and Applied Sciences is Energy, Environmental and Chemical Engineering. Thus we must also include the school code to differentiate them  such that the record for  E33 is distinct from that of L33.&lt;br /&gt;
# Create a table named '''courses''' with the following fields:&lt;br /&gt;
#* '''school_code''' of type '''ENUM'''&lt;br /&gt;
#*: This should have the same letters in the same order as the '''school_code''' '''ENUM''' field in the '''departments''' table.&lt;br /&gt;
#* '''dept_id''' of the same size of integer as in the '''departments''' table&lt;br /&gt;
#* '''course_code''' of type '''CHAR(5)''' (this will hold course codes; e.g., '330S', '131', '2960')&lt;br /&gt;
#* '''name''' of type '''VARCHAR(150)'''&lt;br /&gt;
#: The appropriate fields in this table should make a foreign key reference to the corresponding fields in '''department'''.&lt;br /&gt;
#: In addition, it is up to you to determine the field(s) for the primary key.&lt;br /&gt;
#: '''Note:''' If you are unsure which fields to make the foreign keys and feel the need to beg your friends or the TAs to give you the answer, bang your head on your desk whilst repeating &amp;quot;I WILL EXERCISE REASON AND COMMON SENSE AND I WILL CURTAIL MY DESIRE TO BLINDLY FOLLOW DIRECTIONS&amp;quot;&lt;br /&gt;
#: ''Disclaimer: don't actually bang your head on your desk, the resulting head trauma may in fact make it harder for you to determine which fields should have associated foreign keys.''&lt;br /&gt;
# Create a table named '''grades''' with the following fields:&lt;br /&gt;
#* '''pk_grade_ID''' of an appropriately-sized unsigned integer type (should be larger than the one you chose for the '''students''' table)&lt;br /&gt;
#*: You should declare this field to be '''auto_increment''' and make it the primary key.&lt;br /&gt;
#*: This is called a ''surrogate key'' as opposed to a ''natural key'' because it doesn't arise &amp;quot;naturally&amp;quot; from the data; that is to say that it is not derived from application data. The use of surrogate keys vs. natural keys is a polemic issue amongst database designers.  For a decently unbiased take on the issue, see this page: http://www.agiledata.org/essays/keys.html#Comparison&lt;br /&gt;
#*: '''Food for thought:''' Aside from simply exposing you to the concept, can you think of any reasons why a surrogate key might be preferable for this table?  Alternatively, what attributes, if any, could you use as a natural key, and what might be the drawbacks of doing so?&lt;br /&gt;
#* '''student_id''' of the same integer (unsigned) type that you chose in the '''students''' table&lt;br /&gt;
#* '''grade''' of type '''decimal'''&lt;br /&gt;
#* '''school_code''' of type '''ENUM'''&lt;br /&gt;
#*: Can you guess what entries to use for the enum?&lt;br /&gt;
#* '''dept_id''' of the same integer type that you've used for this field in other tables&lt;br /&gt;
#* '''course_code''' of the same type you chose for the course code in the '''courses''' table&lt;br /&gt;
#: The '''grades''' table should have foreign keys to both the '''students''' table and the '''courses''' table.&lt;br /&gt;
&lt;br /&gt;
=== Populate Tables ===&lt;br /&gt;
&lt;br /&gt;
Now, populate the tables by downloading the text files given below and loading them into the appropriate tables.&lt;br /&gt;
&lt;br /&gt;
'''Note:''' Do not insert all the values manually; instead, use the MySQL's ability to load in data from text files.&lt;br /&gt;
&lt;br /&gt;
You may find the following article to be very helpful: [[MySQL Schema and State]]&lt;br /&gt;
&lt;br /&gt;
The files containing the data are:&lt;br /&gt;
&lt;br /&gt;
* students: https://docs.google.com/file/d/0ByHgvetJ0GJyMGFjMWI4MzAtMzljYy00Yjk3LTllMWItZjZkYmU1NzU3NWU0/edit&lt;br /&gt;
* courses: https://docs.google.com/file/d/0ByHgvetJ0GJyMGY1NGYzYmUtNGQwYi00MTY3LTkzMjgtMDYwOTM3NDNjZTg4/edit&lt;br /&gt;
* departments: https://docs.google.com/file/d/0ByHgvetJ0GJyZWY2OWE4ZWEtYzVmMC00YjBiLWEzZjgtYzdhMDczODAyNDli/edit&lt;br /&gt;
* grades: https://docs.google.com/file/d/0ByHgvetJ0GJyZmJjNzllNjAtMzdhZC00MzU5LTg3MDYtMTRmMjE5MDE2MzY2/edit&lt;br /&gt;
&lt;br /&gt;
=== Insert More Data ===&lt;br /&gt;
&lt;br /&gt;
Insert the following data into the tables that you have created and populated:&lt;br /&gt;
&lt;br /&gt;
# Insert an entry for CSE 330&lt;br /&gt;
#: ''If you don't know CSE's department code, how can you find out using the tables in the database?''&lt;br /&gt;
# Insert the grades given for the students named below.  You may choose to make the entries for whichever classes you like, with the one condition that all of the students must have a grade for CSE 330 (who wouldn't want to take that class: I hear the professor and TAs are amazing!)&lt;br /&gt;
#* '''Ben Harper'''&lt;br /&gt;
#** E-mail: '''bharper@ffym.com'''&lt;br /&gt;
#** Student ID: '''88'''&lt;br /&gt;
#** Grades:&lt;br /&gt;
#*** 5.5&lt;br /&gt;
#*** 0&lt;br /&gt;
#*** 20&lt;br /&gt;
#* '''Matt Freeman'''&lt;br /&gt;
#** E-mail: '''mfreeman@kickinbassist.net'''&lt;br /&gt;
#** Student ID: '''202'''&lt;br /&gt;
#** Grades:&lt;br /&gt;
#*** 100&lt;br /&gt;
#*** 90.5&lt;br /&gt;
#*** 94.8&lt;br /&gt;
#* '''Marc Roberge'''&lt;br /&gt;
#** E-mail: '''mroberge@ofarevolution.us'''&lt;br /&gt;
#** Student ID: '''115'''&lt;br /&gt;
#** Grades:&lt;br /&gt;
#*** 15&lt;br /&gt;
#*** 37&lt;br /&gt;
#*** 45.5&lt;br /&gt;
#: You may choose any 3 classes you'd like for them to be enrolled in, with at least one class, &amp;quot;CSE 330S&amp;quot;, in which they are all enrolled.&lt;br /&gt;
&lt;br /&gt;
=== Querying Your Database ===&lt;br /&gt;
&lt;br /&gt;
Now that you have a fully-functional, populated database, let's do some queries on it!&lt;br /&gt;
&lt;br /&gt;
Write the following '''select''' queries and then run them for a TA:&lt;br /&gt;
&lt;br /&gt;
# Select the entire grades table.&lt;br /&gt;
# Select all fields describing the courses offered in the school of arts and sciences (school code L).&lt;br /&gt;
# The names, student IDs, and grades of the students who are in CSE330.&lt;br /&gt;
# The names and e-mails of any student with an average below 50 so that the dean can send them an email notification that they are now on academic probation.&lt;br /&gt;
#: ''You should be able to do this in only one query, without making any temporary tables.  You will need to use aggregation functions and the '''having''' keyword.''&lt;br /&gt;
# An individual report card for Jack Johnson, consisting of two tables (these can be done using separate queries):&lt;br /&gt;
## His student ID, e-mail address, and average grade.&lt;br /&gt;
##: ''Again, you should be able to do this in just one query, using the correct combination of aggregation functions and joins.''&lt;br /&gt;
## The classes he is in and his grades for those classes. To give you an idea, one row in the table should look like this:&lt;br /&gt;
##: &amp;lt;code&amp;gt;E	81	400	Independent Study	98.5&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Group Project ==&lt;br /&gt;
&lt;br /&gt;
You will work in pairs on this project.  You may work with the same partner from Module 2, or change to someone else.&lt;br /&gt;
&lt;br /&gt;
'''Important Reminder:''' frequently commit your work to your subversion repository as a backup!&lt;br /&gt;
&lt;br /&gt;
=== Simple News Web Site ===&lt;br /&gt;
&lt;br /&gt;
'''Examples:'''&lt;br /&gt;
* http://digg.com/&lt;br /&gt;
* http://slashdot.org/&lt;br /&gt;
&lt;br /&gt;
You should use '''PHP''' unless you get permission to use another web technology from the instructor.  You may also use phpMyAdmin to help set up databases.&lt;br /&gt;
&lt;br /&gt;
You may find this wiki article helpful: [[PHP and MySQL]]&lt;br /&gt;
&lt;br /&gt;
==== Requirements ====&lt;br /&gt;
&lt;br /&gt;
* Users can register for accounts and then log in to the website.&lt;br /&gt;
* Accounts should have both a username and a ''secure'' password.  '''NEVER store plaintext passwords in a database!'''&lt;br /&gt;
*: For more information on password security, refer to [[Web Application Security, Part 2#Password Security|the Web Application Security guide]].&lt;br /&gt;
*: You need to implement your own authentication system for this module; that is, you may not use something like OpenID.  You may, however, use OpenID in future modules.&lt;br /&gt;
* Registered users can submit stories: either a link with summary or news text.&lt;br /&gt;
*: You do not have to make a distinction between the two types of stories, although if you want to, you could do something with this for the creative portion of your project.&lt;br /&gt;
* Registered users can comment on any story.&lt;br /&gt;
* Administrator users can delete stories and comments.&lt;br /&gt;
* Unregistered users can only view stories and comments.&lt;br /&gt;
* Registered users can edit their stories and can delete their comments.&lt;br /&gt;
* All data must be kept in a MySQL database (user information, stories, comments, and categories).&lt;br /&gt;
&lt;br /&gt;
=== Web Security and Validation ===&lt;br /&gt;
&lt;br /&gt;
Your project needs to demonstrate that thought was put into web security and best practice.  For more information, see this week's Web Application Security guide: [[Web Application Security, Part 2]]&lt;br /&gt;
&lt;br /&gt;
In particular:&lt;br /&gt;
&lt;br /&gt;
* '''Your application needs to be secure from SQL injection attacks'''. If you are using prepared queries, you should already be safe on this front.&lt;br /&gt;
* '''All of your output needs to be sanitized using htmlentities()'''.&lt;br /&gt;
&lt;br /&gt;
You shouldn't forget the practices you learned last week:&lt;br /&gt;
&lt;br /&gt;
* '''You should pass tokens in forms''' to prevent CSRF attacks.&lt;br /&gt;
* '''Your page should validate''' with no errors through the W3C validator.&lt;br /&gt;
&lt;br /&gt;
== Grading ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;font-size:2em; line-height:2em;&amp;quot;&amp;gt;'''Due Date: _____ (both individual and group)'''&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
!Assignment&lt;br /&gt;
!Points&lt;br /&gt;
|-&lt;br /&gt;
|Tables Correct&lt;br /&gt;
|2&lt;br /&gt;
|-&lt;br /&gt;
|Data Queries Correct&lt;br /&gt;
|2&lt;br /&gt;
|-&lt;br /&gt;
!colspan=&amp;quot;2&amp;quot;|Group Portion:&lt;br /&gt;
|-&lt;br /&gt;
|User Authentication&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|User Registration&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Secure Password&lt;br /&gt;
|2&lt;br /&gt;
|-&lt;br /&gt;
|Main page displays all stories (or most recent stories)&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Page with individual story and comments&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Story Submission&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Comment System&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Administrator Deletion of Stories/Comments&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|User Edit of Story/Comment&lt;br /&gt;
|2&lt;br /&gt;
|-&lt;br /&gt;
|Protect Against SQL Injection Attack&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Sanitize Output&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Older Web Security Practices and Validation&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Creative Portion&lt;br /&gt;
|2&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
[[Category:Module 3]]&lt;br /&gt;
[[Category:Modules]]&lt;/div&gt;</summary>
		<author><name>Marc</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=Module_2&amp;diff=674</id>
		<title>Module 2</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=Module_2&amp;diff=674"/>
		<updated>2012-09-21T15:21:07Z</updated>

		<summary type="html">&lt;p&gt;Marc: /* Uploading Files to Your Server */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In Module 2, you will learn about HTML, CSS, and PHP.&lt;br /&gt;
&lt;br /&gt;
This article contains your assignments for Module 2.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;font-size:1.2em; line-height:1.2em;&amp;quot;&amp;gt;'''DO NOT WAIT UNTIL THE LAST MINUTE TO START ON THIS (or any) MODULE!'''  The most common reason students perform poorly in this class is due to procrastination.  You have been warned.&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Individual Assignments ==&lt;br /&gt;
&lt;br /&gt;
=== Learning HTML and CSS ===&lt;br /&gt;
&lt;br /&gt;
You need to become familiar with HTML and CSS.  Read the HTML and CSS guide to get started: [[HTML and CSS]]&lt;br /&gt;
&lt;br /&gt;
=== Write a Birthday Card ===&lt;br /&gt;
&lt;br /&gt;
'''Write a birthday card to a friend or family member using HTML and CSS.'''  Use HTML do define the content of the card (like the headings and the paragraphs), and use CSS to define the appearance.  Some ideas:&lt;br /&gt;
&lt;br /&gt;
* Make the background-color of the page baby blue and use purple ink to write a card to a little boy&lt;br /&gt;
* Make the text big and red, and include pictures of hearts&lt;br /&gt;
* Use a boxy font with text shadows to make your card look urban (more advanced)&lt;br /&gt;
&lt;br /&gt;
Remember that you're in a computer science class (not an art class), so we don't care if your card looks ugly.  The main thing is that you learn HTML and CSS and use them appropriately.&lt;br /&gt;
&lt;br /&gt;
'''Hint:''' For tips on editing files, see [[#Tips on Editing Files]] farther down on this page.&lt;br /&gt;
&lt;br /&gt;
=== Validation ===&lt;br /&gt;
&lt;br /&gt;
Your birthday card must pass the W3C Validator with no errors.  For more information see the HTML and CSS guide: [[HTML and CSS#Validation]]&lt;br /&gt;
&lt;br /&gt;
=== Installing PHP ===&lt;br /&gt;
&lt;br /&gt;
You need to '''install PHP on your EC2 server'''.  Instructions are at the top of the PHP guide: [[PHP]]&lt;br /&gt;
&lt;br /&gt;
You need to '''configure PHP to show errors'''.  Instructions are immediately below installation in the PHP guide.&lt;br /&gt;
&lt;br /&gt;
=== Learning the PHP Language ===&lt;br /&gt;
&lt;br /&gt;
Before you can continue, you will need to make yourself acquainted with PHP language components.  Read the PHP guide for an overview: [[PHP#PHP Language Components]]&lt;br /&gt;
&lt;br /&gt;
=== Calculator 1 ===&lt;br /&gt;
&lt;br /&gt;
'''Make a calculator that uses PHP to multiply two variables provided in the URL and displays the result on a page.'''&lt;br /&gt;
&lt;br /&gt;
=== Calculator 2 ===&lt;br /&gt;
&lt;br /&gt;
'''Make a second calculator.  This one should have an HTML form for the two inputs.'''  It can either POST back to the same page, or to a different result page.  In addition to multiplication, this page should support addition, subtraction, and division, by means of a radio button group on the page.&lt;br /&gt;
&lt;br /&gt;
== Group Project ==&lt;br /&gt;
&lt;br /&gt;
You will work in pairs (that means you and one other person) on this project.&lt;br /&gt;
&lt;br /&gt;
'''Important Reminder:''' frequently commit your work to your subversion repository as a backup!&lt;br /&gt;
&lt;br /&gt;
=== Simple File Management Site ===&lt;br /&gt;
&lt;br /&gt;
You will be making a simple file management site that supports uploading, viewing, and deleting files associated with various usernames.  Details:&lt;br /&gt;
&lt;br /&gt;
* You should have a file named '''users.txt''' stored in a secure place on your filesystem.  It should have one username per line.&lt;br /&gt;
* Users need to specify their username before they can sign into your site.  You should check to see if their username is present in '''users.txt'''.  (Passwords add an extra layer of complexity that we will cover in a later module.)&lt;br /&gt;
* Use PHP Session variables to keep track of the user who is logged in.&lt;br /&gt;
*  Once in the system, you will present the available files for that user. The user then can delete these files, display/open them, or upload new files.&lt;br /&gt;
* A user should be able to see only his/her own files.&lt;br /&gt;
* When a user logs out, all files should be inaccessible until logging back in.&lt;br /&gt;
* You need to support at least 3 different users.&lt;br /&gt;
** Registering new users is NOT necessary (although you may do so for part of the creative portion)&lt;br /&gt;
* The url should NOT reveal internal file structure (including file names, so don't just link to the actual file on the web page!)&lt;br /&gt;
** Example of what not to do:  http://www.example.com/download.php?file=/home/paul/file.txt&lt;br /&gt;
** Another bad example:  http://www.example.com/~user/file.txt&lt;br /&gt;
*: In general, don't reveal any internal information about the site.&lt;br /&gt;
* Food for thought: Given that Apache processes (with the exception of the main process) do not run as root, but rather as the user apache, how can you allow both your user account and the php scripts to read and write the necessary files?&lt;br /&gt;
* Creative portion: add an extra function to the site.&lt;br /&gt;
** It must be non-trivial, and involve learning outside the instructions provided in the class materials&lt;br /&gt;
** This idea needs to be approved by the TAs/Professor.  Discuss it with at least one TA or the professor before proceeding.&lt;br /&gt;
** Note that the creative portion is worth double the points of a regular task.  Creative portions will not be given full credit if they are too simple, or are simply rehashed things that you've already done (whether it be in this or previous modules).&lt;br /&gt;
&lt;br /&gt;
You will probably find the PHP guide on this wiki to be helpful: [[PHP#Other PHP Tips]]&lt;br /&gt;
&lt;br /&gt;
=== Web Security and Validation ===&lt;br /&gt;
&lt;br /&gt;
Your project needs to demonstrate that thought was put into web security and best practice.  For more information, see this week's Web Application Security guide: [[Web Application Security, Part 1]]&lt;br /&gt;
&lt;br /&gt;
In particular:&lt;br /&gt;
&lt;br /&gt;
* '''Your application needs to be safe from CSRF attacks'''. That is, '''you should pass tokens when uploading and deleting files''' in order to prevent request forgeries.&lt;br /&gt;
* '''Your project must pass the W3C Validator with no errors'''.  For more information, see the HTML and CSS guide: [[HTML and CSS#Validation]]&lt;br /&gt;
&lt;br /&gt;
== Tips on Editing Files ==&lt;br /&gt;
&lt;br /&gt;
You have several choices when it comes down to actually editing files on your web site.&lt;br /&gt;
&lt;br /&gt;
* You can use a command-line text editor, like '''emacs''', '''vi''', or '''nano'''&lt;br /&gt;
* You can use a GUI text editor, like Notepad++ or TextWrangler&lt;br /&gt;
* You can use a full GUI IDE, like Eclipse&lt;br /&gt;
* You can also edit files directly using WinSCP or FIleZilla, or other SFTP programs (see following section).&lt;br /&gt;
&lt;br /&gt;
The choice is really what you prefer.  Using the GUI certainly has numerous advantages over a command-line interface, but it's sometimes simpler to edit files directly on your server.  Either way, you should frequently commit changes to your repository.&lt;br /&gt;
&lt;br /&gt;
See [[#Uploading Files to Your Server]] for tips on editing files on your desktop and then uploading them to your server.&lt;br /&gt;
&lt;br /&gt;
If you use an IDE, you should consider using the Aptana Studio plugin for Eclipse.  Aptana Studio gives you tools for developing in HTML, CSS, JavaScript, and PHP.  To install it in Eclipse:&lt;br /&gt;
&lt;br /&gt;
# In Eclipse, go to '''Install New Software...'''&lt;br /&gt;
# Add the following URL: http://update.aptana.com/update/studio/&lt;br /&gt;
#: If that doesn't work, you can try directly downloading Aptana from http://aptana.com/products/studio3/download&lt;br /&gt;
# Load the packages and install Aptana Studio.&lt;br /&gt;
# Restart Eclipse.&lt;br /&gt;
# In the Aptana Studio welcome screen, go to Plugins&lt;br /&gt;
# Install the Aptana Studio PHP plugin&lt;br /&gt;
# Restart Eclipse again.&lt;br /&gt;
&lt;br /&gt;
If you don't want to use Eclipse, there are other free text editors that you can use on your computer.  Notepad++ is a good choice for Windows, and TextWrangler is a good choice for Mac OS X.&lt;br /&gt;
&lt;br /&gt;
* You may want to download Notepad++ and save it to your H: drive.  Link: http://notepad-plus-plus.org/&lt;br /&gt;
* You can download TextWrangler from here (or just get it from the Mac App Store): http://www.barebones.com/products/TextWrangler/&lt;br /&gt;
&lt;br /&gt;
=== Uploading Files to Your Server ===&lt;br /&gt;
&lt;br /&gt;
If you edit files on your desktop, there are several ways to upload those files to your server.&lt;br /&gt;
&lt;br /&gt;
* If you edit the files in Eclipse, just commit changes to your repository, and on your server, run &amp;lt;code&amp;gt;svn update&amp;lt;/code&amp;gt; to pull the changes down.  This works best if you have [[Web Server Configuration#Pointing Apache to your Repository|configured Apache to point to your SVN repository]].&lt;br /&gt;
* You can use as SSH filesystem client to make local files automatically update on your server.  For instructions, see [[Web Server Configuration#SSHFS|the Web Server Configuration guide]] from Module 1.&lt;br /&gt;
* You can use an SFTP client like FileZilla (universal) or WinSCP (if on Windows) to upload files to your server.  For instructions, see [[Web Server Configuration#SFTP|the Web Server Configuration guide]] from Module 1.&lt;br /&gt;
&lt;br /&gt;
If you need help setting up an SSH filesystem or an SFTP client, you may ask a TA.  Once everything is up and running, you will be able to easily upload files to your server for the remainder of this course.&lt;br /&gt;
&lt;br /&gt;
'''Note:''' It is recommended, although not required, to backup files using SVN.&lt;br /&gt;
&lt;br /&gt;
== Grading ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;font-size:2em; line-height:2em;&amp;quot;&amp;gt;'''Due Date: Monday September 24th, by 1 PM (both individual and group)'''&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
!Assignment&lt;br /&gt;
!Points&lt;br /&gt;
|-&lt;br /&gt;
|Birthday Card Content&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Birthday Card Validation&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Calculator 1&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Calculator 2&lt;br /&gt;
|2&lt;br /&gt;
|-&lt;br /&gt;
!colspan=&amp;quot;2&amp;quot;|Group Portion:&lt;br /&gt;
|-&lt;br /&gt;
|Multi-User Login&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Logout Mechanism&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Can't Access Other Users' Files&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Can't See File/Directory Structure&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Can Upload New Files&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Can View/Download Files&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Can Delete Files&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Cross-Site Request Forgery Safe&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Validation&lt;br /&gt;
|1&lt;br /&gt;
|-&lt;br /&gt;
|Creative Portion&lt;br /&gt;
|2&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
[[Category:Module 2]]&lt;br /&gt;
[[Category:Modules]]&lt;/div&gt;</summary>
		<author><name>Marc</name></author>
		
	</entry>
</feed>