Giter Club home page Giter Club logo

django-registration-email's Introduction

Important

This app has been discontinued due to the give-up of django-registration. Also there are a lot of well developed and more extensive alternatives on the market.

Why don't you check out django-allauth: https://github.com/pennersr/django-allauth

It's already integrated in our project template (incl. templates & settings): https://github.com/bitmazk/django-project-template/ It's configured the way we used this app.

django-registration-email

We use django-registration in almost all our projects. However, we don't like Django's limited username and would like to allow our users to sign up via email.

This project provides a custom authentication backend which allows users to authenticate via email. We also provide an EmailRegistrationForm which checks if an email has already been taken.

Since we still have to store a username and since emails can easily be longer than 30 characters, the username will be computed as a md5 hexdigest of the email address.

We included a urls.py that overrides all URLs of django-registration and Django's auth with a clean and sane structure and you will find a default set of all necessary templates.

Usage

Install this package::

pip install -e git://github.com/bitmazk/django-registration-email#egg=registration_email

Add registration and registration_email to your INSTALLED_APPS::

INSTALLED_APPS = [
    # all your other apps
    'registration',
    'registration_email',
]

Update your urls.py::

url(r'^accounts/', include('registration_email.backends.default.urls')),

Add some settings to your settings.py::

ACCOUNT_ACTIVATION_DAYS = 7
AUTHENTICATION_BACKENDS = (
    'registration_email.auth.EmailBackend',
)
LOGIN_REDIRECT_URL = '/'

Run syncdb::

./manage.py syncdb

Settings

django-registration-email introduces a new setting:

REGISTRATION_EMAIL_ACTIVATE_SUCCESS_URL

Default: lambda request, user: '/'

Function to return the URL to redirect to after a successful account activation. If you leave this at lambda request, user: '/' it will direct to your base URL.

REGISTRATION_EMAIL_REGISTER_SUCCESS_URL

Default: lambda request, user: '/'

Function to return the URL to redirect to after a successful account registration. If you leave this at lambda request, user: '/' it will direct to your base URL.

How to use a custom form

Let's say you want to collect the user's first name and last name when he registers. In order to achieve that, you need to do the following:

1. Create a custom form

Create a new app my_registration in your project and give it a forms.py where you override our EmailRegistrationForm and your desired extra fields:

from django import forms
from registration_email.forms import EmailRegistrationForm

class CustomEmailRegistrationForm(EmailRegistrationForm):
    first_name = forms.CharField()
    last_name = forms.CharField()

Do NOT override the form's save() method.

2. Override the URL

Now you need to tell the registration view that it is supposed to use the custom form:

# your main urls.py
...
from django.conf import settings
from registration.backends.simple.views import RegistrationView
from my_registration.forms import CustomEmailRegistrationForm

urlpatterns = [
    ...
    url(
        r'^accounts/register/$',
        RegistrationView.as_view(
            template_name='registration/registration_form.html',
            form_class=CustomEmailRegistrationForm,
            get_success_url=getattr(
                settings, 'REGISTRATION_EMAIL_REGISTER_SUCCESS_URL',
                lambda request, user: '/'),
        ),
        name='registration_register',
    ),

    url(r'^accounts/', include('registration_email.backends.default.urls')),
    ...
]

3. Create a signal handler

In the urls.py above I'm using the SimpleBackend. When you have a look at that backend you will see that the backend sends a signal after creating and logging in the user. The signal will get all parameters that we need in order to access the data that has been validated and sent by the form, so let's build a signal handler:

# in my_registration.models.py
from django.dispatch import receiver
from registration.signals import user_registered

@receiver(user_registered)
def user_registered_handler(sender, user, request, **kwargs):
    user.first_name = request.POST.get('first_name')
    user.last_name = request.POST.get('last_name')
    user.save()

This method has the drawback that you save the user two times in a row. If you have concerns about performance you would have to create your own my_registration.backends.CustomRegistrationBackend class. That class would inherit registration.backends.simple.SimpleBackend and override the register method.

But really, we are talking about registration here, I can't imagine how saving the user twice could do any harm.

