PHP code example of tinyapps / tinyusermanager

1. Go to this page and download the library: Download tinyapps/tinyusermanager library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

tinyapps / tinyusermanager example snippets




return [
  'host' => '127.0.0.1',
  'db' => 'your_db',
  'user' => 'db_user',
  'password' => 'db_password'
];

$dbConfig = nager\Helpers\Database::conn(
  $dbConfig['host'],
  $dbConfig['db'],
  $dbConfig['user'],
  $dbConfig['password'],
  'utf8mb4'
);

$session = new TinyUserManager\Session();
if ($session->login('[email protected]', 'opensesame')) {
  // login succeded
} else {
  // wrong credentials
}

if ($session->loggedIn()) {
  // user is logged in
  $user = $session->getUser();
}

if ($user = TinyUserManager\UserManager::createUser('[email protected]', 'opensesame', ['phone' => '+49 123 45678'])) {
  // User has been created
}

$emailConfig = new TinyUserManager\EmailConfig('[email protected]', 'Example');

TinyUserManager\ConfirmationHandler::sendConfirmationEmail($user, $emailConfig, 'Please confirm your registration', '<p><a href="https://example.com/activate/%uid%/%token%">Activate account</a></p>');

$emailConfig->useSmtp();
$emailConfig->setHost('mail.example.com');
$emailConfig->setUsername('[email protected]');
$emailConfig->setPassword('your_email_password');
$emailConfig->setPort(465);
$emailConfig->setSmtpSecure('ssl');

$user = TinyUserManager\UserManager::getUser($userId);
if (TinyUserManager\ConfirmationHandler::confirmUser($user, $token)) {
  // confirmed
}

$user->setField('phone', '+49 123 456789');
TinyUserManager\UserManager::updateUser($user);

TinyUserManager\PasswordResetHandler::sendConfirmationEmail(
	$user,
	$emailConfig,
	$emailSubject,
	'<a href="https://example.com/reset/?uid=%uid%&token=%token%">Reset password</a>',
);

$user = TinyUserManager\UserManager::getUser($userId);
if (TinyUserManager\PasswordResetHandler::confirmPasswordForgotToken($user, $token)) {
  // valid
}

TinyUserManager\PasswordResetHandler::setNewPassword($user, $newPassword);