Email Validation with Django and python-social-auth

Photo by Onlineprinters on Unsplash

So you’re asking yourself – robot or real person?

When it comes to user accounts, the standard litmus test is email validation. Besides the immediate benefits – of offering us a straightforward unique identifier for users, and making it more difficult to automate creating a mass of accounts on our service – by requiring that each account have an email address and interact therewith to confirm the addresses validity, it also offers us the chance to associate a known-working email account with a user account. This is important for transactional emails such as password resets or for potential two-factor authentication use… and if you’re a little less ethical, for sending marketing desirable and informative emails about interesting products and services.

"But," you whine piteously, "the whole reason I integrated python-social-auth into my project was to let the OAuth providers look after this sort of thing for me!"

Tough rocks. Twitter ain’t gonna give you their users’ email addresses. Just look at all those angry comments. If their whining didn’t get through to Twitter, yours isn’t going to do the trick either. Besides, eventually you’ll probably want to allow the user to login the good old-fashioned way, with a username (which may or may not be their email address) and a password – in which case, you’ll want to handle validating their email address yourself anyways.

So, given that we’ve already integrated python-social-auth into our Django project (some of the same principles will apply to other frameworks, but many of the details presented herein are specified to Django) – let’s get email validation working as part of our user creation/authentication pipeline.

(more…)

Adding Dynamically Named Methods to Python Classes

Photo by Inbetween Architects on Unsplash

I recently wanted to dynamically add methods to a Python class based on a list of relationships. The model class, Animal, was related to a number of description classes like Color and Sound. For a given animal, I wanted to be able to easily get the values for its descriptions, such as:

elephant.color_values()
# => ['gray', 'silver', 'taupe']

Although I could have simply written non-dynamic methods like color_values, noise_values, etc. in the Animal class, I had already defined a list of the relevant class names and I prefer not repeating code. So instead I dove into Python’s dynamic pool.

(more…)

2014 Review: Day 9

software screenshot

Taking an opportunity to look back at some of our most-read posts from this year, in case you missed them the first time, as the last few days of the year slip by us…

In our penultimate look back at 2014’s developer blog, Fran Bull talks about using interactive widgets inside of IPython notebooks:

(more…)

2014 Review: Day 8

Taking an opportunity to look back at some of our most-read posts from this year, in case you missed them the first time, as the last few days of the year slip by us…

William Allen White

William Allen White

 

My turn! Earlier this year I wrote about a little Twitterbot that I wrote to periodically tweet out snippets of lyrics from songs by the band They Might Be Giants…

(more…)

2014 Review: Day 4

As 2014 winds down, we’re taking an opportunity to look back at some of our most-read posts from this year, in case you missed them the first time. 

Django logo

Vlad Orlenko wrote a couple of great posts on integrating social logins and posting with web apps written using the Django web app framework:

(more…)