本文整理汇总了PHP中Idno\Entities\User::getByHandle方法的典型用法代码示例。如果您正苦于以下问题:PHP User::getByHandle方法的具体用法?PHP User::getByHandle怎么用?PHP User::getByHandle使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Idno\Entities\User
的用法示例。
在下文中一共展示了User::getByHandle方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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.");
}
}
示例2: 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/');
}
示例3: 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));
}
}
示例4: 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();
}
示例5: postContent
function postContent()
{
if (!empty($this->arguments[0])) {
$user = \Idno\Entities\User::getByHandle($this->arguments[0]);
}
if (empty($user)) {
$this->forward();
}
// TODO: 404
if ($user->saveDataFromInput($this)) {
\Idno\Core\site()->session()->addMessage($user->getTitle() . ' was saved.');
$this->forward($user->getURL());
}
$this->forward($_SERVER['HTTP_REFERER']);
}
示例6: getContent
function getContent()
{
$acct = $this->getInput('resource');
if (!empty($acct)) {
if (substr($acct, 0, 5) == 'acct:' && strlen($acct) > 8) {
$handle = str_replace('@' . \Idno\Core\site()->config()->host, '', substr($acct, 5));
if ($user = \Idno\Entities\User::getByHandle($handle)) {
$links = \Idno\Core\site()->triggerEvent('webfinger', array('object' => $user));
}
}
}
$t = \Idno\Core\site()->template();
$t->setTemplateType('json');
$t->__(array('subject' => $acct, 'links' => $links))->drawPage();
}
示例7: 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') {
if (!empty(\Idno\Core\Idno::site()->config()->cherwell['profile_user'])) {
if ($profile_user = User::getByHandle(\Idno\Core\Idno::site()->config()->cherwell['profile_user'])) {
\Idno\Core\Idno::site()->currentPage()->setOwner($profile_user);
}
}
if (empty($profile_user)) {
\Idno\Core\Idno::site()->currentPage()->setOwner(\Idno\Entities\User::getOne(['admin' => true]));
}
}
});
\Idno\Core\Idno::site()->addPageHandler('/admin/cherwell/?', 'Themes\\Cherwell\\Pages\\Admin');
}
示例8: postContent
function postContent()
{
$name = $this->getInput('name');
$handle = $this->getInput('handle');
$password = $this->getInput('password');
$password2 = $this->getInput('password2');
$email = $this->getInput('email');
$user = new \Idno\Entities\User();
if (!empty($email) && filter_var($email, FILTER_VALIDATE_EMAIL)) {
if (!($emailuser = \Idno\Entities\User::getByEmail($email)) && !($handleuser = \Idno\Entities\User::getByHandle($handle)) && !empty($handle) && $password == $password2 && strlen($password) > 4 && !empty($name)) {
$user = new \Idno\Entities\User();
$user->email = $email;
$user->handle = $handle;
$user->setPassword($password);
$user->setTitle($name);
if (!\Idno\Entities\User::get()) {
$user->setAdmin(true);
}
$user->save();
} else {
if (empty($handle)) {
\Idno\Core\site()->session()->addMessage("You can't have an empty handle.");
} else {
if (!empty($handleuser)) {
\Idno\Core\site()->session()->addMessage("Unfortunately, a user is already using that handle. Please choose another.");
}
}
if (!empty($emailuser)) {
\Idno\Core\site()->session()->addMessage("Unfortunately, a user is already using that email address. Please choose another.");
}
if ($password != $password2 || strlen($password) <= 4) {
\Idno\Core\site()->session()->addMessage("Please check that your passwords match and that your password is over four characters long.");
}
}
} else {
\Idno\Core\site()->session()->addMessage("That doesn't seem to be a valid email address.");
}
if (!empty($user->_id)) {
\Idno\Core\site()->session()->addMessage("You've registered! Well done.");
\Idno\Core\site()->session()->logUserOn($user);
} else {
\Idno\Core\site()->session()->addMessage("We couldn't register you.");
$this->forward($_SERVER['HTTP_REFERER']);
}
}
示例9: postContent
function postContent()
{
$this->adminGatekeeper();
$user_uuid = $this->getInput('user');
$action = $this->getInput('action');
$user = Application::getByUUID($user_uuid);
if ($user instanceof Application) {
$name = $user->getTitle();
$handle = $user->handle;
$email = $user->email;
switch ($action) {
case 'approve':
if (!($emailuser = \Idno\Entities\User::getByEmail($email)) && !($handleuser = \Idno\Entities\User::getByHandle($handle)) && !empty($handle) && strlen($handle) <= 32 && !substr_count($handle, '/')) {
$real_user = new \Idno\Entities\User();
$real_user->setHandle($user->handle);
$real_user->email = $user->email;
$real_user->password = $user->password;
$real_user->setTitle($user->getTitle());
if ($real_user->save()) {
$user->delete();
$email_message = new Email();
$email_message->setSubject("Your membership was approved!");
$email_message->addTo($real_user->email);
$email_message->setHTMLBodyFromTemplate('applytojoin/approved', ['user' => $real_user]);
$email_message->send();
\Idno\Core\site()->session()->addMessage("{$name}'s membership application was approved. They can now log into the site.");
} else {
\Idno\Core\site()->session()->addMessage("Something went wrong and we weren't able to approve {$name}'s membership application.");
}
} else {
\Idno\Core\site()->session()->addMessage("We couldn't approve {$name}'s application. Either their handle or their email was invalid or in use.");
}
break;
case 'delete':
$user->delete();
\Idno\Core\site()->session()->addMessage("{$name}'s membership application was deleted.");
break;
}
}
$this->forward(\Idno\Core\site()->config()->getDisplayURL() . 'admin/applytojoin/');
}
示例10: postContent
function postContent()
{
if (!empty($this->arguments[0])) {
$user = \Idno\Entities\User::getByHandle($this->arguments[0]);
}
if (empty($user)) {
$this->forward();
}
// TODO: 404
if ($user->saveDataFromInput($this)) {
if ($onboarding = $this->getInput('onboarding')) {
$services = \Idno\Core\site()->syndication()->getServices();
if (!empty($services) || !empty(\Idno\Core\site()->config->force_onboarding_connect)) {
$this->forward(\Idno\Core\site()->config()->getURL() . 'begin/connect');
} else {
$this->forward(\Idno\Core\site()->config()->getURL() . 'begin/publish');
}
}
$this->forward($user->getURL());
}
$this->forward($_SERVER['HTTP_REFERER']);
}
示例11:
/**
* Return an admin test user, creating it if necessary.
* @return \Idno\Entities\User
*/
protected function &admin()
{
// Have we already got a user?
if (static::$testAdmin) {
return static::$testAdmin;
}
// Get a user (shouldn't happen)
if ($user = \Idno\Entities\User::getByHandle('testadmin')) {
static::$testAdmin = $user;
return $user;
}
// No user there, so create one
$user = new \Idno\Entities\User();
$user->handle = 'testadmin';
$user->email = 'hello@withknown.com';
$user->setPassword(md5(rand()));
// Set password to something random to mitigate security holes if cleanup fails
$user->setTitle('Test Admin User');
$user->setAdmin(true);
$user->save();
static::$testAdmin = $user;
return $user;
}
示例12: getByProfileURL
/**
* Retrieve a user by their profile URL.
* @param string $url
* @return User|false
*/
static function getByProfileURL($url)
{
// If user explicitly has a profile url set (generally this means it's a RemoteUser class
if ($result = \Idno\Core\Idno::site()->db()->getObjects(get_called_class(), array('url' => $url), null, 1)) {
foreach ($result as $row) {
return $row;
}
}
// Ok, now try and see if we can get the local profile
if (preg_match("~" . \Idno\Core\Idno::site()->config()->url . 'profile/([A-Za-z0-9]+)?~', $url, $matches)) {
return \Idno\Entities\User::getByHandle($matches[1]);
}
// Can't find
return false;
}
示例13: APIlogin
/**
* Checks HTTP request headers to see if the request has been properly
* signed for API access, and if so, log the user on and return the user
*
* @return \Idno\Entities\User|false The logged-in user, or false otherwise
*/
function APIlogin()
{
if (!empty($_SERVER['HTTP_X_KNOWN_USERNAME']) && !empty($_SERVER['HTTP_X_KNOWN_SIGNATURE'])) {
\Idno\Core\site()->session()->setIsAPIRequest(true);
if (!\Idno\Common\Page::isSSL() && !\Idno\Core\site()->config()->disable_cleartext_warning) {
\Idno\Core\site()->session()->addErrorMessage("Warning: Access credentials were sent over a non-secured connection! To disable this warning set disable_cleartext_warning in your config.ini");
}
$t = site()->currentPage()->getInput('_t');
if (empty($t)) {
site()->template()->setTemplateType('json');
}
if ($user = \Idno\Entities\User::getByHandle($_SERVER['HTTP_X_KNOWN_USERNAME'])) {
// Short circuit authentication, since this user is already logged in. Needed to resolve #595
if (\Idno\Core\site()->session()->currentUser() && \Idno\Core\site()->session()->currentUser()->getUUID() == $user->getUUID()) {
return $user;
}
$key = $user->getAPIkey();
$hmac = trim($_SERVER['HTTP_X_KNOWN_SIGNATURE']);
$compare_hmac = base64_encode(hash_hmac('sha256', $_SERVER['REQUEST_URI'], $key, true));
if ($hmac == $compare_hmac) {
\Idno\Core\site()->session()->logUserOn($user);
return $user;
}
}
}
// We're not logged in yet, so try and authenticate using other mechanism
if ($return = site()->triggerEvent('user/auth/api', [], false)) {
\Idno\Core\site()->session()->setIsAPIRequest(true);
if (!\Idno\Common\Page::isSSL() && !\Idno\Core\site()->config()->disable_cleartext_warning) {
\Idno\Core\site()->session()->addErrorMessage("Warning: Access credentials were sent over a non-secured connection! To disable this warning set disable_cleartext_warning in your config.ini");
}
}
// If this is an API request but we're not logged in, set page response code to access denied
if ($this->isAPIRequest() && !$return) {
site()->currentPage()->setResponse(403);
}
return $return;
}
示例14: postContent
function postContent()
{
$name = $this->getInput('name');
$handle = trim($this->getInput('handle'));
$password = trim($this->getInput('password'));
$password2 = trim($this->getInput('password2'));
$email = trim($this->getInput('email'));
$code = $this->getInput('code');
$onboarding = $this->getInput('onboarding');
/*if (!\Idno\Common\Page::isSSL() && !\Idno\Core\site()->config()->disable_cleartext_warning) {
\Idno\Core\site()->session()->addErrorMessage("Warning: Access credentials were sent over a non-secured connection! To disable this warning set disable_cleartext_warning in your config.ini");
}*/
if (empty(\Idno\Core\site()->config()->open_registration)) {
if (!($invitation = \Idno\Entities\Invitation::validate($email, $code))) {
\Idno\Core\site()->session()->addErrorMessage("Your invitation doesn't seem to be valid, or has expired.");
$this->forward(\Idno\Core\site()->config()->getURL());
} else {
// Removing this from here - invitation will be deleted once user is created
//$invitation->delete(); // Remove the invitation; it's no longer needed
}
}
$user = new \Idno\Entities\User();
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 && preg_match('/^[a-zA-Z0-9_]{1,}$/', $handle) && !substr_count($handle, '/') && $password == $password2 & \Idno\Entities\User::checkNewPasswordStrength($password)) {
$user = new \Idno\Entities\User();
$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 (!\Idno\Entities\User::get()) {
$user->setAdmin(true);
$user->robot_state = '1';
// State for our happy robot helper
if (\Idno\Core\site()->config()->title == 'New Known site') {
if (!empty($_SESSION['set_name'])) {
\Idno\Core\site()->config()->title = $_SESSION['set_name'];
} else {
\Idno\Core\site()->config()->title = $user->getTitle() . '\'s Known';
}
\Idno\Core\site()->config()->theme = 'Solo';
\Idno\Core\site()->config()->open_registration = false;
\Idno\Core\site()->config()->from_email = $user->email;
\Idno\Core\site()->config()->save();
}
\Idno\Core\site()->triggerEvent('site/firstadmin', array('user' => $user));
// Event hook for first admin
} else {
\Idno\Core\site()->triggerEvent('site/newuser', array('user' => $user));
// Event hook for new user
}
$user->save();
// Now we can remove the invitation
if (!empty($invitation)) {
if ($invitation instanceof Invitation) {
$invitation->delete();
// Remove the invitation; it's no longer needed
}
}
} 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 (!preg_match('/^[a-zA-Z0-9_]{1,}$/', $handle)) {
\Idno\Core\site()->session()->addErrorMessage("Usernames can only have letters, numbers and underscores.");
}
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) || $password != $password2) {
\Idno\Core\site()->session()->addErrorMessage("Please check that your passwords match and that your password is at least 7 characters long.");
}
}
} else {
\Idno\Core\site()->session()->addErrorMessage("That doesn't seem like it's a valid email address.");
}
}
if (!empty($user->_id)) {
\Idno\Core\site()->session()->addMessage("You've registered! You're ready to get started. Why not add a status update to say hello?");
\Idno\Core\site()->session()->logUserOn($user);
if (empty($onboarding)) {
$this->forward();
} else {
$this->forward(\Idno\Core\site()->config()->getURL() . 'begin/profile');
//.........这里部分代码省略.........
示例15: 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 (!($user = User::getByEmail($email))) {
$invitation = new Invitation();
if ($invitation->sendToEmail($email, \Idno\Core\site()->session()->currentUser()->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;
case 'remove_invitation':
$invitation_id = $this->getInput('invitation_id');
if ($invitation = Invitation::getByID($invitation_id)) {
if ($invitation->delete()) {
\Idno\Core\site()->session()->addMessage("The invitation was removed.");
}
}
break;
case 'resend_invitation':
$invitation_id = $this->getInput('invitation_id');
if ($invitation = Invitation::getByID($invitation_id)) {
$email = $invitation->email;
if ($invitation->delete()) {
$new_invitation = new Invitation();
if ($new_invitation->sendToEmail($email)) {
\Idno\Core\site()->session()->addMessage("The invitation was resent.");
}
}
}
break;
case 'add_user':
if (!\Idno\Core\site()->config()->canAddUsers()) {
\Idno\Core\site()->session()->addMessage("You can't add any more users to your site.");
break;
}
$name = $this->getInput('name');
$handle = trim($this->getInput('handle'));
$email = trim($this->getInput('email'));
$password = trim($this->getInput('password1'));
$password2 = trim($this->getInput('password2'));
$user = new \Idno\Entities\User();
if (empty($password) || $password != $password2) {
\Idno\Core\site()->session()->addMessage("Please make sure your passwords match and aren't empty.");
} else {
if (empty($handle) && empty($email)) {
\Idno\Core\site()->session()->addMessage("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, '/')) {
$user = new \Idno\Entities\User();
$user->email = $email;
$user->handle = strtolower(trim($handle));
// Trim the handle and set it to lowercase
$user->setPassword($password);
//.........这里部分代码省略.........