Skip to content

Instantly share code, notes, and snippets.

@mpessolano
Last active March 3, 2021 21:42
Show Gist options
  • Select an option

  • Save mpessolano/853af6c01392ee829c694b0b4a6405b9 to your computer and use it in GitHub Desktop.

Select an option

Save mpessolano/853af6c01392ee829c694b0b4a6405b9 to your computer and use it in GitHub Desktop.
Login en Joomla desde formulario externo (Login in Joomla from external form)
<?php
// https://dominio.joomla.com/external-login.html
// /datadrive/www/html/joomla/components/com_jumi/files/external-login.php
// error_reporting(E_ALL ^ E_STRICT);
// ini_set('display_errors', 1);
$app = JFactory::getApplication('site');
$session = JFactory::getSession();
$credentials = array();
$credentials['username'] = $app->input->post->get('username', '', 'string');
$credentials['password'] = $app->input->post->get('password', '', 'string');
if (true === $app->login($credentials))
{
$user = JFactory::getUser();
// $redirecturl = 'mis-cursos.html';
$redirecturl = 'index.php';
$app->redirect($redirecturl);
}
else
{
?>
<div class="alert alert-danger">
<strong>Acceso Denegado</strong>
</div>
<?php
}
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>External login · Joomla</title>
<link href="https://getbootstrap.com/docs/5.0/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BmbxuPwQa2lc/FVzBcNJ7UAyJxM6wuqIj61tLrc4wSX0szH/Ev+nYRRuWlolflfl" crossorigin="anonymous">
<link href="https://getbootstrap.com/docs/5.0/examples/sign-in/signin.css" rel="stylesheet">
</head>
<body class="text-center">
<main class="form-signin">
<form action="https://dominio.joomla.com/external-login.html" method="post">
<img class="mb-4" src="https://cdn.joomla.org/images/Joomla_logo.png" alt="Joomla CMS" width="40" height="40">
<label for="username" class="visually-hidden">Username</label>
<input type="text" id="username" name="username" class="form-control" placeholder="Username" required>
<label for="password" class="visually-hidden">Password</label>
<input type="password" id="password" name="password" class="form-control" placeholder="Password" required>
<button class="w-100 btn btn-lg btn-primary" type="submit">Log in</button>
</form>
</main>
</body>
</html>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>External login · Joomla</title>
<link href="https://getbootstrap.com/docs/5.0/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BmbxuPwQa2lc/FVzBcNJ7UAyJxM6wuqIj61tLrc4wSX0szH/Ev+nYRRuWlolflfl" crossorigin="anonymous">
<link href="https://getbootstrap.com/docs/5.0/examples/sign-in/signin.css" rel="stylesheet">
</head>
<body class="text-center">
<main class="form-signin">
<form action="https://dominio.joomla.com/external-login.html" method="post">
<img class="mb-4" src="https://cdn.joomla.org/images/Joomla_logo.png" alt="Joomla CMS" width="40" height="40">
<input type="hidden" id="username" name="username" value="test_login">
<input type="hidden" id="password" name="password" value="Password#2021">
<button class="w-100 btn btn-lg btn-primary" type="submit">Log in</button>
</form>
</main>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment