diff --git a/app/__init__.py b/app/__init__.py index a6c9e33..963e227 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -1,4 +1,6 @@ from flask import Flask app = Flask(__name__) +app.config.from_object('config') + from app import views diff --git a/app/forms.py b/app/forms.py new file mode 100644 index 0000000..072873a --- /dev/null +++ b/app/forms.py @@ -0,0 +1,7 @@ +from flask.ext.wtf import Form, TextField, BooleanField +from flask.ext.wtf import Required + +class LoginForm(Form): + openid = TextField('openid', validators = [Required()]) + remember_me = BooleanField('remember_me', default = False) + \ No newline at end of file diff --git a/app/templates/base.html b/app/templates/base.html index 0fbd92f..0a3d1e9 100644 --- a/app/templates/base.html +++ b/app/templates/base.html @@ -9,6 +9,15 @@
Microblog: Home

+ {% with messages = get_flashed_messages() %} + {% if messages %} + + {% endif %} + {% endwith %} {% block content %}{% endblock %} \ No newline at end of file diff --git a/app/templates/index.html b/app/templates/index.html index 7fa8c8a..80d4533 100644 --- a/app/templates/index.html +++ b/app/templates/index.html @@ -1,4 +1,6 @@ + {% extends "base.html" %} + {% block content %}

Hi, {{user.nickname}}!

{% for post in posts %} diff --git a/app/templates/login.html b/app/templates/login.html new file mode 100644 index 0000000..81a7540 --- /dev/null +++ b/app/templates/login.html @@ -0,0 +1,34 @@ + +{% extends "base.html" %} + +{% block content %} + +

Sign In

+
+ {{form.hidden_tag()}} +

+ Please enter your OpenID, or select one of the providers below:
+ {{form.openid(size=80)}} + {% for error in form.errors.openid %} + [{{error}}] + {% endfor %}
+ |{% for pr in providers %} + {{pr.name}} | + {% endfor %} +

+

{{form.remember_me}} Remember Me

+

+
+{% endblock %} diff --git a/app/views.py b/app/views.py index 7742496..b6cb21f 100644 --- a/app/views.py +++ b/app/views.py @@ -1,5 +1,6 @@ -from flask import render_template +from flask import render_template, flash, redirect from app import app +from forms import LoginForm @app.route('/') @app.route('/index') @@ -15,7 +16,18 @@ def index(): 'body': 'The Avengers movie was so cool!' } ] - return render_template("index.html", + return render_template('index.html', title = 'Home', user = user, posts = posts) + +@app.route('/login', methods = ['GET', 'POST']) +def login(): + form = LoginForm() + if form.validate_on_submit(): + flash('Login requested for OpenID="' + form.openid.data + '", remember_me=' + str(form.remember_me.data)) + return redirect('/index') + return render_template('login.html', + title = 'Sign In', + form = form, + providers = app.config['OPENID_PROVIDERS']) diff --git a/config.py b/config.py new file mode 100644 index 0000000..a5655eb --- /dev/null +++ b/config.py @@ -0,0 +1,9 @@ +CSRF_ENABLED = True +SECRET_KEY = 'you-will-never-guess' + +OPENID_PROVIDERS = [ + { 'name': 'Google', 'url': 'https://www.google.com/accounts/o8/id' }, + { 'name': 'Yahoo', 'url': 'https://me.yahoo.com' }, + { 'name': 'AOL', 'url': 'http://openid.aol.com/' }, + { 'name': 'Flickr', 'url': 'http://www.flickr.com/' }, + { 'name': 'MyOpenID', 'url': 'https://www.myopenid.com' }] \ No newline at end of file