ENTE DI FORMAZIONE ACCREDITATO PRESSO REGIONE LOMBARDIA - N.937 SEZIONE B | Via Mosè Bianchi 96 | 20149 Milano | Tel. 02 87367858info@scuoladimusicacluster.it

AutoLoginToForum

{source}<?php

function addJoomlaUser($username, $name, $email, $password, $groups, $activate = false)
{
jimport('joomla.user.helper');

$groups = is_string($groups) ? explode(',', $groups) : (array) $groups;

$data = [
'name' => $name,
'username' => $username,
'password' => $password,
'password2' => $password,
'email' => JStringPunycode::emailToPunycode($email),
'groups' => $groups
];

if (!$activate) {
$hash = JApplicationHelper::getHash(JUserHelper::genRandomPassword());
$data['activation'] = $hash;
$data['block'] = 1;
}

// Load the users plugin group.
JPluginHelper::importPlugin('user');
$user = new JUser;

if (!$user->bind($data)) {
throw new Exception($user->getError());
}

if (!$user->save()) {
throw new Exception($user->getError());
}

return $user;
}

if (!isset($_GET['nome']) || !isset($_GET['email']) || !isset($_GET['codice_auth'])) {
die("non hai i permessi per visitare questa pagina");
}
if ($_GET['codice_auth'] !== "60a9d06d7198e2facc5ce32ecfe5c8065107b774ba8c8bbc3173da226e939d4a") {
die("non hai i permessi per visitare questa pagina");
}

$username = $_GET['email'];
$name = $_GET['nome'];
$password = bin2hex(random_bytes(10)); //random
$email = $_GET['email'];
$db = JFactory::getDbo();
$query = $db->getQuery(true)
->select('id')
->from('#__users')
->where('email=' . $db->quote($username));

$db->setQuery($query);
$result = $db->loadResult();

//Se l'utente non esiste lo creo
if (empty($result)) {
// Create Joomla User Account
$new_user = addJoomlaUser($username, $name, $email, $password, '2', true); //2 = registered
$query = $db->getQuery(true)
->select('id')
->from('#__users')
->where('email=' . $db->quote($username));

$db->setQuery($query);
$result = $db->loadResult();
}

//mi assicuro che sia abilitato (quindi non bloccato)
$user = JUser::getInstance($result); // Bring this in line with the rest of the system
$user->username = $username;
$user->password = JUserHelper::hashPassword($password);
$user->block = 0;
//salvo
if (!$user->save()) {
throw new Exception($user->getError());
}

// Instantiate the application.
$app = JFactory::getApplication('site');

// Hardcoded for now
$credentials['username'] = $username;
$credentials['password'] = $password; //random

$error = $app->login($credentials);

//redirect logged in user
switch ($_GET['redirect']) {
case 'pagamenti':
$app->redirect('pagamenti.html');
break;
default:
$app->redirect('index.php?option=com_kunena&view=category&layout=list&Itemid=520');
break;
}
?>
{/source}

Scuola di Musica Cluster
Partecipa all'Open Day!

Cluster Music S.r.l.
via Mosè Bianchi 96, 20149 Milano
Tel. 02 87367858
Partita Iva 08543130960

Ente di formazione accreditato presso Regione Lombardia - Servizi di Istruzione e Formazione Professionale Iscrizione n.937 del 10/05/2016 – Sezione B

Privacy Policy | Cookie Policy