]> git.parisson.com Git - django-social-auth.git/commitdiff
Example app styling
authorMatías Aguirre <matiasaguirre@gmail.com>
Thu, 6 Jan 2011 02:46:22 +0000 (00:46 -0200)
committerMatías Aguirre <matiasaguirre@gmail.com>
Thu, 6 Jan 2011 02:46:22 +0000 (00:46 -0200)
example/app/templates/base.html [new file with mode: 0644]
example/app/templates/done.html [new file with mode: 0644]
example/app/templates/error.html [new file with mode: 0644]
example/app/templates/home.html [new file with mode: 0644]
example/app/views.py

diff --git a/example/app/templates/base.html b/example/app/templates/base.html
new file mode 100644 (file)
index 0000000..e9f3532
--- /dev/null
@@ -0,0 +1,73 @@
+<html>
+  <head>
+    <title>Social authentication | {% block title %}{% endblock %}</title>
+    <style>
+      body {
+        background-color: #eee;
+        padding: 10px 20px;
+        font-family: sans-serif;
+        color: #333;
+      }
+      h1 {
+        font-size: 1.5em;
+        border-bottom: 1px solid #ddd;
+        width: 95%;
+      }
+      h2 {
+        font-size: 1.2em;
+      }
+      a, a:visited {
+        color: #459FDA;
+        text-decoration: none;
+      }
+      a:hover {
+        text-decoration: underline;
+      }
+      input[type="text"] {
+        border: 1px solid #ccc;
+        padding: 3px;
+        width: 300px;
+      }
+      input[type="submit"] {
+        padding: 2px 20px;
+        margin-left: -5px;
+      }
+      label {
+        display: block;
+      }
+      th {
+        text-align: left;
+        padding-right: 25px;
+        font-weight: normal;
+      }
+      tr.even {
+        background-color: #ddd;
+      }
+      #content {
+        padding: 5px 20px;
+      }
+      .helptext {
+        font-size: 0.9em;
+        color: #aaa;
+        margin: 0;
+        padding: 0;
+      }
+      a.logout, .associated, .error {
+        color: #c00;
+      }
+      #forkme {
+        position: absolute;
+        top: 0;
+        right: 0;
+        border: 0;
+      }
+    </style>
+  </head>
+  <body>
+    <h1>{% block heading %}{% endblock %}</h1>
+    <div id="content">
+      {% block content %}{% endblock %}
+    </div>
+    <a id="forkme" href="http://github.com/omab/django-social-auth"><img src="https://assets2.github.com/img/e6bef7a091f5f3138b8cd40bc3e114258dd68ddf?repo=&url=http%3A%2F%2Fs3.amazonaws.com%2Fgithub%2Fribbons%2Fforkme_right_red_aa0000.png&path=" alt="Fork me on GitHub"></a>
+  </body>
+</html>
diff --git a/example/app/templates/done.html b/example/app/templates/done.html
new file mode 100644 (file)
index 0000000..a28fa04
--- /dev/null
@@ -0,0 +1,55 @@
+{% extends "base.html" %}
+{% block title %}Logged in{% endblock %}
+
+{% block heading %}Logged in!{% endblock %}
+
+{% block content %}
+<div>
+  <h2>User data:</h2>
+  <table>
+    <tr class="odd"><th>Id:</th> <td>{{ user.id }}</td></tr>
+    <tr class="even"><th>Username:</th> <td>{{ user.username }}</td></tr>
+    <tr class="odd"><th>Email:</th> <td>{{ user.email|default:"Not provided" }}</td></tr>
+    <tr class="even"><th>First name:</th> <td>{{ user.first_name|default:"Not provided" }}</td></tr>
+    <tr class="odd"><th>Last name:</th> <td>{{ user.last_name|default:"Not provided" }}</td></tr>
+  </table>
+</div>
+
+<div>
+  <h2>Associate new credentials:</h2>
+  <ul>
+    <li>
+      <a href="/associate/twitter/">Twitter</a>
+      {% if twitter %}<span class="associated">(associated)</span>{% endif %}
+    </li>
+    <li>
+      <a href="/associate/facebook/">Facebook</a>
+      {% if facebook %}<span class="associated">(associated)</span>{% endif %}
+    </li>
+    <li>
+      <a href="/associate/orkut/">Orkut</a>
+      {% if orkut %}<span class="associated">(associated)</span>{% endif %}
+    </li>
+    <li>
+      <a href="/associate/google/">Google</a>
+      {% if google %}<span class="associated">(associated)</span>{% endif %}
+    </li>
+    <li>
+      <a href="/associate/yahoo/">Yahoo</a>
+      {% if yahoo %}<span class="associated">(associated)</span>{% endif %}
+    </li>
+
+    <li>
+      <form action="/associate/openid/" method="post">{% csrf_token %}
+        <label for="openid_identifier">Other provider:</label>
+        <input id="openid_identifier" type="text" value="" name="openid_identifier" />
+        <input type="submit" />
+      </form>
+    </li>
+  </ul>
+</div>
+
+<div>
+  <a class="logout" href="/logout/">Logout</a>
+</div>
+{% endblock %}
diff --git a/example/app/templates/error.html b/example/app/templates/error.html
new file mode 100644 (file)
index 0000000..99e1e58
--- /dev/null
@@ -0,0 +1,11 @@
+{% extends "base.html" %}
+{% block title %}Error{% endblock %}
+
+{% block heading %}Error!{% endblock %}
+
+{% block content %}
+<div>
+  <p class="error">Sorry but some error made you impossible to login.</p>
+  <p>Please try again <a href="/">Home</a></p>
+</div>
+{% endblock %}
diff --git a/example/app/templates/home.html b/example/app/templates/home.html
new file mode 100644 (file)
index 0000000..67252cc
--- /dev/null
@@ -0,0 +1,31 @@
+{% extends "base.html" %}
+{% block title %}Login{% endblock %}
+
+{% block heading %}Login using any of the following methods{% endblock %}
+
+{% block content %}
+<div>
+  <h2>Login using <a href="http://oauth.net/">OAuth</a> from:</h2>
+  <ul>
+    <li><a href="/login/twitter/">Twitter</a></li>
+    <li><a href="/login/facebook/">Facebook</a></li>
+    <li><a href="/login/orkut/">Orkut</a></li>
+  </ul>
+</div>
+
+<div>
+  <h2>Login using <a href="http://openid.net/">OpenId</a> from:</h2>
+  <ul>
+    <li><a href="/login/google/">Google</a></li>
+    <li><a href="/login/yahoo/">Yahoo</a></li>
+    <li>
+      <form action="/login/openid/" method="post">{% csrf_token %}
+        <label for="openid_identifier">Other provider</label>
+        <input id="openid_identifier" type="text" value="" name="openid_identifier" />
+        <input type="submit" />
+        <p class="helptext">Like your personal <a href="https://www.myopenid.com/" title="My OpenId">myopenid</a></p>
+      </form>
+    </li>
+  </ul>
+</div>
+{% endblock %}
index 690c0695440b7d898b2277f1399e305eb7f2b5de..74d2cffddb2188962925852d47aa929e76bcc65f 100644 (file)
-from django.http import HttpResponseRedirect, HttpResponse
+from django.http import HttpResponseRedirect
 from django.contrib.auth import logout as auth_logout
 from django.contrib.auth.decorators import login_required
-from django.template import Template, Context, RequestContext
+from django.template import RequestContext
+from django.shortcuts import render_to_response
 
 
 def home(request):
+    """Home view, displays login mechanism"""
     if request.user.is_authenticated():
         return HttpResponseRedirect('done')
-    return HttpResponse(Template(
-    """
-    <html>
-      <head>
-        <title>Social access</title>
-      </head>
-      <body>
-        <h1>Login using any of the following methods:</h1>
-        <div style="padding-left: 30px;">
-          <div>
-            <h2>Login using <a href="http://oauth.net/">OAuth</a> from:</h2>
-            <ul>
-              <li><a href="/login/twitter/">Twitter</a></li>
-              <li><a href="/login/facebook/">Facebook</a></li>
-              <li><a href="/login/orkut/">Orkut</a></li>
-            </ul>
-          </div>
-          <div>
-            <h2>Login using <a href="http://openid.net/">OpenId</a> from:</h2>
-            <ul>
-              <li><a href="/login/google/">Google</a></li>
-              <li><a href="/login/yahoo/">Yahoo</a></li>
-              <li>
-                <form action="/login/openid/" method="post">{% csrf_token %}
-                  <label for="openid_identifier">Other provider:</label>
-                  <input id="openid_identifier" type="text" value="" name="openid_identifier" />
-                  <input type="submit" />
-                </form>
-              </li>
-            </ul>
-          </div>
-        </div>
-      </body>
-    </html>
-    """).render(Context(RequestContext(request))),
-    content_type='text/html;charset=UTF-8')
+    else:
+        return render_to_response('home.html', None, RequestContext(request))
 
 @login_required
 def done(request):