Troubleshooting

If you had another value for AUTHENTICATION_BACKENDS in your settings.py before it might be that it is saved in your django_session table. I found no other way around this than to delete the rows in that table.

TODO

  • Password reset link points to original django template

django-registration-email's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

django-registration-email's Issues

error: [Errno 10061] No connection could be made because the target machine actively refused it

Hi all,
I want to retrieve information about all the vms running on ESX server. I have found two modules suitable for my requirement. pysphere and psphere. But when I try to connect to the remote server it throws me the following error.

  1. psphere:
    URLError: <urlopen error [Errno 10061] No connection could be made because the target machine actively refused it>
  2. pysphere:
    error: [Errno 10061] No connection could be made because the target machine actively refused it

Can anyone please help me to resolve this issue. Thanks in advance.

-Vinay Kalyankar.

Not compatible with django-registration 1.0?

Installed both apps with pip. Followed instructions in your readme file. It seems that your app is not compatible with the class based views of django-registration?

here the error:
ImportError at /accounts/register/
cannot import name activate

and the line where the import is not working:

.../src/registration-email/registration_email/backends/default/urls.py in
6. from registration.views import activate, register

Fix pip install instruction

The readme says to install with:
pip install -e https://github.com/bitmazk/django-registration-email#egg=registration_email
but it should be:
pip install -e git://github.com/bitmazk/django-registration-email#egg=registration_email

If you run it the way you have it you will get the below error.
--editable=https://github.com/bitmazk/django-registration-email#egg=registration_email should be formatted with svn+URL, git+URL, hg+URL or bzr+URL

Exception information:
Traceback (most recent call last):
File "/home/johnny/.virtualenvs/elasticiti/local/lib/python2.7/site-packages/pip-1.1-py2.7.egg/pip/basecommand.py", line 104, in main
status = self.run(options, args)
File "/home/johnny/.virtualenvs/elasticiti/local/lib/python2.7/site-packages/pip-1.1-py2.7.egg/pip/commands/install.py", line 217, in run
InstallRequirement.from_editable(name, default_vcs=options.default_vcs))
File "/home/johnny/.virtualenvs/elasticiti/local/lib/python2.7/site-packages/pip-1.1-py2.7.egg/pip/req.py", line 65, in from_editable
name, url = parse_editable(editable_req, default_vcs)
File "/home/johnny/.virtualenvs/elasticiti/local/lib/python2.7/site-packages/pip-1.1-py2.7.egg/pip/req.py", line 1318, in parse_editable
'--editable=%s should be formatted with svn+URL, git+URL, hg+URL or bzr+URL' % editable_req)
InstallationError: --editable=https://github.com/bitmazk/django-registration-email#egg=registration_email should be formatted with svn+URL, git+URL, hg+URL or bzr+URL

Use with custom user model

I am using a custom user model and trying to use django-registration-email.

However, it gives me the following error:-

Manager isn't available; User has been swapped for 'thursdayfootball.Player'

Obviously, Player is my user model.
Is it possible to use this with a custom user model? If so, what do I need to do?

After installing using "pip install -e ... git:...", adding to INSTALLED_APPS and then running "python manage.py syncdb" I get "django.core.exceptions.ImproperlyConfigured: ImportError registration: No module named registration"

Hello,

Thanks for making this package available. I get the following error after running "python manage.py syncdb" (and before that following all the installation instructions until that point in the README file):

django.core.exceptions.ImproperlyConfigured: ImportError registration: No module named registration

I am using django 1.5 with python 2.7, and using virtualenv, on a Mac OS X 10.8.3.

Could you please advise? Many thanks!

"correct" way to add name to the registration form

I'm excited to have found this package for its core purpose of using email address as Django username. I'm also interested in collecting the user's name during registration. Do you have any advice on how to alter the form, but still be able to incorporate future versions of django-registration-email?

Custom Form problem

I followed the steps from "How to use a custom form", but after that,
when user is registering (with first_name and last_name fields ) account is automatically activate and activation email is not send.
Is it bug or wrong configuration?

Change the username when the email address changes?

