Buenas,
Adjunto ejemplo de como podriais facilmente usar sesiones para poder autenticar y dar acceso a vuestros modulos.
Escenario: App con menu y acceso a 2 modulos. Si no estas autenticado vas a la pantalla de login. Si no te autenticas, no entras. Facil
Cread dentro de HIX una carpeta, p.e. /sessions y poned todos los ejemplos tal cual estan nombrados
index.html
<?prg
if ! USessionReady()
URedirect( 'login.html' )
retu nil
endif
retu ''
?>
<!DOCTYPE html>
<html>
<body>
<h3>My App</h3><hr>
<h4>Menu</h4>
<ul>
<li><a href="module_a.html">Module A</a>
<li><a href="module_b.html">Module B</a>
</ul>
<br><br>
<a href='logout.prg'>Logout</a>
</body>
</html>login.html
<!DOCTYPE html>
<html>
<body>
<h2>HTML Forms</h2>
<form action="auth.prg" method="post">
<label for="user">User (demo)</label><br>
<input type="text" name="user" value="demo"><br>
<label for="psw">Password (1234)</label><br>
<input type="text" name="psw" value="1234"><br><br>
<input type="submit" value="Login">
</form>
<p>If you click the "Login" button, the form-data will be sent to a page called "auth.prg"</p>
</body>
</html>auth.prg
function Auth()
local cName := UPost( 'user' )
local cPsw := UPost( 'psw' )
local hData := {=>}
if cName == 'demo' .and. cPsw == '1234'
USessionStart()
hData[ 'user' ] := 'demo'
hData[ 'name' ] := 'Mr. Demo'
hData[ 'rol' ] := 'admin'
Usession( 'credentials', hData )
URedirect( 'index.html' )
else
URedirect( 'login.html' )
endif
return nillogout.prg
function Auth()
if USessionReady()
USessionEnd()
endif
URedirect( 'login.html' )
return nilmodule_a.html
<?prg
if ! USessionReady()
URedirect( 'login.html' )
retu nil
endif
retu ''
?>
<!DOCTYPE html>
<html>
<body>
<h3>Module A...</h3><hr>
Welcome <?prg return USession( 'credentials' )[ 'name' ] ?>
<br><br><a href='index.html'>Main menu</a>module_b.html
<?prg
if ! USessionReady()
URedirect( 'login.html' )
retu nil
endif
retu ''
?>
<!DOCTYPE html>
<html>
<body>
<h3>Module B...</h3><hr>
Welcome <?prg return USession( 'credentials' )[ 'name' ] ?>
<br><br><a href='index.html'>Main menu</a>Esta es la base para poder autenticar y trabajar con sesiones
Ya solo te te toca escribir en la url -> /sessions/index.html
C.
Salutacions, saludos, regards
"...programar es fácil, hacer programas es difÃcil..."
UT Page -> https://carles9000.github.io/
Forum UT -> https://discord.gg/bq8a9yGMWh
HIX -> https://github.com/carles9000/hix
"...programar es fácil, hacer programas es difÃcil..."
UT Page -> https://carles9000.github.io/
Forum UT -> https://discord.gg/bq8a9yGMWh
HIX -> https://github.com/carles9000/hix