kpmpgsmkii/kanga.world/site/plugins/kangaworld-integration/user.php

40 lines
987 B
PHP

<?php
function kpApiUserCreate($name, $email, $password, &$response) {
try {
kirby()->users()->create([
'name' => $name,
'email' => $email,
'password' => $password,
'language' => 'en',
'role' => 'user'
]);
$response['result'] = 'true';
$response['reason'] = 'User created.';
} catch(Exception $e) {
$response['reason'] = $e->getMessage();
}
}
function kpApiUserGet($email, &$response) {
try {
$user = kirby()->users()->findByKey($email);
//$response['userraw'] = dump($user);
if ($user) {
$response['name'] = $user->username();
$response['email'] = $user->email();
$response['password'] = $user->password();
$response['language'] = $user->language();
$response['role'] = $user->role()->id();
$response['result'] = 'true';
$response['reason'] = 'User found.';
} else {
$response['reason'] = 'User not found.';
}
} catch(Exception $e) {
$response['reason'] = $e->getMessage();
}
}
?>