Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CREATE OR REPLACE FUNCTION web.mlogin(
- character varying[],
- character varying[])
- RETURNS character varying AS
- $BODY$
- DECLARE name_array ALIAS FOR $1;
- DECLARE value_array ALIAS FOR $2;
- DECLARE id varchar;
- DECLARE ik varchar;
- DECLARE tegevus varchar;
- DECLARE new_sess varchar;
- DECLARE tmp varchar;
- DECLARE tmp_arr varchar[];
- DECLARE a varchar;
- declare pealkiri varchar;
- declare vorm1 varchar;
- declare vorm2 varchar;
- declare uuskatse varchar;
- declare meeles varchar;
- declare startpage varchar;
- --EDGAR. menu declaration
- declare vahe text;
- declare menu text := coalesce(get_session_variable('MENU'));
- BEGIN
- --a:=log(digidoc.m_id_auth_check(get_key('M-SESS')));
- --vahe:=name_array;
- --a:=log(vahe);
- --vahe:=value_array;
- --a:=log(vahe);
- if get_session_variable('DAD')='jvolis' then
- --startpage:='/';
- startpage:='/jvolis/!web.index?login';
- else
- startpage:=replace(info('start_page'),'::DAD::',get_session_variable('DAD'));
- end if;
- if coalesce(get_session_variable('LOGINLEVEL')::int4, 10) >= 30 then
- return pwa.redirect(startpage);
- end if;
- a:=set_session_variable('MENU', 'N');
- tegevus:=COALESCE(arrayvalue(name_array, value_array, 'tegevus'), '');
- id:=to_null(arrayvalue(name_array, value_array, 'id'));
- meeles:=pwa.cookie_get('MEELES');
- --a:=log(meeles);
- if length(id)<=9 and id ~ '^0?5' then -- Tõenäoliselt tegemist on eesti mobiiliga
- id:='+372'||ngltrim(id, '0');
- elsif not coalesce(asutused.is_isikukood(id), false) and id ~ '^3725\\d{6,8}$' then -- Tõenäoliselt tegemist on eesti mobiiliga
- id:='+'||id;
- end if;
- pealkiri:='<p>Lisainfot mobiilse autentimise kohta leiab aadressilt <a class="menulink" href="http://mobiil.id.ee" target="_blank">mobiil.id.ee</a>.</p>';
- vorm1:='<form name="m_vorm" id="m_vorm" method="get" action=""><input type="hidden" name="tegevus" value="Alusta autentimist" />
- <p>Sisestage isikukood või mobiiltelefoni number kujul +3725xxxxx või 5xxxxx:<br /><br /> <input type="text" name="id"';
- vorm2:=' /><br /><br />
- <input type="checkbox" name="meeles" '||CASE WHEN meeles is not null then 'checked' else '' end||' /> Pea andmed meeles (ühiskasutatava arvuti puhul pole soovitav!)
- <br /><br /><br />
- <input type="submit" name="submit" value="Alusta autentimist" /></p></form>';
- uuskatse:='<p>Uue autentimiskatse tegemiseks vajutage lingile: <a class="menulink" href="/gvolis/avalik/m_login/">M-ID</a></p>';
- if tegevus='Alusta autentimist' and not (coalesce(asutused.is_isikukood(id), false) or coalesce(id, '') in ('90101010092', '90101010072') or coalesce(id, '') ~ '^\\+\\d{6,}$') then
- a:=web.algus(gettext('WEB','Mobiil-ID autentimine'));
- a:=htp.p(volis.panel_start('panel_mlogin','Mobiil-ID autentimine','maximized-fixed',null));
- a:=htp.p(pealkiri);
- a:=htp.p('<p class="alert">Vale isikukood või mobiiltelefoni number</p>');
- a:=htp.p(vorm1||' value="'||escape_html(coalesce(id,meeles,''))||'"'||vorm2);
- a:=set_key('M-KOOD_MOBIIL', '');
- a:=set_key('M-SESS', '');
- a:=set_key('M-KOOD', '');
- a:=set_key('M-ISIKUKOOD', '');
- a:=set_key('M-EESNIMI', '');
- a:=set_key('M-PERENIMI', '');
- a:=set_key('M-STATUS', '');
- elsif tegevus='Alusta autentimist' then
- if get_key('M-KOOD_MOBIIL') = id then
- -- Kasutaja tegi refreshi => Staatuse kontroll
- if not get_key('M-STATUS')='011' then
- a:=set_key('M-STATUS', digidoc.m_id_auth_check(get_key('M-SESS')));
- end if;
- else
- tmp_arr:=digidoc.m_id_auth(id);
- if COALESCE(array_upper(tmp_arr, 1), 0) >= 7 and tmp_arr[1]='OK' then
- a:=set_key('M-KOOD_MOBIIL', id);
- a:=set_key('M-SESS', tmp_arr[3]);
- a:=set_key('M-KOOD', tmp_arr[4]);
- a:=set_key('M-ISIKUKOOD', tmp_arr[5]);
- a:=set_key('M-EESNIMI', tmp_arr[6]);
- a:=set_key('M-PERENIMI', tmp_arr[7]);
- a:=set_key('M-STATUS', '010'); --OUTSTANDING_TRANSACTION
- else
- a:=set_key('M-STATUS', tmp_arr[2]);
- end if;
- end if;
- ik:=get_key('M-ISIKUKOOD');
- if get_key('M-STATUS') in ('010') then --OUTSTANDING_TRANSACTION
- a:=web.algus(gettext('WEB','Mobiil-ID autentimine'));
- --EDGAR. Kui ei tahete menyyd, siis ei joonista
- if menu<>'N' then
- a:=htp.p(volis.panel_start('panel_mlogin','Mobiil-ID autentimine','maximized-fixed',null));
- end if;
- --a:=htp.p(volis.panel_start('panel_mlogin','Mobiil-ID autentimine','maximized-fixed',null));
- a:=htp.p(pealkiri);
- if id ~ '^\\+' then
- a:=htp.p('<br /><p>Mobiiltelefoni number: '||escape_html(id)||'</p><br />');
- else
- a:=htp.p('<br /><p>Isikukood: '||escape_html(id)||'</p><br />');
- end if;
- a:=htp.p('<div id="sonum"><p>Palun oodake! Mõne aja pärast algab Teie mobiiltelefonis autentimisprotseduur.'||COALESCE(' Kontrollkood on: <b>'||to_null(get_key('M-KOOD'))||'</b>', '')||'</p>');
- a:=htp.p('<p>Kui olete sisestanud PIN1 koodi mobiiltelefoni, kuid keskkonda sisenemist pole toimunud ca 5 sekundi jooksul, siis värskendage palun <a class="menulink" href="#" onclick="window.location.reload(true)">seda lehekülge</a>.</p>');
- a:=htp.p('<p>Kui autentimisprotseduur ei alga pikema aja jooksul, siis kontrollige palun, kas Teie mobiiltelefon on levis ning korrake autentimist, vajutades lingile: <a class="menulink" href="/gvolis/avalik/m_login/">M-ID</a>.</p></div>');
- -- a:=htp.p('<script type="text/javascript">setTimeout("window.location.reload(true)", 5000);</script>');
- a:=htp.p(web.mlogin_script('tegevus=Alusta%20autentimist&id=')||coalesce(id::text,''));
- elsif get_key('M-STATUS')='011' then --USER_AUTHENTICATED
- -- Update session
- new_sess:=pwa.create_session(get_session_variable('SESSION_ID'),'login','40','M-ID',ik,get_key('M-EESNIMI'),get_key('M-PERENIMI'),null,null,null);
- if new_sess='NOTOK' then
- a:=set_session_variable('CODE',null);
- a:=set_key('M-KOOD_MOBIIL', '');
- a:=set_key('M-SESS', '');
- a:=set_key('M-KOOD', '');
- a:=set_key('M-ISIKUKOOD', '');
- a:=set_key('M-EESNIMI', '');
- a:=set_key('M-PERENIMI', '');
- a:=set_key('M-STATUS', '');
- a:=web.algus(gettext('WEB','Mobiil-ID autentimine'));
- a:=htp.p(volis.panel_start('panel_mlogin','Mobiil-ID autentimine','maximized-fixed',null));
- a:=htp.p(pealkiri);
- a:=htp.p('<p class="alert">Ligipääs antud keskkonnale on keelatud</p>');
- return web.lopp();
- else
- a:=set_session_variable('SESSION_ID', new_sess);
- --a:=pwa.putstringhdr('Set-Cookie: '||get_session_variable('SESSIONKEY')||'='||new_sess||'; PATH=/'||pwa.cookie_domain()||';secure'||'\n');
- a:=pwa.putstringhdr('Set-Cookie: '||get_session_variable('SESSIONKEY')||'='||new_sess||'; PATH=/'||pwa.cookie_domain()||''||'\n');
- if not asutused.is_isikukood(get_key('M-KOOD_MOBIIL')) then
- a:=set_key('MOBIIL',get_key('M-KOOD_MOBIIL'));
- end if;
- end if;
- tmp:=to_null(pwa.cookie_get('LOCATION'));
- if tmp is null then
- return htp.redirect(startpage);
- else
- a:=pwa.cookie_remove('LOCATION',null,null);
- return htp.redirect(unescape_uri(tmp));
- end if;
- elsif get_key('M-STATUS') in ('004', '012', '013', '014', '015', '016', '017', '018', '301', '303') then -- Kasutajapoolsed vead
- a:=web.algus(gettext('WEB','Mobiil-ID autentimine'));
- a:=htp.p(volis.panel_start('panel_mlogin','Mobiil-ID autentimine','maximized-fixed',null));
- a:=htp.p(pealkiri);
- if id ~ '^\\+' then
- a:=htp.p('<br /><p>Mobiiltelefoni number: '||escape_html(id)||'</p><br />');
- else
- a:=htp.p('<br /><p>Isikukood: '||escape_html(id)||'</p><br />');
- end if;
- a:=htp.p('<p class="alert">Autentimisprotseduur ebaõnnestus (veakood: '||get_key('M-STATUS')||') - '||lov_code2value('WEB.M-STATUS',get_key('M-STATUS'))||'</p>');
- a:=htp.p(uuskatse);
- else -- Süsteemsed vead
- a:=web.algus(gettext('WEB','Mobiil-ID autentimine'));
- a:=htp.p(volis.panel_start('panel_mlogin','Mobiil-ID autentimine','maximized-fixed',null));
- a:=htp.p(pealkiri);
- if id ~ '^\\+' then
- a:=htp.p('<br /><p>Mobiiltelefoni number: '||escape_html(id)||'</p><br />');
- else
- a:=htp.p('<br /><p>Isikukood: '||escape_html(id)||'</p><br />');
- end if;
- a:=htp.p('<p class="alert">Autentimisprotseduur ebaõnnestus (veakood: '||get_key('M-STATUS')||') - '||lov_code2value('WEB.M-STATUS',get_key('M-STATUS'))||'</p>');
- a:=htp.p(uuskatse);
- raise warning 'web.mlogin: tehniline viga! kood=%; kirjeldus=%', get_key('M-STATUS'),lov_code2value('WEB.M-STATUS',get_key('M-STATUS'));
- end if;
- else
- a:=web.algus(gettext('WEB','Mobiil-ID autentimine'));
- --EDGAR. Kui ei tahete menyyd, siis ei joonista
- if menu<>'N' then
- a:=htp.p(volis.panel_start('panel_mlogin','Mobiil-ID autentimine','maximized-fixed',null));
- end if;
- a:=htp.p(pealkiri);
- a:=htp.p(vorm1||coalesce(' value="'||meeles||'"','')||vorm2);
- --a:=htp.p(web.mlogin_script('X'));
- a:=set_key('M-KOOD_MOBIIL', '');
- a:=set_key('M-SESS', '');
- a:=set_key('M-KOOD', '');
- a:=set_key('M-ISIKUKOOD', '');
- a:=set_key('M-EESNIMI', '');
- a:=set_key('M-PERENIMI', '');
- a:=set_key('M-STATUS', '');
- end if;
- if id is not null and arrayvalue(name_array, value_array, 'meeles') is not null then
- a:=pwa.cookie_set('MEELES',id::varchar,null,(current_timestamp + interval '30 days')::timestamp,'/'||pwa.cookie_domain());
- elsif tegevus='Alusta autentimist' and arrayvalue(name_array, value_array, 'meeles') is null then
- a:=pwa.cookie_remove('MEELES',null,null);
- end if;
- a:=htp.p(volis.panel_end('panel_mlogin','maximized-fixed'));
- return web.lopp();
- END;
- $BODY$
- LANGUAGE plpgsql VOLATILE SECURITY DEFINER
- COST 100;
- ALTER FUNCTION web.mlogin(character varying[], character varying[])
- OWNER TO sysadm;
- COMMENT ON FUNCTION web.mlogin(character varying[], character varying[]) IS 'Mobiilse autentimise kasutajaliides (pooleli).';
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement