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
| create or replace package SessionPK as
session_duration constant number := 120; -- minutes(2h)
function is_logged return number;
function check_login (p_login in client.Login%type, p_password in client.Pass%type) return number;
procedure get_user(p_lastname out personne.nom%type, p_firstname out personne.prenom%type);
procedure logout;
end SessionPK;
/
create or replace
package body SessionPK as
function get_session_id return varchar2 is
session_cookie owa_cookie.cookie;
session_id varchar2 (32);
last date;
begin
session_cookie := owa_cookie.get ('sessionid');
if session_cookie.num_vals = 0 then
return null;
end if;
session_id := session_cookie.vals (session_cookie.vals.first);
begin
select sessions.last into last from sessions where sessions.id_session = session_id;
exception
when no_data_found then
owa_cookie.remove ('sessionid', session_id);
return null;
end;
if sysdate > last + SessionPK.session_duration / 1440 then
owa_cookie.remove ('session_id', session_id);
delete from sessions where id_session = session_id;
commit;
return null;
end if;
update sessions set last = sysdate where id_session = session_id;
return session_id;
/*exception
when others then
centrale.ajoutLog('SessionPK.get_session_id',SQLCODE,SQLERRM);*/
end get_session_id;
function check_login (p_login in client.Login%type, p_password in client.Pass%type) return number is
v_session_id varchar2 (32);
v_client_id client.id_client%type;
begin
v_session_id := get_session_id;
if v_session_id is not null then
centrale.ajoutLog('sessionPK.check_login',SQLCODE,SQLERRM,'Client deja connecté');
return 0;
end if;
begin
select id_client into v_client_id from client where login like p_login and pass like p_password;
exception when no_data_found then
return 0;
end;
select sys_guid () into v_session_id from dual;
owa_cookie.send ('sessionid', v_session_id, sysdate + 30 / 1440);
insert into sessions values (v_session_id, v_client_id, sysdate);
commit;
return 1;
end check_login;
...
end SessionPK; |
Partager