15 ha cambiato i file con 174 aggiunte e 39 eliminazioni
@ -0,0 +1,22 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
namespace MwgAuth\Models; |
||||||
|
|
||||||
|
use MwgAuth\Core\Model; |
||||||
|
|
||||||
|
class Token extends Model |
||||||
|
{ |
||||||
|
public static function useCns(string $token): bool |
||||||
|
{ |
||||||
|
$token = self::selectOne('tokens', ['auth'], ['token' => $token]); |
||||||
|
if (null === $token) { |
||||||
|
return true; |
||||||
|
} |
||||||
|
$user_id = self::selectOne('sessions', ['user_id'], ['auth' => $token['auth']]); |
||||||
|
if (null === $user_id) { |
||||||
|
return true; |
||||||
|
} |
||||||
|
$useCns = self::selectOne('users', ['use_cns'], ['id' => $user_id['user_id']]); |
||||||
|
return $useCns['use_cns'] == 1; |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,33 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
namespace MwgAuth\Models; |
||||||
|
|
||||||
|
use MwgAuth\Core\Model; |
||||||
|
|
||||||
|
class UserTool extends User |
||||||
|
{ |
||||||
|
public static function add(string $username, string $password, string $remote, bool $useCns): bool |
||||||
|
{ |
||||||
|
return self::insert('users', [ |
||||||
|
'username' => $username, |
||||||
|
'password' => self::hashPassword($password), |
||||||
|
'remote' => $remote, |
||||||
|
'use_cns' => $useCns, |
||||||
|
]); |
||||||
|
} |
||||||
|
|
||||||
|
public static function list(): array |
||||||
|
{ |
||||||
|
return self::select('users', ['id', 'username', 'remote', 'use_cns'], []); |
||||||
|
} |
||||||
|
|
||||||
|
public static function token(string $username): ?string |
||||||
|
{ |
||||||
|
$rows = self::select('users', ['id'], ['username' => $username]); |
||||||
|
if (empty($rows)) { |
||||||
|
return null; |
||||||
|
} |
||||||
|
$user = new User($rows[0]['id'], $username); |
||||||
|
return $user->getToken('http://localhost/callback'); |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,2 @@ |
|||||||
|
ALTER TANLE `logins` ADD COLUMN `email` VARCHAR(255) NULL DEFAULT NULL AFTER `cognome`; |
||||||
|
ALTER TANLE `users` ADD COLUMN `use_cns` BOOLEAN NOT NULL DEFAULT TRUE AFTER `remote`; |
||||||
@ -0,0 +1,14 @@ |
|||||||
|
#!/usr/bin/env php |
||||||
|
<?php |
||||||
|
|
||||||
|
use MwgAuth\Core\Config; |
||||||
|
use MwgAuth\Models\UserTool; |
||||||
|
|
||||||
|
require_once(dirname(__DIR__) . '/App/bootstrap.php'); |
||||||
|
|
||||||
|
if ($argc < 2) { |
||||||
|
echo "Usage: $argv[0] <username>\n"; |
||||||
|
exit(1); |
||||||
|
} |
||||||
|
$token = UserTool::token($argv[1]); |
||||||
|
echo Config::getValue('site', 'url') . "?t=$token\n"; |
||||||
@ -0,0 +1,27 @@ |
|||||||
|
#!/usr/bin/env php |
||||||
|
<?php |
||||||
|
|
||||||
|
namespace Tools; |
||||||
|
|
||||||
|
use MwgAuth\Models\UserTool; |
||||||
|
|
||||||
|
require_once(dirname(__DIR__) . '/App/bootstrap.php'); |
||||||
|
|
||||||
|
$username = readline("Nome utente: "); |
||||||
|
$password = readline("Password: "); |
||||||
|
$remote = readline("Indirizzo remoto (default: *): "); |
||||||
|
if (empty($remote)) { |
||||||
|
$remote = '*'; |
||||||
|
} |
||||||
|
$cns = readline("Usa CNS? (Y/n): "); |
||||||
|
if (empty($cns)) { |
||||||
|
$cns = 'y'; |
||||||
|
} |
||||||
|
$cns = strtolower($cns) === 'y'; |
||||||
|
echo "Aggiungo utente...\n"; |
||||||
|
$result = UserTool::add($username, $password, $remote, $cns); |
||||||
|
if ($result) { |
||||||
|
echo "Utente aggiunto con successo.\n"; |
||||||
|
} else { |
||||||
|
echo "Errore durante l'aggiunta dell'utente.\n"; |
||||||
|
} |
||||||
@ -0,0 +1,11 @@ |
|||||||
|
#!/usr/bin/env php |
||||||
|
<?php |
||||||
|
|
||||||
|
use MwgAuth\Models\UserTool; |
||||||
|
|
||||||
|
require_once(dirname(__DIR__) . '/App/bootstrap.php'); |
||||||
|
|
||||||
|
$users = UserTool::list(); |
||||||
|
foreach ($users as $user) { |
||||||
|
echo "ID: {$user['id']}, Username: {$user['username']}, Remote: {$user['remote']}, Use CNS: {$user['use_cns']}\n"; |
||||||
|
} |
||||||
Caricamento…
Reference in new issue