[cpif] r175 - in trunk: . backend frontend-web
svn at argo.es
svn at argo.es
Thu Jun 21 00:17:21 CEST 2007
Author: jcea
Date: Thu Jun 21 00:17:20 2007
New Revision: 175
Log:
Completamos OpenID!!!.
?Verdad que mola un huevo?
Modified:
trunk/TODO
trunk/backend/database.py
trunk/backend/upgrade.py
trunk/frontend-web/globales.py
trunk/frontend-web/url_LOGIN.py
trunk/frontend-web/url_LOGIN_OpenID.py
Modified: trunk/TODO
==============================================================================
--- trunk/TODO (original)
+++ trunk/TODO Thu Jun 21 00:17:20 2007
@@ -113,8 +113,12 @@
- 20070620: FRONTAL WEB: El almacenamiento de sesiones OpenID
debe ser persistente, para evitar ataques "replay".
-- 20070520: FRONTAL WEB: Si no aceptamos accesos anonimos, no
+- 20070620: FRONTAL WEB: Si no aceptamos accesos anonimos, no
nos funcionara la autenticacion OpenID, ya que siempre
nos mostrara la pagina de LOGIN, incluso cuando este llegando
la autentificacion.
+
+- 20070620: FRONTAL WEB: Usando pruebas OpenID es muy facil
+ saber si un nick esta registrado, y que proveedor OpenID
+ utiliza.
Modified: trunk/backend/database.py
==============================================================================
--- trunk/backend/database.py (original)
+++ trunk/backend/database.py Thu Jun 21 00:17:20 2007
@@ -1,7 +1,7 @@
# $Id$
-VERSION_DB="2007062002"
+VERSION_DB="2007062003"
from globales import thread_len
@@ -64,12 +64,12 @@
# Si pasamos nick/clave, de ahi comprobamos tambien su identidad
# Si SOLO pasamos un nick, solo comprobamos si el usuario existe,
# pero no verificamos identidad.
-def usuario_verifica(conn,nick=None,clave=None,cookie=None) :
+def usuario_verifica(conn,nick=None,clave=None,cookie=None,force_login=False) :
root=conn.get_root()
- if clave :
+ if clave or force_login :
usuario=root["usuarios"]["usuarios"].get(normaliza_nick(nick),None)
- if usuario and (clave==usuario["clave"]) :
+ if usuario and ((clave==usuario["clave"]) or force_login) :
import random,sys
cookie=str(random.randint(0,sys.maxint))+str(random.randint(0,sys.maxint))
usuario["cookie"]=cookie
Modified: trunk/backend/upgrade.py
==============================================================================
--- trunk/backend/upgrade.py (original)
+++ trunk/backend/upgrade.py Thu Jun 21 00:17:20 2007
@@ -93,5 +93,10 @@
root["usuarios"]["usuarios"]["alvaro"]["OpenID"].add("http://alvaro.lopez.myopenid.com/")
conn.commit()
-
+ if root["version del foro"]=="2007062002" :
+ print "Actualizando la base de datos: 2007062002 -> 2007062003"
+ root["version del foro"]="2007062003"
+ if "alvaro" in root["usuarios"]["usuarios"] :
+ root["usuarios"]["usuarios"]["alvaro"]["OpenID"].add("http://perseverantia.com/")
+ conn.commit()
Modified: trunk/frontend-web/globales.py
==============================================================================
--- trunk/frontend-web/globales.py (original)
+++ trunk/frontend-web/globales.py Thu Jun 21 00:17:20 2007
@@ -22,5 +22,5 @@
http_max_clients=16
# OpenID Support
-openid_support=False
+openid_support=True
Modified: trunk/frontend-web/url_LOGIN.py
==============================================================================
--- trunk/frontend-web/url_LOGIN.py (original)
+++ trunk/frontend-web/url_LOGIN.py Thu Jun 21 00:17:20 2007
@@ -40,7 +40,7 @@
from openid.consumer import consumer
from url_LOGIN_OpenID import sessions,create_new_state
servidor="http://"+handler.headers["host"]+"/"
- rnd,sesion=create_new_state(usuario_form)
+ rnd,sesion=create_new_state(usuario_form,"/"+"/".join(path))
oidconsumer=consumer.Consumer(sesion,sessions)
try :
request = oidconsumer.begin(OpenID_form)
Modified: trunk/frontend-web/url_LOGIN_OpenID.py
==============================================================================
--- trunk/frontend-web/url_LOGIN_OpenID.py (original)
+++ trunk/frontend-web/url_LOGIN_OpenID.py Thu Jun 21 00:17:20 2007
@@ -11,7 +11,7 @@
import threading
mutex=threading.Lock()
-def create_new_state(usuario) :
+def create_new_state(usuario,path) :
import sys,random,time
global state,expire_state,mutex
ts=time.time()
@@ -23,7 +23,7 @@
while rnd in state :
rnd=random.randint(0,sys.maxint)
expiracion=ts+15*60
- st={"expiracion":expiracion,"usuario":usuario}
+ st={"expiracion":expiracion,"usuario":usuario,"path":path}
state[rnd]=st
expire_state.append((expiracion,rnd))
while expire_state[0][0]<ts :
@@ -58,6 +58,8 @@
return None
st=pop_state(st)
+ if not st :
+ return (200,{"Content-Type":"text/plain; charset=utf-8"},"Peticion invalida")
q=handler.path.find("?")
if q<0 : return (200,{"Content-Type":"text/plain; charset=utf-8"},"Peticion invalida")
@@ -74,11 +76,19 @@
oidconsumer=consumer.Consumer(st,sessions)
info=oidconsumer.complete(q)
- print "XXX",st
if info.status==consumer.FAILURE and info.identity_url :
return (200,{"Content-Type":"text/plain; charset=utf-8"},"Verificacion fallida")
elif info.status==consumer.SUCCESS :
- return (200,{"Content-Type":"text/plain; charset=utf-8"},"CORRECTO!!!!")
+ @monitor
+ def login(conn,usuario) :
+ import database
+ return database.usuario_verifica(conn,nick=usuario,force_login=True)
+ resultado=login(st["usuario"])
+ assert resultado
+ nick,cookie=resultado
+ if cookie :
+ cookie="cpif_auth=%s; path=/;" %cookie
+ return (302,{"Set-Cookie":cookie,"Location":st["path"]},"")
elif info.status==consumer.CANCEL :
return (200,{"Content-Type":"text/plain; charset=utf-8"},"Verificacion Cancelada")
elif info.status==consumer.SETUP_NEEDED :
More information about the cpif
mailing list