Attachment 'SingleSignOnSMF.py'

Download

   1 def SingleSignOnSMF(request, **kw):
   2 	""" If the user is authenticated to SMF (1.1.1)
   3 	    then automatically create/use the same named user in Moin
   4 	"""
   5 
   6 	import PHPUnserialize;
   7 	import Cookie;
   8 
   9 	user_obj = kw.get('user_obj')
  10         try:
  11 		cookie = Cookie.SimpleCookie(request.saved_cookie)
  12         except Cookie.CookieError:
  13 		# ignore invalid cookies
  14 		cookie = None
  15         if cookie and cookie.has_key(request.cfg.sso_smf_cookiename):
  16 		import urllib
  17 		cookievalue = cookie[request.cfg.sso_smf_cookiename].value
  18 		cookievalue = urllib.unquote(cookievalue) # cookie value is urlencoded, decode it
  19 		us = PHPUnserialize.PHPUnserialize()
  20 		values = us.unserialize(cookievalue)
  21 		#request.log("Got id %s from smf" % values[0])
  22 		
  23 		import MySQLdb
  24 		connection = MySQLdb.connect(host=request.cfg.sso_smf_host,
  25 			user=request.cfg.sso_smf_user,
  26 			passwd=request.cfg.sso_smf_passwd,
  27 			db=request.cfg.sso_smf_db)
  28 		cursor = connection.cursor()
  29 		cursor.execute("SELECT memberName, realName, emailAddress " +
  30 			       "FROM smf_members WHERE ID_MEMBER = " + values[0])
  31 		data = cursor.fetchall()
  32 		#request.log("data: %s|%s|%s" % (data[0][0], data[0][1], data[0][2]))
  33 		from MoinMoin.user import User
  34 		user = User(request, name=data[0][1], auth_username=data[0][0])
  35 		changed = False
  36 		if data[0][1] != user.aliasname:
  37 			user.aliasname = data[0][1]
  38 			changed = True
  39 		if data[0][2] != user.email:
  40 			user.email = data[0][2]
  41 			changed = True
  42 
  43 		if user:
  44 			user.create_or_update(changed)
  45 		if user and user.valid:
  46 			return user, True # True to get other methods called, too
  47 	return user_obj, True # continue with next method in auth list

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2007-01-01 04:35:17, 4.7 KB) [[attachment:PHPUnserialize.py]]
  • [get | view] (2007-01-01 04:36:27, 1.6 KB) [[attachment:SingleSignOnSMF.py]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.