Permalink
Browse files

Logging & nicer flow

  • Loading branch information...
dustball committed Mar 26, 2011
1 parent 73c29d4 commit c15c11d91231e3e855b198486e762341f1b01ef5
Showing with 76 additions and 5 deletions.
  1. +6 −0 index.yaml
  2. +36 −4 main.py
  3. +2 −0 static/.gitignore
  4. +31 −0 templates/log.html
  5. +1 −1 templates/main.html
View
@@ -9,3 +9,9 @@ indexes:
# manually, move them above the marker line. The index.yaml file is
# automatically uploaded to the admin console when you next deploy
# your application using appcfg.py.
+
+- kind: MacAddressMapping
+ properties:
+ - name: username
+ - name: created
+ direction: desc
View
40 main.py
@@ -9,6 +9,7 @@
import base64
import urllib
import time
+import string
DOMAIN = 'hackerdojo.com'
MEMBER_DOWNLOAD = 0
@@ -56,6 +57,14 @@ def get_stat(name, resolution=60):
else:
return 0
+class Login(db.Model):
+ """ A non log of logins. """
+
+ address = db.StringProperty()
+ username = db.StringProperty()
+ created = db.DateTimeProperty(auto_now_add=True)
+
+
class MacAddressMapping(db.Model):
""" Member MAC address mapping
@@ -68,11 +77,32 @@ class MacAddressMapping(db.Model):
username = db.StringProperty()
created = db.DateTimeProperty(auto_now_add=True)
+ @classmethod
+ def register_new_device(cls, address, username):
+ total_devices = 2
+ devices = cls.all().filter('username =', username).order("-created").fetch(100)
+ for d in devices[total_devices-1:]:
+ d.delete()
+ m = cls(address=address, username=username)
+ m.put()
+ return m
+
+
@classmethod
def get_by_mac(cls, address):
return cls.all().filter('address =', address).get()
+class LogHandler(webapp.RequestHandler):
+ """ Show log """
+
+ def get(self):
+ log = Login.all()
+ self.response.out.write(template.render('templates/log.html', {
+ 'log': log
+ }))
+
+
class EntryHandler(webapp.RequestHandler):
""" Entry point for the wifi app
@@ -99,17 +129,18 @@ class MemberHandler(webapp.RequestHandler):
def post(self):
client = AppsService(domain=DOMAIN)
- username = self.request.get('username')
+ username = string.split(self.request.get('username'),"@")[0].strip()
mac = self.request.get('mac')
redirect = self.request.get('redirect')
try:
- client.ClientLogin('%s@%s' % (username, DOMAIN), self.request.get('password'))
+ client.ClientLogin('%s@%s' % (username, DOMAIN), self.request.get('password').strip())
+ login = Login(username=username, address = mac)
+ login.put()
existing = MacAddressMapping.get_by_mac(mac)
if existing and not is_suspended(username):
self.redirect(redirect or DEFAULT_REDIRECT)
elif not is_suspended(username):
- m = MacAddressMapping(address=mac, username=username)
- m.put()
+ MacAddressMapping.register_new_device(mac,username)
self.redirect(redirect or DEFAULT_REDIRECT)
else:
raise Exception("Invalid account")
@@ -202,6 +233,7 @@ def post(self):
def main():
application = webapp.WSGIApplication([
('/dev', DevHandler),
+ ('/log', LogHandler),
('/api/mac/(.+)', MacHandler),
('/api/stat/(.+)', StatHandler),
('/guest', GuestHandler),
View
@@ -1 +1,3 @@
*.pyc
+*/*.pyc
+*/*/.pyc
View
@@ -0,0 +1,31 @@
+{% extends 'base.html' %}
+{% block content %}
+
+ <div class="container_12 content">
+ <div class="grid_12 alpha omega">
+
+ <img border=0 src="/static/dojo400.png" style="margin:2em" width="400" height="141" />
+
+ </div>
+
+ <br>
+
+ <div class="grid_12 alpha omega">
+
+ <div style="margin:2em">
+ <table width=100%>
+ {% for l in log %}
+ <tr><td>{{l.created}}</td><td>{{l.username}}</td><td>{{l.address}}</td></tr>
+ {% endfor %}
+ </table>
+ </div>
+
+ </div>
+
+
+
+ <div class="clearfix">&nbsp;</div>
+
+ </div>
+
+{% endblock %}
View
@@ -29,7 +29,7 @@ <h2><b>FIBER Internet has arrived!</b> Members, login below to gain full access
<h3>Members</h3>
<form method="post" action="/member" class="memberlogin">
- {% if error %}<p style="color: red; font-size: smaller; font-weight:bold">{{error}}</p>{% endif %}
+ {% if error %}<p style="color: red; font-size: smaller; font-weight:bold">{{error|escape}}</p>{% endif %}
<table cellpadding=0 cellspacing=1 border="0" width="100%">
<tr><td class="label">Username:</td><td width="100%"><input class="textbox homeinput" name="username" type="text" placeholder="ex: joe.smith" /></td></tr>
<tr><td class="label">Password:</td><td width="100%"><input class="textbox homeinput" name="password" type="password" /></td></tr>

0 comments on commit c15c11d

Please sign in to comment.