How to get windows user id in web2py for an intranet application?
I'm using web2py for an intranet site and need to get current login windows user id in my c开发者_如何学Controller. Whether any function is available?
You need to install an NTLM authentication module on your web server such as mod_sspi or mod_ntlm then check the REMOTE_USER environment variable of the request. Here is something similar in Django: http://brandonkonkle.com/blog/2008/sep/13/django-apache-and-mod_auth_sspi/
If you mean you need code at the server to know the windows id of the current browser user, web2py isn't going to be able to tell you that. Windows authentication has nothing to do with web protocols.
I don't know if that works but try psutil module, which is supposed to work on both Windows and Unix.
import os, psutil
ownPid = os.getpid() #This one works in Windows, but os.getuid() does not...
ownUid = [p.uid for p in psutil.process_iter()
if p.pid == ownPid][0]
精彩评论