signin_lobby.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 
00003 import nstart
00004 import config
00005 import os, sys, string, time
00006 import socket
00007 
00008 from pyclearsilver.log import *
00009 
00010 from pyclearsilver.CSPage import Context
00011 import neo_cgi, neo_cs, neo_util
00012 from MBPage import MBPage
00013 from webui import config
00014 
00015 from auth import browserauth
00016 from auth import cookieauth
00017 from auth import db_auth
00018 from auth import pwauth
00019 
00020 from web_msgs.msg import WebEvent
00021 import rospy
00022 
00023 class SignInPage(MBPage):
00024     def setup(self, hdf):
00025         pass
00026     
00027     def display(self, hdf):
00028         username = hdf.getValue("Query.username", "")
00029         if not username: return
00030 
00031         # need to check ip address is coming from the lobby
00032         # lobby address is in config
00033         ip_address = socket.gethostbyname(config.gLobbyHost)
00034 
00035         if hdf.getValue("CGI.RemoteAddress", "") != ip_address:
00036             warn("request from lobby on %s does not match %s" % (hdf.getValue("CGI.RemoteAddress", ""), ip_address))
00037             return
00038         else:
00039             warn("ip address is authorized")
00040 
00041         # create the user record and transfer all info
00042         user = self.authdb.users.lookupCreate(username=username)
00043 
00044         for key in ("role", "pw_hash", "status", "dismissed_notices", "favorite_apps", "skype_id"):
00045             user[key] = hdf.getValue("Query." + key, "")
00046 
00047         user.save()
00048 
00049         # write the active user file
00050         self.username = username
00051         self.make_active_user(hdf)
00052 
00053         # publish a web event that we logged in
00054         pub = rospy.Publisher("/webui/events", WebEvent)
00055         rospy.init_node("webui_login", anonymous=True)
00056         msg = WebEvent()
00057         msg.source = "user"
00058         msg.type = "login (lobby)"
00059         msg.data = self.username
00060         pub.publish(msg)
00061 
00062 
00063 def run(context):
00064     page = SignInPage(context, pagename="signin_lobby", nologin=1)
00065     return page
00066 
00067 def main(context):
00068   page = run(context)
00069   page.start()
00070   
00071 
00072 if __name__ == "__main__":
00073     main(Context())
00074 


webui
Author(s): Scott Hassan/hassan@willowgarage.com
autogenerated on Wed Apr 23 2014 10:36:00