I am trying to set up my own backend, which requests another database for which I created a model in the system. It uses its own rules (email instead of username and another salty / hashed password), so I cannot use built-in authentication. I configured my own backend for authentication:
class BlahBlahBackend:
def check_password():
return true
def authenticate(self, email=None, password=None):
import myapp.models.loginmodel
try:
person = myapp.models.loginmodel.People.objects.get(email=email)
if check_password(password, person.password):
try:
user = User.objects.get(email=email)
except User.DoesNotExist:
username=person.first_name + person.last_name
name_count = User.objects.filter(username__startswith = username).count()
if name_count:
username = '%s%s'%(username, name_count + 1)
user = User.objects.create_user(username,email)
else:
user = User.objects.create_user(username,email)
except People.DoesNotExist:
return None
def get_user(self, user_id):
try:
return User.objects.get(pk=user_id)
except User.DoesNotExist:
return None
I added BlahBlahBackend as an authentication server:
AUTHENTICATION_BACKENDS = ('django.contrib.auth.backends.ModelBackend', 'Socialauth.auth_backends.OpenIdBackend', 'Socialauth.auth_backends.TwitterBackend', 'Socialauth.auth_backends.FacebookBackend', 'Socialauth.auth_backends.BlahBlahBackend', )
, auth, socialauth.
, :
def blahblah_login_complete(request):
email = request.POST.get('email')
password = request.POST.get('password')
user = authenticate(email,password)
# if user is authenticated then login user
if user:
login(request, user)
else:
return HttpResponseRedirect(reverse('socialauth_login_page'))
, , , , , .
,
Session.objects.all().delete()
-.
:
- , AUTHENTICATION_BACKENDS
- /, ? , .
- . , - , , openid Twitter?
Update:
! , . , , django doc : " , , ", , . , , . , urls.py, , .