Index: /django_apps/running/admin.py
===================================================================
--- /django_apps/running/admin.py	(revision 300)
+++ /django_apps/running/admin.py	(revision 301)
@@ -5,9 +5,9 @@
   fields = [ 'date', 'distance', 'time' ]
 
-class UserAdmin(admin.ModelAdmin):
+class RunningUserAdmin(admin.ModelAdmin):
   inlines = [ ResultInline, ]
   class Media:
     css = { "all" : ("css/hide_admin_original.css",) }
-admin.site.register(User, UserAdmin)
+admin.site.register(RunningUser, RunningUserAdmin)
 
 
Index: /django_apps/running/models.py
===================================================================
--- /django_apps/running/models.py	(revision 300)
+++ /django_apps/running/models.py	(revision 301)
@@ -2,14 +2,15 @@
 import datetime
 
+from django.contrib.auth.models import User
+
 # Create your models here.
-class User(models.Model):
-  name = models.CharField(max_length=50)
-  def __unicode__(self):
-    return self.name
+class RunningUser(User):
+  class Meta:
+    proxy = True
 
 class Result(models.Model):
   user = models.ForeignKey(User)
   distance = models.DecimalField(max_digits=5,decimal_places=2)
-  time = models.TimeField()
+  time = models.TimeField(default='00:00:00')
   date = models.DateField(default=datetime.date.today)
 
Index: /django_apps/running/static/year-total.js
===================================================================
--- /django_apps/running/static/year-total.js	(revision 300)
+++ /django_apps/running/static/year-total.js	(revision 301)
@@ -1,3 +1,6 @@
 function yearTotalGraph(data, binder) {
+  if (data.length == 0) {
+    return;
+  }
   var start = data[0].x;
   var end = data[data.length - 1].x;
@@ -33,5 +36,5 @@
                   pv.search.index(data, d2, function(d) d.x) + 1);
           fx.domain(d1, d2);
-          fy.domain(scale.checked ? [0, pv.max(dd, function(d) d.y)] : y.domain());
+          fy.domain(scale.checked ? [0, pv.max(dd, function(d) d.y) * 1.1] : y.domain());
           return dd;
         })
Index: /django_apps/running/templates/index.html
===================================================================
--- /django_apps/running/templates/index.html	(revision 300)
+++ /django_apps/running/templates/index.html	(revision 301)
@@ -1,5 +1,5 @@
 <ul>
 {% for user in user_list %} 
-<li><a href="{% url running.views.user_index user.name %}">{{ user }}</li>
+<li><a href="{% url running.views.user_index user.username %}">{{ user }}</li>
 {%endfor %}
 </ul>
Index: /django_apps/running/templates/user_index.html
===================================================================
--- /django_apps/running/templates/user_index.html	(revision 300)
+++ /django_apps/running/templates/user_index.html	(revision 301)
@@ -20,12 +20,42 @@
   </head>
   <body>
-    <a href="{% url running.views.index %}">User Overview</a><p />
-    <h1>Welcome {{ user }}</h1>
+  <table>
+  <tr>
+  <td>
+    <a href="{% url running.views.index %}">User Overview</a>
+  </td>
+  <td>-</td>
+  <td>
+    {% if user.is_authenticated %}
+<form method="post" action="{% url logout %}">
+      <input type="submit" value="logout" />
+  {% csrf_token %}
+  <input type="hidden" name="next" value="{{ request.path }}" />
+</form>
+    {% else %}
+<form method="post" action="{% url login %}">
+  {% csrf_token %}
+  <table>
+  <tr>
+      <td><input type="text" name="username" /></td>
+      <td><input type="password" name="password" /></td>
+      <td><input type="submit" value="login" /></td>
+  </tr>
+  </table>
+  <input type="hidden" name="next" value="{{ request.path }}" />
+</form>
+{% endif %}
+</td>
+</tr>
+</table>
+   <h1>Welcome {{ user.username|default:"New User" }}</h1>
+   <a href="#results">Add new results</a>
+
     <div id="center">
-      <h3>Week totals</h3>
+      <h3>Week totals in KM</h3>
       <div id="fig2">
         <div id="week-statistics"> </div>
       </div>
-      <h3>Accumulated Totals</h3>
+      <h3>Accumulated Totals in KM</h3>
       <div id="fig">
         <div style="text-align:right;padding-right:20;">
@@ -35,5 +65,15 @@
         <div id="total-statistics"> </div>
       </div>
+      <h3>Avergage Speed in KM</h3>
+      <div id="fig">
+        <div style="text-align:right;padding-right:20;">
+          <input checked id="scale" type="checkbox" onchange="vis.render()"
+          ><label for="scale">Scale to fit</label>
+        </div>
+        <div id="speed-statistics"> </div>
+      </div>
     </div>
+    {% if user.is_authenticated %}
+    {% if user.id == runninguser.id %}
     <form method="post" action="">
     {% csrf_token %}
@@ -63,5 +103,11 @@
     <input type="submit" value="Submit Values"/>
     </form>
-    Beheer al je gegevens <a href="{% url admin:running_user_change user.id %}">hier</a>.
+    {% else %}
+      Bewerk je eigen gegevens <a href="{% url running.views.user_index user.username %}">hier</a>.
+    {% endif %}
+    {% else %}
+    Login om je gegevens toe te voegen.
+    {% endif %}
+    <a name="results" />
 
 
@@ -69,5 +115,5 @@
   // Graph Week totals
   var xhr = new XMLHttpRequest();
-  xhr.open('GET', '{% url running.views.json_user_column user.id %}', false);
+  xhr.open('GET', '{% url running.views.json_user_column runninguser.id %}', false);
   xhr.send(null);
   var myData = JSON.parse(xhr.responseText, function (key, value) {
@@ -81,5 +127,5 @@
   // Graph Year totals
   var xhr = new XMLHttpRequest();
-  xhr.open('GET', '{% url running.views.json_user_total user.id %}', false);
+  xhr.open('GET', '{% url running.views.json_user_total runninguser.id %}', false);
   xhr.send(null);
   
@@ -95,4 +141,23 @@
   yearTotalGraph(data, 'total-statistics');
 </script>
+
+
+<script type="text/javascript+protovis">
+  // Graph Average Speed
+  var xhr = new XMLHttpRequest();
+  xhr.open('GET', '{% url running.views.json_user_speed runninguser.id %}', false);
+  xhr.send(null);
+  
+  var data = JSON.parse(xhr.responseText, function (key, value) {
+      var type;
+      if ( value != null) {
+        if ( key === 'x') {
+           return new Date(value);
+        }
+      }
+      return value;
+  });
+  yearTotalGraph(data, 'speed-statistics');
+</script>
   </body>
 </html>
Index: /django_apps/running/urls.py
===================================================================
--- /django_apps/running/urls.py	(revision 300)
+++ /django_apps/running/urls.py	(revision 301)
@@ -8,3 +8,6 @@
     url(r'^json/user/column/(\d+)/$', 'running.views.json_user_column'),
     url(r'^json/user/total/(\d+)/$', 'running.views.json_user_total'),
+    url(r'^json/user/speed/(\d+)/$', 'running.views.json_user_speed'),
+    url(r'^accounts/login/$', 'django.contrib.auth.views.login', name='login' ),
+    url(r'^accounts/logout/$', 'django.contrib.auth.views.logout', name='logout'),
 )
Index: /django_apps/running/views.py
===================================================================
--- /django_apps/running/views.py	(revision 300)
+++ /django_apps/running/views.py	(revision 301)
@@ -4,27 +4,32 @@
 from django.http import HttpResponse
 from django.forms.models import modelformset_factory, inlineformset_factory
+from django.forms.models import BaseModelFormSet
 from django.template import RequestContext
 
 from django.shortcuts import render_to_response, get_object_or_404
-from running.models import Result, User
+from running.models import Result, RunningUser
 import json
 
 def user_index(request, user_name):
-    user = get_object_or_404(User, name=user_name)
+    running_user = get_object_or_404(RunningUser, username=user_name)
     ResultFormSet = modelformset_factory(Result, fields=('date', 'distance', 'time'), exclude=('user'), extra=3, can_delete=True)
     if request.method == 'POST':
+       if not request.user.is_authenticated():
+          return HttpResponseForbidden('Not Logged In!')
        formset = ResultFormSet(request.POST, request.FILES)
        if formset.is_valid():
          instances = formset.save(commit=False)
          for instance in instances:
-           instance.user = user
+           instance.user = running_user
            instance.save()
-
-    result_list = Result.objects.filter(user=user)
-    formset = ResultFormSet(queryset=result_list)
-    return render_to_response('user_index.html', { 'user' : user, 'formset' : formset }, context_instance=RequestContext(request))
+         result_list = Result.objects.filter(user=running_user).order_by('date')
+         formset = ResultFormSet(queryset=result_list)
+    else:
+      result_list = Result.objects.filter(user=running_user).order_by('date')
+      formset = ResultFormSet(queryset=result_list)
+    return render_to_response('user_index.html', { 'runninguser' : running_user, 'formset' : formset, 'request' : request }, context_instance=RequestContext(request))
 
 def index(request):
-    user_list = User.objects.all()
+    user_list = RunningUser.objects.all()
     return render_to_response('index.html', { 'user_list' : user_list })
 
@@ -40,5 +45,5 @@
 
 def json_user_column(request,user_id):
-    user = get_object_or_404(User, pk=user_id)
+    user = get_object_or_404(RunningUser, pk=user_id)
     result_list = Result.objects.filter(user=user).values_list('date', 'distance')
 
@@ -59,5 +64,6 @@
 
 def json_user_total(request,user_id):
-    result_list = Result.objects.values_list('date', 'distance')
+    user = get_object_or_404(RunningUser, pk=user_id)
+    result_list = Result.objects.filter(user=user).values_list('date', 'distance')
     json_list = []
     distance_total = 0.0
@@ -68,2 +74,15 @@
     data = json.dumps(json_list, ensure_ascii=False, indent=2)
     return HttpResponse(data,mimetype="application/json")
+
+def json_user_speed(request,user_id):
+    user = get_object_or_404(RunningUser, pk=user_id)
+    result_list = Result.objects.filter(user=user).values_list('date', 'distance', 'time')
+    json_list = []
+    # Output date object in epoch milliseconds as JavaScript find this easy to use.
+    for (date,distance,time) in result_list:
+        hour = float(time.second + time.minute * 60) / 3600 + time.hour
+        if hour == 0:
+          continue
+        json_list.append({'x': int(date.strftime("%s")) * 1000, 'y' : float(distance) / hour})
+    data = json.dumps(json_list, ensure_ascii=False, indent=2)
+    return HttpResponse(data,mimetype="application/json")