+    """Login complete view, displays user data"""
     names = request.user.social_auth.values_list('provider', flat=True)
-    return HttpResponse(Template(
-    """
-    <html>
-      <head>
-        <title>Logged in</title>
-        <style>th{text-align: left;}</style>
-      </head>
-      <body>
-        <h1>Logged in!</h1>
-        <table>
-          <tr><th>Id:</th> <td>{{ user.id }}</td></tr>
-          <tr><th>Username:</th> <td>{{ user.username }}</td></tr>
-          <tr><th>Email:</th> <td>{{ user.email|default:"Not provided" }}</td></tr>
-          <tr><th>First name:</th> <td>{{ user.first_name|default:"Not provided" }}</td></tr>
-          <tr><th>Last name:</th> <td>{{ user.last_name|default:"Not provided" }}</td></tr>
-        </table>
-        <p><a href="/logout/">Logout</a></p>
-
-        <h2>Associate new credentials:</h2>
-        <div>
-          <ul>
-            <li><a href="/associate/twitter/">Twitter</a> {% if twitter %}(associated){% endif %}</li>
-            <li><a href="/associate/facebook/">Facebook</a> {% if facebook %}(associated){% endif %}</li>
-            <li><a href="/associate/orkut/">Orkut</a> {% if orkut %}(associated){% endif %}</li>
-            <li><a href="/associate/google/">Google</a> {% if google %}(associated){% endif %}</li>
-            <li><a href="/associate/yahoo/">Yahoo</a> {% if yahoo %}(associated){% endif %}</li>
-            <li>
-              <form action="/associate/openid/" method="post">{% csrf_token %}
-                <label for="openid_identifier">Other provider:</label>
-                <input id="openid_identifier" type="text" value="" name="openid_identifier" />
-                <input type="submit" />
-              </form>
-            </li>
-          </ul>
-        </div>
-      </body>
-    </html>
-    """).render(RequestContext(request, dict((name.lower(), True)
-                                                for name in names))),
-    content_type='text/html;charset=UTF-8')
-
+    return render_to_response('done.html',
+                              dict((name.lower(), True) for name in names),
+                              RequestContext(request))
 
 def error(request):
-    return HttpResponse(Template(
-    """
-    <html>
-      <head>
-        <title>Error</title>
-      </head>
-      <body>
-        <h1>Error!</h1>
-        <p>Sorry but some error made you impossible to login</p>
-        <a href="/">Homepage</a>
-      </body>
-    </html>
-    """).render(Context()),
-    content_type='text/html;charset=UTF-8')
+    """Error view"""
+    return render_to_response('error.html', None, RequestContext(request))
 
 def logout(request):
+    """Logs out user"""
     auth_logout(request)
     return HttpResponseRedirect('/')