Skip to content

Commit

Permalink
sign in, sign out - openID
Browse files Browse the repository at this point in the history
  • Loading branch information
andris9 committed Nov 20, 2010
1 parent 49f0d6e commit e1280f8
Show file tree
Hide file tree
Showing 11 changed files with 150 additions and 4 deletions.
17 changes: 17 additions & 0 deletions app.yaml
Expand Up @@ -4,5 +4,22 @@ runtime: python
api_version: 1

handlers:

- url: /favicon\.ico
static_files: static/favicon.ico
upload: static/favicon.ico

- url: /robots\.txt
static_files: static/robots.txt
upload: static/robots.txt
mime_type: image/x-icon

- url: /webadmin/.*
script: $PYTHON_LIB/google/appengine/ext/admin
login: admin

- url: /static
static_dir: static/static

- url: .*
script: main.py
Binary file modified diff_match_patch.pyc
Binary file not shown.
64 changes: 61 additions & 3 deletions main.py
Expand Up @@ -11,17 +11,75 @@
from google.appengine.ext import db
from google.appengine.ext.webapp import template
import os
import urllib




def gen_template_values(http):
template_values = {
"user": users.get_current_user()
}
return template_values

def showError(http, message=None):
template_values = gen_template_values(http)
template_values["message"] = message or "Error"
path = os.path.join(os.path.dirname(__file__), 'views/error.html')
http.response.out.write(template.render(path, template_values))

def errorNotLoggedIn(http):
showError(http, "You need to be logged in!")

class MainHandler(webapp.RequestHandler):
def get(self):
template_values = {}
path = os.path.join(os.path.dirname(__file__), 'views/main.html')
template_values = gen_template_values(self)
path = os.path.join(os.path.dirname(__file__), 'views/front.html')
self.response.out.write(template.render(path, template_values))

class LoggedHandler(webapp.RequestHandler):
def get(self):
user = users.get_current_user()
if not user:
return errorNotLoggedIn(self)

template_values = gen_template_values(self)
path = os.path.join(os.path.dirname(__file__), 'views/logged.html')
self.response.out.write(template.render(path, template_values))

class LogoutHandler(webapp.RequestHandler):
def get(self):
user = users.get_current_user()
if not user:
url = "/"
else:
url = users.create_logout_url("/")
self.redirect(url)

class LoginHandler(webapp.RequestHandler):
def get(self):
template_values = gen_template_values(self)

target_url = self.request.get("target_url", None);
if target_url:
target_url = "/logged?target_url=%s" % urllib.quote_plus(target_url)
else:
target_url = "/logged"

template_values["target_url"] = target_url
path = os.path.join(os.path.dirname(__file__), 'views/login.html')
self.response.out.write(template.render(path, template_values))

def post(self):
url = users.create_login_url(self.request.get("target_url", None),
federated_identity=self.request.get("openid", None))
self.redirect(url)

def main():
application = webapp.WSGIApplication([('/', MainHandler)],
application = webapp.WSGIApplication([('/', MainHandler),
('/login', LoginHandler),
('/logout', LogoutHandler),
('/logged', LoggedHandler)],
debug=True)
util.run_wsgi_app(application)

Expand Down
Binary file added static/favicon.ico
Binary file not shown.
2 changes: 2 additions & 0 deletions static/robots.txt
@@ -0,0 +1,2 @@
# Robots Exclusion Standard file
# read more from http://www.robotstxt.org/wc/exclusion.html
5 changes: 5 additions & 0 deletions static/static/style.css
@@ -0,0 +1,5 @@


body{
font-family: Helvetica, Arial, Sans-serif;
}
12 changes: 12 additions & 0 deletions views/error.html
@@ -0,0 +1,12 @@
{% extends "main.html" %}


{% block title %}Error{% endblock %}

{% block body %}

<h1>Error</h1>

<h3>{{ message }}</h3>

{% endblock %}
10 changes: 10 additions & 0 deletions views/front.html
@@ -0,0 +1,10 @@
{% extends "main.html" %}


{% block title %}jipikajee{% endblock %}

{% block body %}

<h1>tere tere!</h1>

{% endblock %}
10 changes: 10 additions & 0 deletions views/logged.html
@@ -0,0 +1,10 @@
{% extends "main.html" %}


{% block title %}Logged in{% endblock %}

{% block body %}

<h1>Successfully logged in!</h1>

{% endblock %}
17 changes: 17 additions & 0 deletions views/login.html
@@ -0,0 +1,17 @@
{% extends "main.html" %}


{% block title %}Log in{% endblock %}

{% block body %}

<h1>Log in</h1>

<form method="post" action="/login">
<input type="hidden" name="target_url" value="{{ target_url }}"/>
<p>
Open ID: <input type="text" name="openid" value="" /> <input type="submit" name="nupp" value="Log in" />
</p>
</form>

{% endblock %}
17 changes: 16 additions & 1 deletion views/main.html
@@ -1,9 +1,24 @@
<!DOCTYPE html>
<html>
<head>
<title>Patch</title>
<title>{% block title %}{% endblock %}</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link href="/static/style.css" rel="stylesheet" type="text/css" />
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">
<link rel="icon" href="/favicon.ico" type="image/x-icon">
</head>
<body>

<div>
{% if user %}
<a href="/logout">Log out</a>
{% else %}
<a href="/login">Log in</a>
{% endif %}
</div>


{% block body %}{% endblock %}

</body>
</html>

0 comments on commit e1280f8

Please sign in to comment.