Thanks for this link, I saw it Saturday.
But the problem is the same, I have to login to use template like that:
{% if user.is_authenticated %}
lol
{% else %}
not lol
{% endif %}
and my view.py is somethink like that:
username = request.POST['user']
password = request.POST['password']
user = authenticate(username=username, password=password)
if user is not None:
login(request, user)
Do I have to overload login method to use it like that ?
On Mon, Jan 18, 2010 at 9:32 AM, nostradamnit <[email protected]> wrote:
> Olivier,
>
> Look at this -
> http://stackoverflow.com/questions/1057149/django-users-and-authentication-from-external-source
>
> I imagine your problem comes from the fact that django.contrib.auth
> User is tied to the DB
>
> Sam
>
> On Jan 18, 12:09 am, Olivier Détour <[email protected]> wrote:
>> up
>>
>> 2010/1/16 Détour Olivier <[email protected]>:
>>
>>
>>
>> > Hi,
>> > I would create my own auth backend. I tried to understand and trace
>> > source code.
>> > I want to create an internal DB with SHA1 and username.
>> > But I cannot login, Django says me I do not set DB ENGINE. I would not
>> > use something like MySQL or any DB Engine.
>>
>> > Here is my source code:
>> > mybackend.py:
>>
>> > from django.contrib.auth.models import User
>> > from django.contrib.auth.backends import RemoteUserBackend
>>
>> > class MyUser (User):
>> > def save (self):
>> > """saving to DB disabled"""
>> > pass
>>
>> > objects = None # we cannot really use this w/o local DB
>> > username = "" # and all the other properties likewise.
>> > # They're defined as model.CharField or similar,
>> > # and we can't allow that
>>
>> > def get_group_permissions (self):
>> > """If you don't make your own permissions module,
>> > the default also will use the DB. Throw it away"""
>> > return [] # likewise with the other permission defs
>>
>> > def get_and_delete_messages (self):
>> > """Messages are stored in the DB. Darn!"""
>> > return []
>>
>> > class WWWBackend (RemoteUserBackend):
>> > # Create a User object if not already in the database?
>> > create_unknown_user = False
>>
>> > def get_user (self, user_id):
>> > user = somehow_create_an_instance_of(MyUser, user_id)
>> > return user
>>
>> > def authenticate (self, username=None, password=None):
>> > if username == "lol" and password == "lol":
>> > user = MyUser(username=username, password=password)
>> > return user
>> > return None
>>
>> > my view.py:
>>
>> > from django import forms
>> > from django.core.context_processors import csrf
>> > from django.template import RequestContext, loader
>> > from django.http import HttpResponse, HttpResponseRedirect
>> > from django.contrib.auth import authenticate, login
>>
>> > #! Form Upload Object
>> > class LoginForm (forms.Form):
>> > user = forms.CharField(widget = forms.TextInput)
>> > password = forms.CharField(widget = forms.PasswordInput)
>>
>> > def index(request):
>> > if request.method == 'POST':
>> > form = LoginForm(request.POST)
>> > if form.is_valid():
>> > # FIXME: Check if file is good.
>> > #handle_uploaded_torrent(request.FILES['file'])
>> > username = request.POST['user']
>> > password = request.POST['password']
>> > user = authenticate(username=username, password=password)
>> > if user is not None:
>> > login(request, user)
>>
>> > return HttpResponseRedirect('/')
>> > else:
>> > form = LoginForm()
>>
>> > t = loader.get_template('template/index.html')
>> > c = RequestContext(request, {
>> > 'login_form': form,
>> > })
>> > return HttpResponse(t.render(c))
>>
>> > Thanks for reponses,
>> > Regards,
>>
>> --
>> Olivier Détour
>> Sent from Reserved, ***
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>
>
>
--
Olivier Détour
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.