Login

Django Registration with GMail account

Author:
btbytes
Posted:
March 29, 2007
Language:
Python
Version:
.96
Tags:
registration email gmail django-registration
Score:
7 (after 9 ratings)

This code works with Django-registration app found here: http://code.google.com/p/django-registration/ If you plan to use this django-registrtion code in your website to allow user registration but do not run your own email server,this snippet can be handy.

It uses gmail server to send out email. You have to install libgmail module first.

Add two lines to your settings.py GMAIL_USERNAME = '[email protected]' GMAIL_PASSWORD = 'your_password' Change models.py - create_inactive_user(...) as given above

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
  if send_email:            
      current_domain = Site.objects.get_current().domain
      subject = "Activate your new account at %s" %  current_domain
      message_template = loader.get_template('registration/activation_email.txt')
      message_context = Context({ 'site_url': 'http://%s/' % current_domain,
                                        'activation_key': activation_key,
                                        'expiration_days': settings.ACCOUNT_ACTIVATION_DAYS })
        message = message_template.render(message_context)
        ga = libgmail.GmailAccount(settings.GMAIL_USERNAME, settings.GMAIL_PASSWORD)
        ga.login()
        msg = libgmail.GmailComposedMessage(to=new_user.email, subject=subject, body=message)
        ga.sendMessage(msg)

More like this

  1. Serialize a model instance by chriswedgwood 1 week, 6 days ago
  2. Automatically setup raw_id_fields ForeignKey & OneToOneField by agusmakmun 9 months, 2 weeks ago
  3. Crispy Form by sourabhsinha396 10 months, 1 week ago
  4. ReadOnlySelect by mkoistinen 10 months, 2 weeks ago
  5. Verify events sent to your webhook endpoints by santos22 11 months, 2 weeks ago

Comments

woot4moo (on April 27, 2008):

I am going to save everyone a lot of heart ache here. Add these lines and that error will go away:

in create_inactive_user(...)

salt = sha.new(str(random.random())).hexdigest()[:5] activation_key = sha.new(salt+new_user.username).hexdigest()

and change profile_callback to this: if profile_callback is not None: profile_callback(user=new_user, activiation_key=activiation_key)

#

asinox (on September 3, 2009):

oliver.andrich is right.

#

Please login first before commenting.