Hi,

I saw that the username will be computed as a md5 hexdigest.
However, is it recalculated any time the email address changes?
I changed it in the admin and I did not see the username change.
It can lead to a problem at some point if people update their email address but the username md5 hexdigest are still based on the old email addresses.

What do you think?
Thanks

some bug with your_name field

on register page i see form with fields:
Email:
Password:
Password (repeat):
Your name:

All fields visible

but after 100500 unsuccessful enter name i open source code of forms.py and found it:
data = self.cleaned_data
if data.get('your_name'):
# Bot protection. The name field is not visible for human users.
raise forms.ValidationError(_('Please enter a valid name.'))

if your_name is fake field why i see it in form?

Fix pip install instruction

The readme says to install with:
pip install -e https://github.com/bitmazk/django-registration-email#egg=registration_email
but it should be:
pip install -e git://github.com/bitmazk/django-registration-email#egg=registration_email

If you run it the way you have it you will get the below error.
--editable=https://github.com/bitmazk/django-registration-email#egg=registration_email should be formatted with svn+URL, git+URL, hg+URL or bzr+URL

Exception information:
Traceback (most recent call last):
File "/home/johnny/.virtualenvs/elasticiti/local/lib/python2.7/site-packages/pip-1.1-py2.7.egg/pip/basecommand.py", line 104, in main
status = self.run(options, args)
File "/home/johnny/.virtualenvs/elasticiti/local/lib/python2.7/site-packages/pip-1.1-py2.7.egg/pip/commands/install.py", line 217, in run
InstallRequirement.from_editable(name, default_vcs=options.default_vcs))
File "/home/johnny/.virtualenvs/elasticiti/local/lib/python2.7/site-packages/pip-1.1-py2.7.egg/pip/req.py", line 65, in from_editable
name, url = parse_editable(editable_req, default_vcs)
File "/home/johnny/.virtualenvs/elasticiti/local/lib/python2.7/site-packages/pip-1.1-py2.7.egg/pip/req.py", line 1318, in parse_editable
'--editable=%s should be formatted with svn+URL, git+URL, hg+URL or bzr+URL' % editable_req)
InstallationError: --editable=https://github.com/bitmazk/django-registration-email#egg=registration_email should be formatted with svn+URL, git+URL, hg+URL or bzr+URL

Logging in with email does not worl

Hi,

Thanks for the registration-email framework. Very useful!

I ran into a problem when trying to login. When using email address and password to login, the framework does not recognize the credentials. When I use username directly in the email field and the password, the login works successfully.
Has this issue been reported previously? Shouldn't there be a code snippet that retrieves the username based on the email id provided and supplies it for logging in.

Thanks!

Exception caused when used with django-registration 1.0

When using latest pull of django-registration-email, with django-registration 1.0 (latest as of this writeup), on Django 1.5.1, I'm getting the following exception:

File "/home/jeryn/..../registration_email/backends/default/urls.py", line 6, in
from registration.views import activate, register
ImportError: cannot import name activate

I think this is because the latest django-registration moved to class-based views. Can someone release a fix for this?

Errno 10061] No connection could be made because the target machine actively refused it

hi i have this working on local machine when im on accounts/register and try create a new user i get this error
^***************************+

error at /accounts/register/

[Errno 10061] No connection could be made because the target machine actively refused it

Request Method: POST
Request URL: http://127.0.0.1:8000/accounts/register/
Django Version: 1.5
Exception Type: error
Exception Value:

[Errno 10061] No connection could be made because the target machine actively refused it

Exception Location: C:\Python27\lib\socket.py in create_connection, line 571
Python Executable: C:\Python27\python.exe
Python Version: 2.7.3
Python Path:

