Commit 3b06cbef authored by Lysander Trischler's avatar Lysander Trischler

Remove extra home and login pages

There is no extra ``/login`` and ``/today`` URL anymore. Login form and
today's overview are both rendered on the new front page at ``/`` depending
on the user's login status. If the user is logged in all the exercices
performed today are shown, otherwise a login form is represented. The POST
login method is also handled at ``/``.

Please note the old ``/login`` POST won't work anymore! GET is redirected
to the front page from the both old URLs. Please change your URLs, if
necessary.

Thanks to WF for this change request.
parent 7cf30aab
......@@ -223,14 +223,27 @@ if __name__ == "__main__":
def end(self):
return utc_to_local(self["end"])
@route(r'/')
class HomeHandler(BaseHandler):
@route(r'/', aliases=[r'/login', r'/today'])
class LoginOrTodayHandler(tornadyse.LoginHandler, BaseHandler):
login = BaseHandler.login
def get(self):
self.render("base.html")
if self.current_user is None:
@route(r'/login')
class LoginHandler(tornadyse.LoginHandler, BaseHandler):
login = BaseHandler.login
# user is NOT logged in: render login form
tornadyse.LoginHandler.get(self)
else:
# user is logged in: render today overview
start = datetime.datetime.combine(self.today, datetime.time(hour=3))
end = start + datetime.timedelta(days=1)
self.render("today.html", exercises=[Exercise(**exercise) for exercise in self.db.query("""
SELECT id, username, discipline, count, start, end
FROM exercises
WHERE start >= %s AND start < %s
ORDER BY start DESC, end DESC, count, username
""", start, end)])
@route(r'/logout')
class LogoutHandler(tornadyse.LogoutHandler, BaseHandler): pass
......@@ -728,19 +741,6 @@ if __name__ == "__main__":
daily=daily,
hourly=hourly)
@route(r'/today')
class TodayHandler(BaseHandler):
@authenticated
def get(self):
start = datetime.datetime.combine(self.today, datetime.time(hour=3))
end = start + datetime.timedelta(days=1)
self.render("today.html", exercises=[Exercise(**exercise) for exercise in self.db.query("""
SELECT id, username, discipline, count, start, end
FROM exercises
WHERE start >= %s AND start < %s
ORDER BY start DESC, end DESC, count, username
""", start, end)])
@route(r'/passwd')
class ChangeAPIPasswordHandler(BaseHandler):
......@@ -1091,6 +1091,7 @@ if __name__ == "__main__":
+ "@" + tornado.options.options.mysql_hostname
+ "/" + tornado.options.options.mysql_database
+ "/sessions",
login_url="/",
localhost_ip=tornado.options.options.localhost_ip
)
self.db = torndb.Connection(
......
......@@ -8,18 +8,17 @@
</head>
<body>{% if handler.settings["debug"] %}<p style="position:fixed;top:.5em;right:.5em;background-color:pink;border:.2em solid purple;color:purple;font-weight:bold;font-size:1.5em;padding:.5em">Debug-Modus</p>{% end %}
<header>
<h1>{% module navi("HomeHandler", "Kraftwerk") %}</h1>
<h1>{% module navi("LoginOrTodayHandler", "Kraftwerk") %}</h1>
<nav>
{% if current_user %}
{% module navi("TodayHandler", "Heute") %}
{% module navi("LoginOrTodayHandler", "Heute") %}
{% module navi("ListUsersHandler", "Benutzerübersicht") %}
{% module navi("ListExercisesHandler", "Übungsübersicht") %}
{% module navi("AddExerciseHandler", "Übung eintragen") %}
{% module navi("ChangeAPIPasswordHandler", "API-Passwort ändern") %}
{% module navi("LogoutHandler", "%s abmelden" % (current_user.display_name or current_user.username)) %}
{% else %}
{% module navi("LoginHandler", "Anmelden") %}
{% end %}
{% module navi("LoginOrTodayHandler", "Anmelden") %}
{% module navi("APIHandler", "REST-API") %}
</nav>
</header>
......
......@@ -11,7 +11,7 @@
<dl>
<dt class=required><label for=username>Benutzername</label></dt>
<dd class=required><input type=text name=username id=username value="{{ username }}" maxlength=32 required=required placeholder="der Benutzername"{% if username == "" %} autofocus=autofocus{% end %} /><p class=info>Bei der Benutzernameneingabe auf die Groß- und Kleinschreibung achten.</p></dd>
<dt class=required><label for=password>Passwort</label></dt>
<dd class=required><input type=password name=password id=password value="" maxlength=128 required=required placeholder="das Passwort"{% if username != "" %} autofocus=autofocus{% end %} /><p class=info>Bei der Kennworteingabe auf die Groß- und Kleinschreibung achten.</p></dd>
</dl>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment