Skip to content

Instantly share code, notes, and snippets.

@jtauber jtauber/zero...account.diff Secret
Last active Nov 19, 2015

Embed
What would you like to do?
diff --git a/requirements.txt b/requirements.txt
index 016a56b..043e5a4 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1,2 +1,6 @@
Django==1.8.5
pinax-theme-bootstrap==7.1.1
+django-user-accounts==1.2
+metron==1.3.5
+pinax-eventlog==1.0.0
+django-jsonfield==0.9.15
diff --git a/project_name/urls.py b/project_name/urls.py
index aeb47f8..2b7c766 100644
--- a/project_name/urls.py
+++ b/project_name/urls.py
@@ -1,8 +1,16 @@
-from django.conf.urls import patterns, url
+from django.conf import settings
+from django.conf.urls import patterns, include, url
+from django.conf.urls.static import static
from django.views.generic import TemplateView
+from django.contrib import admin
+
urlpatterns = patterns(
"",
url(r"^$", TemplateView.as_view(template_name="homepage.html"), name="home"),
+ url(r"^admin/", include(admin.site.urls)),
+ url(r"^account/", include("account.urls")),
)
+
+urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
diff --git a/project_name/settings.py b/project_name/settings.py
index e24d9a9..db2312b 100644
--- a/project_name/settings.py
+++ b/project_name/settings.py
@@ -94,6 +94,7 @@ TEMPLATES = [
"django.core.context_processors.tz",
"django.core.context_processors.request",
"django.contrib.messages.context_processors.messages",
+ "account.context_processors.account",
"pinax_theme_bootstrap.context_processors.theme",
],
},
@@ -116,6 +117,7 @@ ROOT_URLCONF = "{{ project_name }}.urls"
WSGI_APPLICATION = "{{ project_name }}.wsgi.application"
INSTALLED_APPS = [
+ "django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.messages",
@@ -127,6 +129,11 @@ INSTALLED_APPS = [
"bootstrapform",
"pinax_theme_bootstrap",
+ # external
+ "account",
+ "metron",
+ "pinax.eventlog",
+
# project
"{{ project_name }}",
]
@@ -165,3 +172,15 @@ FIXTURE_DIRS = [
]
EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend"
+
+ACCOUNT_OPEN_SIGNUP = True
+ACCOUNT_EMAIL_UNIQUE = True
+ACCOUNT_EMAIL_CONFIRMATION_REQUIRED = False
+ACCOUNT_LOGIN_REDIRECT_URL = "home"
+ACCOUNT_LOGOUT_REDIRECT_URL = "home"
+ACCOUNT_EMAIL_CONFIRMATION_EXPIRE_DAYS = 2
+ACCOUNT_USE_AUTH_AUTHENTICATE = True
+
+AUTHENTICATION_BACKENDS = [
+ "account.auth_backends.UsernameAuthenticationBackend",
+]
diff --git a/project_name/apps.py b/project_name/apps.py
index 405a174..0233c3b 100644
--- a/project_name/apps.py
+++ b/project_name/apps.py
@@ -1,6 +1,11 @@
+from importlib import import_module
+
from django.apps import AppConfig as BaseAppConfig
class AppConfig(BaseAppConfig):
name = "{{ project_name }}"
+
+ def ready(self):
+ import_module("{{ project_name }}.receivers")
diff --git a/project_name/receivers.py b/project_name/receivers.py
new file mode 100644
index 0000000..5aa22c9
--- /dev/null
+++ b/project_name/receivers.py
@@ -0,0 +1,59 @@
+from django.dispatch import receiver
+
+from account.signals import password_changed
+from account.signals import user_sign_up_attempt, user_signed_up
+from account.signals import user_login_attempt, user_logged_in
+
+from pinax.eventlog.models import log
+
+
+@receiver(user_logged_in)
+def handle_user_logged_in(sender, **kwargs):
+ log(
+ user=kwargs.get("user"),
+ action="USER_LOGGED_IN",
+ extra={}
+ )
+
+
+@receiver(password_changed)
+def handle_password_changed(sender, **kwargs):
+ log(
+ user=kwargs.get("user"),
+ action="PASSWORD_CHANGED",
+ extra={}
+ )
+
+
+@receiver(user_login_attempt)
+def handle_user_login_attempt(sender, **kwargs):
+ log(
+ user=None,
+ action="LOGIN_ATTEMPTED",
+ extra={
+ "username": kwargs.get("username"),
+ "result": kwargs.get("result")
+ }
+ )
+
+
+@receiver(user_sign_up_attempt)
+def handle_user_sign_up_attempt(sender, **kwargs):
+ log(
+ user=None,
+ action="SIGNUP_ATTEMPTED",
+ extra={
+ "username": kwargs.get("username"),
+ "email": kwargs.get("email"),
+ "result": kwargs.get("result")
+ }
+ )
+
+
+@receiver(user_signed_up)
+def handle_user_signed_up(sender, **kwargs):
+ log(
+ user=kwargs.get("user"),
+ action="USER_SIGNED_UP",
+ extra={}
+ )
diff --git a/project_name/templates/_account_bar.html b/project_name/templates/_account_bar.html
index e69de29..08b2e77 100644
--- a/project_name/templates/_account_bar.html
+++ b/project_name/templates/_account_bar.html
@@ -0,0 +1,26 @@
+{% load i18n %}
+{% load account_tags %}
+
+
+<ul class="nav navbar-nav pull-right">
+ {% if request.user.is_authenticated %}
+ <p class="navbar-text">
+ <i class="fa fa-user"></i> {% user_display request.user %}
+ </p>
+ <li>
+ <a href="{% url 'account_settings' %}"><i class="fa fa-cog"></i> {% trans "Settings" %}</a>
+ </li>
+ <li>
+ <a id="account_logout" href="{% url 'account_logout' %}"><i class="fa fa-power-off"></i> {% trans "Log out" %}</a>
+ </li>
+ {% else %}
+ <li><a href="{% url 'account_login' %}">{% trans "Log in" %}</a></li>
+ {% if ACCOUNT_OPEN_SIGNUP %}
+ <li><a href="{% url 'account_signup' %}">{% trans "Sign up" %}</a></li>
+ {% endif %}
+ {% endif %}
+</ul>
+
+<form id="accountLogOutForm" style="display: none;" action="{% url 'account_logout' %}" method="POST">
+ {% csrf_token %}
+</form>
diff --git a/project_name/templates/homepage.html b/project_name/templates/homepage.html
index 63ccca7..5bcca1f 100644
--- a/project_name/templates/homepage.html
+++ b/project_name/templates/homepage.html
@@ -2,7 +2,7 @@
{% load i18n %}
-{% block head_title %}pinax-project-zero{% endblock %}
+{% block head_title %}pinax-project-account{% endblock %}
{% block body_class %}home{% endblock %}
@@ -10,14 +10,20 @@
<section class="jumbotron">
<div class="container">
{% include "_messages.html" %}
- <h1>{% blocktrans %}Welcome to<br>pinax-project-zero{% endblocktrans %}</h1>
+ <h1>{% blocktrans %}Welcome to<br>pinax-project-account{% endblocktrans %}</h1>
<p>
{% blocktrans %}
- This project lays the foundation for all other Pinax starter projects.
- It provides the project directory layout on which the other starter
- projects are based.
+ In addition to what is provided by the "zero" project, this project
+ provides thorough integration with django-user-accounts, adding
+ comprehensive account management functionality. It is a foundation
+ suitable for most sites that have user accounts.
{% endblocktrans %}
</p>
+ {% if not user.is_authenticated %}
+ {% url "account_login" as login_url %}
+ {% url "account_signup" as signup_url %}
+ <p>{% blocktrans %}You can <a href="{{ login_url }}" class="btn btn-default">Log In</a> or <a href="{{ signup_url }}" class="btn btn-primary">Sign Up</a> to try out the site.{% endblocktrans %}</p>
+ {% endif %}
</div>
</section>
<section>
diff --git a/project_name/templates/site_base.html b/project_name/templates/site_base.html
index 7221602..13b2da7 100644
--- a/project_name/templates/site_base.html
+++ b/project_name/templates/site_base.html
@@ -1,13 +1,10 @@
{% extends "theme_bootstrap/base.html" %}
{% load staticfiles %}
+{% load metron_tags %}
{% load i18n %}
-{# remove to bring back topbar #}
-{% block topbar_base %}{% endblock %}
-
-
{% block styles %}
{% include "_styles.html" %}
{% endblock %}
@@ -28,5 +25,6 @@
{% endblock %}
{% block extra_body_base %}
+ {% analytics %}
{% block extra_body %}{% endblock %}
{% endblock %}
diff --git a/static/src/less/account.less b/static/src/less/account.less
new file mode 100644
index 0000000..41a51dc
--- /dev/null
+++ b/static/src/less/account.less
@@ -0,0 +1,8 @@
+body.account-settings .account-settings,
+body.account-password .account-password,
+body.account-delete .account-delete {
+ z-index: 2; // Place active items above their siblings for proper border styling
+ color: @list-group-active-color;
+ background-color: @list-group-active-bg;
+ border-color: @list-group-active-border;
+}
\ No newline at end of file
diff --git a/static/src/less/site.less b/static/src/less/site.less
index 37295ea..cf4490e 100644
--- a/static/src/less/site.less
+++ b/static/src/less/site.less
@@ -10,6 +10,8 @@
@font-family-serif: Georgia, "Times New Roman", Times, serif;
@font-family-monospace: Menlo, Monaco, Consolas, "Courier New", monospace;
+// Account
+@import "account.less";
// Site overrides
@import "custom.less";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.