Précédent   Forum du club des développeurs et IT Pro > Autres langages > Python & Zope > Réseau/Web
Réseau/Web Forum d'entraide sur Python et le réseau/Web
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse
 
Outils de la discussion
Publicité
'
Vieux 22/07/2012, 00h47   #1
otobenzina
 
Othmane BENZINA
Inscription : mai 2012
Messages : 15
Détails du profil
Informations personnelles :
Nom : Othmane BENZINA
Localisation : Maroc

Informations forums :
Inscription : mai 2012
Messages : 15
Points : -4
Points : -4
Par défaut Création de session et de cookie

bonsoir,

j'ai développé une classe Session pour la gestion des session de mon application web cette classe enregistre le login et le mot de passe dans un tableau (Sqlite3) et génère un nombre aléatoire, ce nombre il caractérise le cookie mais la page sa marche pas avec la commande le tout passe bien mais quand je fait l'appel par un navigateur

le code de la page:
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#!/usr/bin/python
# -*- coding: utf-8 -*-
 
import cgi
import Cookie
from Session import *
form = cgi.FieldStorage()
 
login = form.getvalue("login")
password = form.getvalue("password")
 
C = Cookie.SimpleCookie()
a=Sessions()
 
b=a.set(login,password)
C["session"] =b
print "Content-Type: text/html\n"
print C

le code de la classe Session:
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/python
# -*- coding: utf-8 -*-
 
import random
import datetime
import sqlite3
class Sessions():
	def __init__(self):
		connection=sqlite3.connect('Sessions.db',detect_types=sqlite3.PARSE_DECLTYPES)
		cursor=connection.cursor()
		cursor.execute('SELECT * FROM Sessions')
		cur=cursor.fetchall()
		a=datetime.datetime.now()
		aa=a.strftime("%a, %d-%b-%Y %H:%M:%S GMT")
		for l in cur:
			if l[3]<aa:
				cursor.execute('DELETE FROM Sessions WHERE alea=?',(l[0],))
				connection.commit()
		cursor.close()
		connection.close()
	def lire(self):
		connection=sqlite3.connect('Sessions.db',detect_types=sqlite3.PARSE_DECLTYPES)
		cursor=connection.cursor()
		cursor.execute('SELECT * FROM Sessions')
		cur=cursor.fetchall()
		a=datetime.datetime.now()
		aa=a.strftime("%a, %d-%b-%Y %H:%M:%S GMT")
		for l in cur:
			if l[3]<aa:
				cursor.execute('DELETE FROM Sessions WHERE alea=?',(l[0],))
				connection.commit()
		cursor.execute('SELECT * FROM Sessions')
		a=cursor.fetchall()
		cursor.close()
		connection.close()
		return a
	def alea(self):
		t=self.lire()
		a=int(random.random()*1000000000000)
		i=0
		while i<len(t):
			if t[i][0]!=a:
				i+=1
			else:
				i=0
				a=int(random.random()*1000000000000)
		return a
	def Enregistre(self,alea,login,password):
		connection=sqlite3.connect('Sessions.db',detect_types =sqlite3.PARSE_DECLTYPES)
		cursor=connection.cursor()
		a=datetime.datetime.now() + datetime.timedelta(minutes=10)
		date=a.strftime("%a, %d-%b-%Y %H:%M:%S GMT")
		cursor.execute('INSERT INTO Sessions VALUES (?,?,?,?)',(alea,login,password,date))
		connection.commit()
		cursor.close()
		connection.close()
	def set(self,login,password):
		a=self.alea()
		self.Enregistre(a,login,password)
		return a
	def get(self,alea):
		t=self.lire()
		for l in t:
			if l[0]==alea:
				login=l[1]
				password=l[2]
				connection=sqlite3.connect('Sessions.db',detect_types=sqlite3.PARSE_DECLTYPES)
				cursor=connection.cursor()
				cursor.execute('DELETE FROM Sessions WHERE alea=?',(alea,))
				connection.commit()
				cursor.close()
				connection.close()
				a=self.set(login,password)
				return [a,login,password]
		return 0
	def close(self,alea):
		connection=sqlite3.connect('Sessions.db',detect_types=sqlite3.PARSE_DECLTYPES)
		cursor=connection.cursor()
		cursor.execute('DELETE FROM Sessions WHERE alea=?',(alea,))
		connection.commit()
		cursor.close()
		connection.close()
merci
otobenzina est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse
Outils de la discussion

Navigation rapide


Fuseau horaire GMT +2. Il est actuellement 16h33.


 
 
 
 
Partenaires

Hébergement Web