Re: auto authenticate

2010-03-25 Thread Peter Bengtsson
If what you want to achieve is to log in a user programmatically you
don't do that by authenticating by username and password.
Example:


def login_by_id(request):

   user = FacebookUser.objects.get(...).user

   from django.contrib.auth import load_backend, login
   for backend in settings.AUTHENTICATION_BACKENDS:
if user == load_backend(backend).get_user(user.pk):
user.backend = backend
   if hasattr(user, 'backend'):
 login(request, user)


On 25 Mar, 18:27, CrabbyPete  wrote:
> I am connecting facebook to an app I have running. In order not to
> change a load of code I created a dummy account when someone logs in
> through facebook. My only problem is I want to authenticate with this
> account when they log  Is there a way to login in a user using the
> encrypted password. I am using pyfacebook and FacebookUser is the
> following model
>
> class FacebookUser(models.Model):
>     user            = models.ForeignKey(User, unique = True)
>     fb_uid          = models.CharField( max_length=100, blank = True,
> unique = True)
>
>     def __unicode__(self):
>         if self.user.username == u'':
>             return str(self.pk)
>         return self.user.username
>
> the fb_uid is the Facebook id I get back. Here is my view when I get
> called from facebook
>
> fb = request.facebook
>  try:
>       fid = FacebookUser.objects.get(Q(fb_uid = fb.uid))
> except FacebookUser.DoesNotExist:
>        return ...
>
> name = fid.user
> pswd = fid.user.password
> user = auth.authenticate(username=name, password=pswd)
>  if user is not None and user.is_active:
>      auth.login(request, user)
>
> pswd is an encrypted password. Is there a way for me to authenticate
> with it?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: auto authenticate

2010-03-26 Thread CrabbyPete
Thanks Peter that is exactly what I was looking for.

On Mar 25, 5:12 pm, Peter Bengtsson  wrote:
> If what you want to achieve is to log in a user programmatically you
> don't do that by authenticating by username and password.
> Example:
>
> def login_by_id(request):
>
>            user = FacebookUser.objects.get(...).user
>
>            from django.contrib.auth import load_backend, login
>            for backend in settings.AUTHENTICATION_BACKENDS:
>                 if user == load_backend(backend).get_user(user.pk):
>                     user.backend = backend
>            if hasattr(user, 'backend'):
>                  login(request, user)
>
> On 25 Mar, 18:27, CrabbyPete  wrote:> I am connecting 
> facebook to an app I have running. In order not to
> > change a load of code I created a dummy account when someone logs in
> > through facebook. My only problem is I want to authenticate with this
> > account when they log  Is there a way to login in a user using the
> > encrypted password. I am using pyfacebook and FacebookUser is the
> > following model
>
> > class FacebookUser(models.Model):
> >     user            = models.ForeignKey(User, unique = True)
> >     fb_uid          = models.CharField( max_length=100, blank = True,
> > unique = True)
>
> >     def __unicode__(self):
> >         if self.user.username == u'':
> >             return str(self.pk)
> >         return self.user.username
>
> > the fb_uid is the Facebook id I get back. Here is my view when I get
> > called from facebook
>
> > fb = request.facebook
> >  try:
> >       fid = FacebookUser.objects.get(Q(fb_uid = fb.uid))
> > except FacebookUser.DoesNotExist:
> >        return ...
>
> > name = fid.user
> > pswd = fid.user.password
> > user = auth.authenticate(username=name, password=pswd)
> >  if user is not None and user.is_active:
> >      auth.login(request, user)
>
> > pswd is an encrypted password. Is there a way for me to authenticate
> > with it?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.