本文整理汇总了PHP中Idno\Entities\User类的典型用法代码示例。如果您正苦于以下问题:PHP User类的具体用法?PHP User怎么用?PHP User使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了User类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: registerEventHooks
function registerEventHooks()
{
\Idno\Core\site()->template()->extendTemplate('account/settings/notifications/methods', 'subscriptions/settings');
\Idno\Core\site()->addEventHook('saved', function (\Idno\Core\Event $event) {
if (!empty($event->data()['object'])) {
$object = $event->data()['object'];
if (!$object instanceof ActivityStreamPost) {
/* @var Idno\Common\Entity $object ; */
$owner = $object->getOwner();
if ($users = User::get([], [], 9999)) {
//$email = new Email();
//$email->setSubject($object->getTitle());
//$email->setHTMLBodyFromTemplate('subscriptions/email', ['object' => $object, 'owner' => $owner]);
$title = implode(' ', array_slice(explode(' ', $object->getTitle()), 0, 10));
foreach ($users as $user) {
if (!empty($user->email) && $user->email != $owner->email && $user->notifications['subscriptions'] != 'none') {
$email = new Email();
$email->setSubject($title);
$email->setHTMLBodyFromTemplate('subscriptions/email', ['object' => $object, 'owner' => $owner]);
$email->addTo($user->email);
$email->send();
}
}
}
}
}
});
}
示例2: postContent
function postContent()
{
$fwd = $this->getInput('fwd');
// Forward to a new page?
if (empty($fwd)) {
$fwd = \Idno\Core\site()->config()->url;
}
if ($user = \Idno\Entities\User::getByHandle($this->getInput('email'))) {
} else {
if ($user = \Idno\Entities\User::getByEmail($this->getInput('email'))) {
} else {
\Idno\Core\site()->triggerEvent('login/failure/nouser', array('method' => 'password', 'credentials' => array('email' => $this->getInput('email'))));
$this->setResponse(401);
}
}
if ($user instanceof \Idno\Entities\User) {
if ($user->checkPassword(trim($this->getInput('password')))) {
\Idno\Core\site()->triggerEvent('login/success', array('user' => $user));
// Trigger an event for auditing
\Idno\Core\site()->session()->logUserOn($user);
$this->forward($fwd);
} else {
\Idno\Core\site()->session()->addErrorMessage("Oops! It looks like your password isn't correct. Please try again.");
\Idno\Core\site()->triggerEvent('login/failure', array('user' => $user));
$this->forward(\Idno\Core\site()->config()->getDisplayURL() . 'session/login/?fwd=' . urlencode($fwd));
}
} else {
\Idno\Core\site()->session()->addErrorMessage("Oops! We couldn't find your username or email address. Please check you typed it correctly and try again.");
$this->forward(\Idno\Core\site()->config()->getDisplayURL() . 'session/login/?fwd=' . urlencode($fwd));
}
}
示例3: postContent
function postContent()
{
$this->createGatekeeper();
// Logged-in only please
$user = \Idno\Core\site()->session()->currentUser();
$name = $this->getInput('name');
$email = $this->getInput('email');
$password = trim($this->getInput('password'));
$username = trim($this->getInput('handle'));
if (!empty($name)) {
$user->setTitle($name);
}
if (!empty($username) && $username != $user->getHandle()) {
$user->setHandle($username);
}
if (!empty($email) && $email != $user->email && filter_var($email, FILTER_VALIDATE_EMAIL)) {
if (!\Idno\Entities\User::getByEmail($email)) {
$user->email = $email;
} else {
\Idno\Core\site()->session()->addMessage('Someone is already using ' . $email . ' as their email address.', 'alert-error');
}
}
if (!empty($password)) {
$user->setPassword($password);
}
if ($user->save()) {
\Idno\Core\site()->session()->refreshSessionUser($user);
\Idno\Core\site()->session()->addMessage("Your details were saved.");
}
$this->forward($_SERVER['HTTP_REFERER']);
}
示例4: post
function post()
{
$this->flushBrowser();
\Idno\Core\site()->logging->log("Loading the user registration callback", LOGLEVEL_DEBUG);
$contents = $this->getInput('content');
$auth_token = $this->getInput('auth_token');
$time = $this->getInput('time');
$signature = $this->getInput('signature');
$secret = \Idno\Core\site()->hub()->secret;
$hmac = hash_hmac('sha1', $contents . $time . $auth_token, $secret);
if ($hmac == $signature) {
if ($contents = json_decode($contents)) {
if (!empty($contents->user)) {
if ($user = \Idno\Entities\User::getByUUID($contents->user)) {
$user->hub_settings = array('token' => $contents->auth_token, 'secret' => $contents->secret);
$user->save();
$result = array('status' => 'ok', 'message' => 'Credentials were stored.');
} else {
$result = array('status' => 'fail', 'message' => 'Couldn\'t find user: ' . $contents->user);
}
} else {
$result = array('status' => 'fail', 'message' => 'No user was sent');
}
} else {
$result = array('status' => 'fail', 'message' => 'Contents were invalid');
}
}
if (empty($result)) {
$result = array('status' => 'fail', 'message' => 'Signature does not match: ' . $signature . ', ' . $hmac);
}
echo json_encode($result);
exit;
}
示例5: postContent
function postContent()
{
$this->reverseGatekeeper();
$name = $this->getInput('name');
$handle = trim($this->getInput('handle'));
$password = trim($this->getInput('password'));
$email = trim($this->getInput('email'));
if (empty($handle) && empty($email)) {
\Idno\Core\site()->session()->addErrorMessage("Please enter a username and email address.");
} else {
if (!empty($email) && filter_var($email, FILTER_VALIDATE_EMAIL)) {
if (!($emailuser = \Idno\Entities\User::getByEmail($email)) && !($handleuser = \Idno\Entities\User::getByHandle($handle)) && !empty($handle) && strlen($handle) <= 32 && !substr_count($handle, '/') && \Idno\Entities\User::checkNewPasswordStrength($password)) {
$user = new Application();
$user->email = $email;
$user->handle = strtolower(trim($handle));
// Trim the handle and set it to lowercase
$user->setPassword($password);
$user->notifications['email'] = 'all';
if (empty($name)) {
$name = $user->handle;
}
$user->setTitle($name);
if ($user->save()) {
$t = clone \Idno\Core\site()->template();
$t->setTemplateType('email');
foreach (\Idno\Core\site()->getAdmins() as $admin) {
$email_message = new Email();
$email_message->setSubject("You have a new membership application!");
$email_message->addTo($admin->email);
$email_message->setHTMLBodyFromTemplate('applytojoin/new', ['user' => $user]);
$email_message->send();
}
$this->forward(\Idno\Core\site()->config()->getDisplayURL() . 'account/join/thanks/');
} else {
var_export(\Idno\Core\site()->session()->messages);
}
} else {
if (empty($handle)) {
\Idno\Core\site()->session()->addErrorMessage("Please create a username.");
}
if (strlen($handle) > 32) {
\Idno\Core\site()->session()->addErrorMessage("Your username is too long.");
}
if (substr_count($handle, '/')) {
\Idno\Core\site()->session()->addErrorMessage("Usernames can't contain a slash ('/') character.");
}
if (!empty($handleuser)) {
\Idno\Core\site()->session()->addErrorMessage("Unfortunately, someone is already using that username. Please choose another.");
}
if (!empty($emailuser)) {
\Idno\Core\site()->session()->addErrorMessage("Hey, it looks like there's already an account with that email address. Did you forget your login?");
}
if (!\Idno\Entities\User::checkNewPasswordStrength($password)) {
\Idno\Core\site()->session()->addErrorMessage("Please check that your password is at least 7 characters long.");
}
}
}
}
$this->forward(\Idno\Core\site()->config()->getDisplayURL() . 'account/join/');
}
示例6: getActor
function getActor()
{
if (is_string($this->actor)) {
return User::getByUUID($this->actor);
}
return $this->actor;
}
示例7: postContent
function postContent()
{
// TODO: change this to actual basic login, of course
if ($user = \Idno\Entities\User::getByHandle($this->getInput('email'))) {
} else {
if ($user = \Idno\Entities\User::getByEmail($this->getInput('email'))) {
} else {
\Idno\Core\site()->triggerEvent('login/failure/nouser', ['method' => 'password', 'credentials' => ['email' => $this->getInput('email')]]);
$this->setResponse(401);
$this->forward('/session/login');
}
}
if ($user instanceof \Idno\Entities\User) {
if ($user->checkPassword($this->getInput('password'))) {
\Idno\Core\site()->triggerEvent('login/success', ['user' => $user]);
// Trigger an event for auditing
\Idno\Core\site()->session()->logUserOn($user);
\Idno\Core\site()->session()->addMessage("You've signed in as {$user->getTitle()}.");
$this->forward();
} else {
\Idno\Core\site()->session()->addMessage("Oops! It looks like your password isn't correct. Please try again.");
\Idno\Core\site()->triggerEvent('login/failure', ['user' => $user]);
}
} else {
\Idno\Core\site()->session()->addMessage("Oops! We couldn't find your username or email address. Please check you typed it correctly and try again.");
}
}
示例8: postContent
function postContent()
{
$this->adminGatekeeper();
// Admins only
$action = $this->getInput('action');
switch ($action) {
case 'add_rights':
$uuid = $this->getInput('user');
if ($user = User::getByUUID($uuid)) {
$user->setAdmin(true);
$user->save();
\Idno\Core\site()->session()->addMessage($user->getTitle() . " was given administration rights.");
}
break;
case 'remove_rights':
$uuid = $this->getInput('user');
if ($user = User::getByUUID($uuid)) {
$user->setAdmin(false);
$user->save();
\Idno\Core\site()->session()->addMessage($user->getTitle() . " was stripped of their administration rights.");
}
break;
case 'delete':
$uuid = $this->getInput('user');
if ($user = User::getByUUID($uuid)) {
if ($user->delete()) {
\Idno\Core\site()->session()->addMessage($user->getTitle() . " was removed from your site.");
}
}
break;
case 'invite_users':
$emails = $this->getInput('invitation_emails');
preg_match_all('/[a-z\\d._%+-]+@[a-z\\d.-]+\\.[a-z]{2,4}\\b/i', $emails, $matches);
$invitation_count = 0;
if (!empty($matches[0])) {
if (is_array($matches[0])) {
foreach ($matches[0] as $email) {
if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
if (!($user = User::getByEmail($email))) {
if ((new Invitation())->sendToEmail($email) !== 0) {
$invitation_count++;
}
}
}
}
}
}
if ($invitation_count > 1) {
\Idno\Core\site()->session()->addMessage("{$invitation_count} invitations were sent.");
} else {
if ($invitation_count == 1) {
\Idno\Core\site()->session()->addMessage("Your invitation was sent.");
} else {
\Idno\Core\site()->session()->addMessage("No email addresses were found or all the people you invited are already members of this site.");
}
}
break;
}
$this->forward(\Idno\Core\site()->config()->getURL() . 'admin/users');
}
示例9: authenticate
/**
* Check that this token is either a user token or the
* site's API token, and auth the current request for that user if so.
*
* @return \Idno\Entities\User user on success
*/
private static function authenticate()
{
$access_token = \Idno\Core\Input::getInput('access_token');
$headers = \Idno\Common\Page::getallheaders();
if (!empty($headers['Authorization'])) {
$token = $headers['Authorization'];
$token = trim(str_replace('Bearer', '', $token));
} else {
if ($token = \Idno\Core\Input::getInput('access_token')) {
$token = trim($token);
}
}
if (!empty($token)) {
$found = Token::findUserForToken($token);
if (!empty($found)) {
\Idno\Core\Idno::site()->session()->setIsAPIRequest(true);
$user = $found['user'];
\Idno\Core\Idno::site()->session()->refreshSessionUser($user);
return $user;
}
$user = \Idno\Entities\User::getOne(array('admin' => true));
if ($token == $user->getAPIkey()) {
\Idno\Core\Idno::site()->session()->setIsAPIRequest(true);
\Idno\Core\Idno::site()->session()->refreshSessionUser($user);
return $user;
}
}
return false;
}
示例10: init
/**
* Sets the page owner on the homepage
*/
function init()
{
\Idno\Core\Idno::site()->events()->addListener('page/get', function (\Idno\Core\Event $event) {
if ($event->data()['page_class'] == 'Idno\\Pages\\Homepage') {
\Idno\Core\Idno::site()->currentPage()->setOwner(\Idno\Entities\User::getOne(['admin' => 1]));
}
});
}
示例11: init
/**
* Sets the page owner on the homepage
*/
function init()
{
\Idno\Core\site()->events()->addListener('page/get', function (\Idno\Core\Event $event) {
if ($event->data()['page_class'] == 'Idno\\Pages\\Homepage') {
\Idno\Core\site()->currentPage()->setOwner(\Idno\Entities\User::getOne(['admin' => true]));
}
});
\Idno\Core\site()->addPageHandler('/admin/cherwell/?', 'Themes\\Cherwell\\Pages\\Admin');
}
示例12: getContent
function getContent()
{
$this->adminGatekeeper();
// Admins only
$users = User::get(array('admin' => true));
$t = \Idno\Core\Idno::site()->template();
$t->body = $t->__(array('users' => $users))->draw('admin/cherwell');
$t->title = 'Theme Settings';
$t->drawPage();
}
示例13: getContent
function getContent()
{
if (!empty($this->arguments[0])) {
$user = \Idno\Entities\User::getByHandle($this->arguments[0]);
}
if (empty($user)) {
$this->forward();
}
// TODO: 404
$t = \Idno\Core\site()->template();
$t->__(array('title' => 'Edit profile: ' . $user->getTitle(), 'body' => $t->__(array('user' => $user))->draw('entity/User/edit')))->drawPage();
}
示例14: getContent
function getContent()
{
$results = [];
$username = $this->getInput('username');
if ($users = User::get([], [], 9999)) {
//User::getByHandle($username)) {
foreach ($users as $user) {
/* @var \Idno\Entities\User $user */
$results[] = ['username' => $user->getHandle(), 'name' => $user->getTitle(), 'image' => $user->getIcon()];
}
}
header('Content-type: text/json');
echo json_encode($results);
}
示例15: canEdit
function canEdit($user_id = '')
{
if (empty($user_id)) {
$user = \Idno\Core\site()->session()->currentUser();
} else {
$user = User::getByUUID($user_id);
}
if (!$user instanceof User) {
return false;
}
if (!$user->isAdmin()) {
return false;
}
return true;
}