Skip to content

Instantly share code, notes, and snippets.

@solanoize
Created July 1, 2017 17:15
Show Gist options
  • Select an option

  • Save solanoize/814e470bcae196bc27977d76ba7cb523 to your computer and use it in GitHub Desktop.

Select an option

Save solanoize/814e470bcae196bc27977d76ba7cb523 to your computer and use it in GitHub Desktop.
from django.contrib.auth.models import User
class EmailAuthBackend(object):
"""
Authenticate menggunakan e-mail.
"""
def authenticate(self, username=None, password=None):
try:
user = User.objects.get(email=username)
if user.check_password(password):
return user
return None
except User.DoesNotExist:
return None
def get_user(self, user_id):
try:
return User.objects.get(pk=user_id)
except User.DoesNotExist:
return None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment