Skip to content

Latest commit

 

History

History

Users

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 

You have to be logged in and have relevant permissions.

USER LISTING

$listing = \ATDev\RocketChat\Users\User::listing();

if (!$listing) {

	// Log the error
	$error = \ATDev\RocketChat\Users\User::getError();
}

CREATE USER

$user = new \ATDev\RocketChat\Users\User();
$user->setName("John Doe");
$user->setEmail("[email protected]");
$user->setUsername("jDoe");
$user->setPassword("123456");

$result = $user->create();

if (!$result) {

	// Log the error
	$error = $user->getError();
}

REGISTER USER

$user = new \ATDev\RocketChat\Users\User();
$user->setName("John Doe");
$user->setEmail("[email protected]");
$user->setUsername("jDoe");
$user->setPassword("123456");

$result = $user->register("[SECRET URL STRING]");
if (!$result) {
	$error = $user->getError();
}

GET USER INFO

$user = new \ATDev\RocketChat\Users\User("[USER ID]");

$result = $user->info();

if (!$result) {

	// Log the error
	$error = $user->getError();
}

UPDATE USER

$user = new \ATDev\RocketChat\Users\User("[USER ID]");
$result = $user->info(); // Get info so that all existing info is preserved

$user->setName("New Doe");

$result = $user->update();

if (!$result) {

	// Log the error
	$error = $user->getError();
}

UPDATE OWN BASIC INFO

$user = \ATDev\RocketChat\Chat::me();
$user->setEmail('[email protected]');
$user->setUsername('[NEW-USER-NAME]');
$user->setName('[NEW-NAME]');
$user->setPassword(hash('sha256', '[CURRENT-PASSWORD]'));
$user->setNewPassword('newPassw0rd');
$user->setCustomFields("{ twitter: '@example' }");

$updatedUser = $user->updateOwnBasicInfo();
if (!$updatedUser) {
    $error = $user->getError();
}

SET ACTIVE STATUS

$user = new \ATDev\RocketChat\Users\User("[USER ID]");
$statusResult = $user->setActiveStatus(true);
if (!$statusResult) {
    $user->getError();
}

SET STATUS MESSAGE

$user = \ATDev\RocketChat\Chat::me();
$result = $user->setStatus("[STATUS MESSAGE]", "away");
if (!$result) {
    $error = $user->getError();
}

GET STATUS

// by userId
$user = (new \ATDev\RocketChat\Users\User())->setUserId("[USER ID]");
// or by username
$user = (new \ATDev\RocketChat\Users\User())->setUsername("[USERNAME]");
$result = $user->getStatus();
// or get callee's status if no userId or username provided
$result = (new \ATDev\RocketChat\Users\User())->getStatus();
if (!$result) {
    $error = $user->getError();
}

UPDATE USER AVATAR FROM LOCAL FILE

$user = new \ATDev\RocketChat\Users\User("[USER ID]");
// or by username
$user = (new \ATDev\RocketChat\Users\User())->setUsername("[USERNAME]");
$avatar = new \ATDev\RocketChat\Users\AvatarFromFile("[PATH TO LOCAL READABLE FILE]");

$result = $user->setAvatar($avatar);
if (!$result) {
	// Log the error
	$error = $user->getError();
}

UPDATE USER AVATAR FROM URL

$user = new \ATDev\RocketChat\Users\User("[USER ID]");
// or by username
$user = (new \ATDev\RocketChat\Users\User())->setUsername("[USERNAME]");
$avatar = new \ATDev\RocketChat\Users\AvatarFromDomain("[URL TO FILE AVAILABLE IN PUBLIC]");

$result = $user->setAvatar($avatar);
if (!$result) {
	// Log the error
	$error = $user->getError();
}

GET USER AVATAR

$user = new \ATDev\RocketChat\Users\User("[USER ID]");
// or by username
$user = (new \ATDev\RocketChat\Users\User())->setUsername("[USERNAME]");

$result = $user->getAvatar();
if (!$result) {
	// Log the error
	$error = $user->getError();
} else {
	// Url to new user avatar
	$user->getAvatarUrl();
}

RESET USER AVATAR

$user = new \ATDev\RocketChat\Users\User("[USER ID]");
// or by username
$user = (new \ATDev\RocketChat\Users\User())->setUsername("[USERNAME]");
$resetResultUser = $user->resetAvatar();
if (!$resetResultUser) {
    $error = $user->getError();
}

DELETE USER

$user = new \ATDev\RocketChat\Users\User("[USER ID]");

$result = $user->delete();

if (!$result) {

	// Log the error
	$error = $user->getError();
}

DELETE OWN ACCOUNT

$user = \ATDev\RocketChat\Chat::me();
$user->setPassword(hash("sha256","[USER PASSWORD]"));
$result = $user->deleteOwnAccount();
if (!$result) {
    $error = \ATDev\RocketChat\Users\User::getError();
}

DEACTIVATE IDLE

$count = \ATDev\RocketChat\Users\User::deactivateIdle(5, "guest");
if (!$count) {
    $error = \ATDev\RocketChat\Users\User::getError();
}

PRESENCE

$users = \ATDev\RocketChat\Users\User::presence("2019-05-22T12:11:45.392Z");
if (!$users) {
	$error = \ATDev\RocketChat\Users\User::getError();
}
print_r($users->first()->getUsername());
print_r($users->isFull());

GET PRESENCE

$user = new \ATDev\RocketChat\Users\User("[USER ID]");
// or by username
$user = (new \ATDev\RocketChat\Users\User())->setUsername("[USERNAME]");
$userPresence = $user->getPresence();
// or callee's presence
$userPresence = (new \ATDev\RocketChat\Users\User())->getPresence();
if (!$userPresence) {
	$error = \ATDev\RocketChat\Users\User::getError();
}
print_r($userPresence->connectionStatus);
print_r($userPresence->lastLogin);

FORGOT PASSWORD

$result = \ATDev\RocketChat\Users\User::forgotPassword('[email protected]');
if (!$result) {
    $result->getError();
}

GET USERNAME SUGGESTION

$user = \ATDev\RocketChat\Chat::me();
$result = $user->getUsernameSuggestion();
if (!$result) {
    $user->getError();
}

SET PREFERENCES

$user = \ATDev\RocketChat\Chat::login("[USERNAME]", "[PASSWORD]");
$preferences = new \ATDev\RocketChat\Users\Preferences();
$preferences->setHighlights(['highlight phrase', 'highlightword']);
$preferences->setAutoImageLoad(false);

$result = $user->setPreferences($preferences);
if (!$result) {
    $result->getError();
}

$preferences = $result->getPreferencesData();
$preferences->getHighlights();

GET PREFERENCES

$user = \ATDev\RocketChat\Chat::login("[USERNAME]", "[PASSWORD]");
$preferences = $user->getPreferences();
if (!$preferences) {
    $user->getError();
}

$preferences->getDesktopNotificationDuration();

CREATE TOKEN

$user = \ATDev\RocketChat\Chat::me();
$result = $user->createToken();
if (!$result) {
    $user->getError();
}

GET PERSONAL ACCESS TOKENS

$user = \ATDev\RocketChat\Chat::me();
$result = $user->getPersonalAccessTokens();
if (!$result) {
    $user->getError();
}

GENERATE PERSONAL ACCESS TOKEN

$user = \ATDev\RocketChat\Chat::me();
$result = $user->generatePersonalAccessToken("[TOKEN NAME]", true);
if (!$result) {
    $user->getError();
}

REGENERATE PERSONAL ACCESS TOKEN

$user = \ATDev\RocketChat\Chat::me();
$result = $user->regeneratePersonalAccessToken("[TOKEN NAME]");
if (!$result) {
    $user->getError();
}

REMOVE PERSONAL ACCESS TOKEN

$user = \ATDev\RocketChat\Chat::me();
$result = $user->removePersonalAccessToken("[TOKEN NAME]");
if (!$result) {
    $user->getError();
}

REMOVE OTHER TOKENS

$user = \ATDev\RocketChat\Chat::me();
$result = $user->removeOtherTokens();
if (!$result) {
    $user->getError();
}