Jatin Kumar
Jatin Kumar

Reputation: 2785

Command Line Authentication in Web2py

I have made a web interface for my project using web2py and configured login with pam. Now i have to make a CLI for the same. I could not find any way i can authenticate the user (we can assume that the user i want to authenticate is already logged in on the linux machine configured with pam and running web2py).

Upvotes: 2

Views: 821

Answers (2)

mswjackso
mswjackso

Reputation: 67

To add to what Massimo said, this one-line login has been implemented now. You can do so using the following code:

#User_id is whatever the id is for the user you are forcing them to log in to
auth.login_user(user_id)

I couldn't find any documentation on this in the book but you can take a look at the method yourself in the gluon.tools module in the source.

Upvotes: 0

Massimo
Massimo

Reputation: 1653

First you need to find out the name of the logged in user:

username = os.getlogin()

Then you force a login:

from gluon.storage import Storage
from uuid import uuid4
session.auth = Storage(user=user, last_visit=request.now,
                                   expiration=auth.settings.expiration,
                                   hmac_key = str(uuid4())

we are about to add a auth method to do this in one line.

Upvotes: 3

Related Questions