Fixed minimal version, works with Django 1.7+, tested on Django 1.9.
Add the following to your settings:
AUTHENTICATION_BACKENDS = [
'project.backends.UserModelEmailBackend', # Login w/ email
'django.contrib.auth.backends.ModelBackend', # Login w/ username
]
Update to https://djangosnippets.org/snippets/1907/ to be a bit more flexible, and code cleaned up a tiny bit.
To use, add this snippet as a file in a templatetags folder in an app or in a project. Then include and call the tag with
{% obfuscate_email 'email' %}
or
{% obfuscate_email 'email' 'link_text' %}
if 'link_text' is provided, it will be used as the text in the body of the <a> tag. If not, then the email will be used.
Instead of the default Django User the Auth Model is 'customer' from the usercp App.
User's can use username as a display to the public, without disclosing their login information. This way they can use a forum with their username, which is seen by everyone.
The login credentials, however are more privat, since it is the e-mail address. Allowing the user to not disclose any information.
Start simple SMTP server on localhost:25 and print to standard output all email headers and the email body. Useful for debugging outgoing mail without configuring SMTP daemon in development enviroment.
Yet another authentication by email address. This one is quick and dirty as we are saving email address in both Username and Email fields. For proper way how to deal with it see
https://docs.djangoproject.com/en/1.6/topics/auth/customizing/#auth-custom-user
Function that takes a bound form (submitted form) and returns a list of pairs of field label and user chosen value.
It takes care of:
1. fields that are not filled out
2. if you want to exclude some fields from the final list
3. ChoiceField (select or radio button)
4. MultipleChoiceField (multi-select or checkboxes)
Usage:
if form.is_valid():
form_data = get_form_display_data(form, exclude=['captcha'])
It's trivial to display the list of pairs in a template:
{% for key, value in form_data %}
{{ key }}: {{ value }}{% endfor %}
Validate form field that include email or emails separated by 'token' kwargs, by default ',' a comma. Return a list [] of email(s). Check validity of the email(s) from django EmailField regex (tested with 1.3, but normally will also work with 1.5)
Beware if using Amazon Simple Queue Service to execute Celery tasks which send email messages! Sometimes SQS messages are duplicated which results in multiple copies of the messages being sent. This is a simple decorator which uses a cache backend to prevent the task from executing twice in a specified period. For example:
@task
@execute_once_in(3600*24*7)
def cron_first_week_follow_up():
"""
Send a follow-up email to new users!
"""
pass
For more info see
<http://atodorov.org/blog/2013/12/06/duplicate-amazon-sqs-messages-cause-multiple-emails/>
<http://atodorov.org/blog/2013/12/11/idempotent-django-email-sender-with-amazon-sqs-and-memcache/>
I had issues getting [snippet 285](https://djangosnippets.org/snippets/285/) working when using a MIMEBase subclass (ie.. MIMEImage).
This modification to [snippet 285](https://djangosnippets.org/snippets/285/).
The backend lets you quickly get an idea of all emails that are sent out. Helpful for debugging or keeping an archive of all communications. Use instead of Django's SMTPBackend.