On Fri, Jul 15, 2011 at 11:55 AM, Rotem Tamir <[email protected]> wrote:

> Hi everyone,
>
> I want to manually log a user based on some criteria.
>
> For example, user signs up, I want to create the User object in the DB
> and then use repoze.who somehow to make this user logged in without
> requiring redirecting to '/login'
>
> In TG1.1 I knew how to do so using this technique:
>
> http://turbogears.org/1.1/docs/Identity/Recipes.html#log-in-a-user-object-manually
>
> how might i do so using tg2.1?
>
> thanks in advance!
>
> Rotem Tamir
>
> --
> You received this message because you are subscribed to the Google Groups
> "TurboGears" 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/turbogears?hl=en.
>
>
I forget where I originally found the example but here is what I use in my
tg2.1 app:

def set_request_user(user):
     from myapp.model import User
     if isinstance(user, User):
         user_name = user.user_name
     else:
         user_name = user
     identity = {'repoze.who.userid': user_name.lower()}
     headers =
request.environ['repoze.who.plugins']['cookie'].remember(request.environ,
identity)
     if headers:
         for k, v in headers:
             response.headers.add(k, v)

hope this helps

Vince









-- 
Vince Spicer
Morcova - The easy way to Social <http://www.morcova.com>

-- 
You received this message because you are subscribed to the Google Groups 
"TurboGears" 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/turbogears?hl=en.

Reply via email to