['C:\Users\ujake\impromusic\impromusic',
'C:\Python27\lib\site-packages\distribute-0.6.35-py2.7.egg',
'C:\Python27\lib\site-packages\django_audiotracks-0.2.1-py2.7.egg',
'C:\Python27\lib\site-packages\mutagen-1.20-py2.7.egg',
'C:\Python27\lib\site-packages\django_registration_email-0.5-py2.7.egg',
'C:\Windows\system32\python27.zip',
'C:\Python27\DLLs',
'C:\Python27\lib',
'C:\Python27\lib\plat-win',
'C:\Python27\lib\lib-tk',
'C:\Python27',
'C:\Python27\lib\site-packages',
'C:\Python27\lib\site-packages\PIL',
'C:\Python27\lib\site-packages\setuptools-0.6c11-py2.7.egg-info']

Server time: Tue, 26 Mar 2013 03:55:14 +0100
Traceback Switch to copy-and-paste view

C:\Python27\lib\site-packages\django\core\handlers\base.py in get_response

                            response = callback(request, *callback_args, **callback_kwargs)

    ...
▶ Local vars
C:\Python27\lib\site-packages\registration\views.py in register

                new_user = backend.register(request, **form.cleaned_data)

    ...
▶ Local vars
C:\Python27\lib\site-packages\registration\backends\default\__init__.py in register

                                                                        password, site)

    ...
▶ Local vars
C:\Python27\lib\site-packages\django\db\transaction.py in inner

                    return func(*args, **kwargs)

    ...
▶ Local vars
C:\Users\ujake\impromusic\impromusic\impromusic\apps\registration\models.py in create_inactive_user

                registration_profile.send_activation_email(site)

    ...
▶ Local vars
C:\Users\ujake\impromusic\impromusic\impromusic\apps\registration\models.py in send_activation_email

            self.user.email_user(subject, message, settings.DEFAULT_FROM_EMAIL)

    ...
▶ Local vars
C:\Python27\lib\site-packages\django\contrib\auth\models.py in email_user

            send_mail(subject, message, from_email, [self.email])

    ...
▶ Local vars
C:\Python27\lib\site-packages\django\core\mail\__init__.py in send_mail

                            connection=connection).send()

    ...
▶ Local vars
C:\Python27\lib\site-packages\django\core\mail\message.py in send

            return self.get_connection(fail_silently).send_messages([self])

    ...
▶ Local vars
C:\Python27\lib\site-packages\django\core\mail\backends\smtp.py in send_messages

                new_conn_created = self.open()

    ...
▶ Local vars
C:\Python27\lib\site-packages\django\core\mail\backends\smtp.py in open

                                               local_hostname=DNS_NAME.get_fqdn())

    ...
▶ Local vars
C:\Python27\lib\smtplib.py in __init__

                (code, msg) = self.connect(host, port)

    ...
▶ Local vars
C:\Python27\lib\smtplib.py in connect

            self.sock = self._get_socket(host, port, self.timeout)

    ...
▶ Local vars
C:\Python27\lib\smtplib.py in _get_socket

            return socket.create_connection((port, host), timeout)

    ...
▶ Local vars
C:\Python27\lib\socket.py in create_connection

            raise err

    ...
▶ Local vars 

Do i have to configure the email server on settings.py for use your app?

best practice on updating email address

I think updating a user's email address is as simple as editing the email property of django's User object and that seems to work - django-registration-email seems to recognize the udpated email address upon the next authentication. If correct, I think it'd be helpful to share with others. Where would be a good place to include that, in the FAQ?

Something like:
How do I allow users to update their email address?
Have users update their email address through a form field, overwriting the email property of django's User object.

hashed username in password reset email?

This is what the rendered password reset email looks like for me.

I'm a little baffled by the sentence with the hashed username showing up in the email. I don't see it in the template that I believe to otherwise be the source: https://github.com/bitmazk/django-registration-email/blob/master/registration_email/templates/registration/password_reset_email.html

Can anyone clue me in to how that sentence gets into the rendered email and how I'd get rid of it or replace the hashed username with the user's email?

-Nate

rendered email below:

You're receiving this email because you requested a password reset for your user account at [site name].

Please go to the following page and choose a new password:

http://[site domain]/accounts/password/reset/confirm/3-3lg-ae24b0904f4c874249a0/

Your username, in case you've forgotten: e81a516598ce748b8c5b17bde8db60

Thanks for using our site!

The [site name] team

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.