Wraps the UserApp PHP client into a small and user-friendly API.
If you don't have a UserApp account, you need to create one.
- App Id: The App Id identifies your app. After you have logged in, you should see your
App Id
instantly. If you're having trouble finding it, follow this guide.
UserApp relies on the autoloading features of PHP to load its files when needed. The autoloading complies with the PSR-0 standard which makes it compatible with most of the major frameworks and libraries. Autoloading in your application is handled automatically when managing the dependencies with Composer.
{
"require": {
"userapp/widget": "~0.6.3"
}
}
require 'autoload.php';
<?php
use \UserApp\Widget\User;
// Import composer autoloader
require_once('vendor/autoload.php');
User::setAppId("YOUR APP ID");
<?php
use \UserApp\Widget\User;
require_once('bootstrap.php');
User::onUnauthorized(function ($sender, $call_context, $error){
header('Location: /login.php');
die();
});
<?php
use \UserApp\Widget\User;
require_once('bootstrap.php');
if($_SERVER['REQUEST_METHOD'] === 'POST'){
$redirect_to = 'login.php?error=INVALID_CREDENTIALS';
if(User::login($_POST['username'], $_POST['password'])){
$redirect_to = 'user/profile.php';
}
header('Location: /' . $redirect_to);
die();
}
?>
<form method="post">
Username: <input type="text" name="username" /><br />
Password: <input type="password" name="password" /><br />
<? if(isset($_GET['error']) && $_GET['error'] == 'INVALID_CREDENTIALS'){ ?>
* Invalid username or password<br />
<? } ?>
<input type="submit" value="Log in" />
</form>
<?php
use \UserApp\Widget\User;
require_once('../must_authenticate.php');
$user = User::current();
?>
User id: <?= $user->user_id ?><br /><br />
Username: <?= ($user->login ?: '(not specified)') ?><br />
First name: <?= ($user->first_name ?: '(not specified)') ?><br />
Last name: <?= ($user->last_name ?: '(not specified)') ?><br />
Email: <?= ($user->email ?: '(not specified)') ?><br />
<a href="logout.php">Logout</a>
<?php
use \UserApp\Widget\User;
require_once('../must_authenticate.php');
$user = User::current();
$user->logout();
header('Location: ../login.php');
bool User::login($username, $password)
bool User::loginWithToken($token)
bool User::signup($username, $password, $email = null, $first_name = null, $last_name = null, $auto_login = true)
bool User::authenticated()
User User::current()
$user = User::current();
$user->logout();
$user->user_id
$user->properties->age->value
- string user_id
- string first_name
- string last_name
- string email
- string login
- object properties
- object features
- object permissions
- array locks
- string ip_address
- int last_login_at
- int updated_at
- int created_at
bool $user->hasPermission($permission_name)
bool $user->hasFeature($feature_name)
void $user->save()
$user->first_name = 'John';
$user->last_name = 'Johnsson';
$user->properties->my_own_property = 'some value';
$user->save();
void $user->logout()
void onUnauthorized(closure($sender, $call_context, $error))
User::onUnauthorized(function($sender, $call_context, $error){
header('Location: /login.php');
die();
});
MIT