- Author:
- marcossousa
- Posted:
- January 31, 2010
- Language:
- Python
- Version:
- 1.1
- Score:
- 1 (after 1 ratings)
Google autentication
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | #models.py
from django.conf import settings
from django.contrib.auth.models import User, check_password
from django.contrib.auth.backends import ModelBackend
from django.utils.translation import ugettext as _
import gdata.contacts
import gdata.contacts.service
class GoogleAuthenticator(ModelBackend):
def __init__(self):
"""Make autentication using a google account."""
self.google_service = gdata.contacts.service.ContactsService()
def authenticate(self, username=None, password=None):
user = None
try:
self.google_service.email = username
self.google_service.password = password
self.google_service.source = 'CampanhaEleicoesGerenciamento'
self.google_service.ProgrammaticLogin()
login_valid = True
pwd_valid = True
except gdata.service.BadAuthentication:
print "A autenticacao falhou"
login_valid = True
pwd_valid = True
return None
if login_valid and pwd_valid:
try:
user = User.objects.get(email=username)
except User.DoesNotExist:
return None
return user
return None
#settings.py
# Customize authentication backend
AUTHENTICATION_BACKENDS = (
'campanha_gerenciamento.custom.models.GoogleAuthenticator',
)
|
More like this
- Template tag - list punctuation for a list of items by shapiromatron 11 months, 2 weeks ago
- JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 11 months, 3 weeks ago
- Serializer factory with Django Rest Framework by julio 1 year, 6 months ago
- Image compression before saving the new model / work with JPG, PNG by Schleidens 1 year, 7 months ago
- Help text hyperlinks by sa2812 1 year, 7 months ago
Comments
Nice but really poor user confidence-experience. With this you'd be able to capture a user's username & password all in clear text and thus you can access his email, saved searches, google checkout, etc.
I would not go near a service that uses this snippet. That's what OAuth was built to solve.
#
Please login first before commenting.