1. Go to this page and download the library: Download openclerk/users 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/ */
openclerk / users example snippets
$migrations = new AllMigrations(db());
if ($migrations->hasPending(db())) {
$migrations->install(db(), $logger);
}
// get current user
$user = Users\User::getInstance(db());
// logout any current user
Users\User::logout(db());
// get a user instance
$user = Users\User::findUser(db(), $user_id);
// signup
$user = Users\UserPassword::trySignup(db(), $email /* may not be null */, $password);
if ($user) {
echo "<h2>Signed up successfully</h2>";
}
// login
$user = Users\UserPassword::tryLogin(db(), $email /* may not be null */, $password);
if ($user) {
echo "<h2>Logged in successfully as $user</h2>";
$user->persist(db());
}
// forgot password
$secret = Users\UserPassword::forgottenPassword(db(), $email);
echo "Secret = $secret\n";
// complete forgot password
Users\UserPassword::completePasswordReset(db(), $email, $secret, $new_password);
// add password to existing user
$user = Users\User::getInstance(db());
$result = Users\UserPassword::addPassword(db(), $user, $password);
// signup
$user = Users\UserOpenID::trySignup(db(), $email /* may be null */, $openid, "http://localhost/register.php");
if ($user) {
echo "<h2>Signed up successfully</h2>";
}
// login
$user = Users\UserOpenID::tryLogin(db(), $openid, "http://localhost/login.php");
if ($user) {
echo "<h2>Logged in successfully as $user</h2>";
$user->persist(db());
}
// add identity to existing user
$user = Users\User::getInstance(db());
$result = Users\UserOpenID::addIdentity(db(), $user, $openid, "http://localhost/add.php");
// signup
$user = Users\UserOAuth2::trySignup(db(), Users\OAuth2Providers::google("http://localhost/register.php"));
if ($user) {
echo "<h2>Signed up successfully</h2>";
}
// login
$user = Users\UserOAuth2::tryLogin(db(), Users\OAuth2Providers::google("http://localhost/login.php"));
if ($user) {
echo "<h2>Logged in successfully as $user</h2>";
$user->persist(db());
}
// add identity to existing user
$user = Users\User::getInstance(db());
$result = Users\UserOAuth2::addIdentity(db(), $user, Users\OAuth2Providers::google("http://localhost/add.php"));
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.