示例#1
0
 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
0
文件: Admin.php 项目: sintoris/Known
 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();
 }
示例#3
0
 function getContent()
 {
     $this->adminGatekeeper();
     // Admins only
     $users = User::get(array(), array(), 99999, 0);
     // TODO: make this more complete / efficient
     $remoteusers = RemoteUser::get(array(), array(), 99999, 0);
     $users = array_merge($users, $remoteusers);
     $t = \Idno\Core\site()->template();
     $t->body = $t->__(array('users' => $users))->draw('admin/users');
     $t->title = 'User Management';
     $t->drawPage();
 }
示例#4
0
 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);
 }
示例#5
0
 static function findUserForToken($token)
 {
     // find a user by their code
     for ($offset = 0;; $offset += 10) {
         $users = \Idno\Entities\User::get(array(), array(), 10, $offset);
         if (empty($users)) {
             break;
         }
         foreach ($users as $user) {
             $indieauth_tokens = $user->indieauth_tokens;
             if (!empty($indieauth_tokens) && isset($indieauth_tokens[$token])) {
                 return array('user' => $user, 'data' => $indieauth_tokens[$token]);
             }
         }
     }
     return array();
 }
示例#6
0
 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']);
     }
 }
示例#7
0
 static function findUserForCode($code)
 {
     // TODO encode user id in the auth code? or otherwise do a reverse lookup
     // to avoid checking every user
     for ($offset = 0;; $offset += 10) {
         $users = \Idno\Entities\User::get(array(), array(), 10, $offset);
         if (empty($users)) {
             break;
         }
         foreach ($users as $user) {
             $indieauth_codes = $user->indieauth_codes;
             if (!empty($indieauth_codes) && isset($indieauth_codes[$code])) {
                 return array('user' => $user, 'data' => $indieauth_codes[$code]);
             }
         }
     }
     return array();
 }
示例#8
0
 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 (empty(\Idno\Core\site()->config()->open_registration)) {
         if (!($invitation = \Idno\Entities\Invitation::validate($email, $code))) {
             \Idno\Core\site()->session()->addMessage("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()->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, '/') && $password == $password2 && strlen($password) > 4) {
                 $user = new \Idno\Entities\User();
                 $user->email = $email;
                 $user->handle = strtolower(trim($handle));
                 // Trim the handle and set it to lowercase
                 $user->setPassword($password);
                 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()->open_registration = false;
                         \Idno\Core\site()->config()->from_email = $user->email;
                         \Idno\Core\site()->config()->save();
                     }
                 }
                 $user->save();
                 \Idno\Core\site()->triggerEvent('site/firstadmin', ['user' => $user]);
                 // Event hook for first admin
                 // Now we can remove the invitation
                 if ($invitation instanceof Invitation) {
                     $invitation->delete();
                     // Remove the invitation; it's no longer needed
                 }
             } else {
                 if (empty($handle)) {
                     \Idno\Core\site()->session()->addMessage("Please create a username.");
                 } else {
                     if (strlen($handle) > 32) {
                         \Idno\Core\site()->session()->addMessage("Your username is too long.");
                     } else {
                         if (substr_count($handle, '/')) {
                             \Idno\Core\site()->session()->addMessage("Usernames can't contain a slash ('/') character.");
                         } else {
                             if (!empty($handleuser)) {
                                 \Idno\Core\site()->session()->addMessage("Unfortunately, someone is already using that username. Please choose another.");
                             }
                         }
                     }
                 }
                 if (!empty($emailuser)) {
                     \Idno\Core\site()->session()->addMessage("Hey, it looks like there's already an account with that email address. Did you forget your login?");
                 }
                 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 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 some profile information?");
         \Idno\Core\site()->session()->logUserOn($user);
         if (empty($onboarding)) {
             $this->forward($user->getURL());
         } else {
             $this->forward(\Idno\Core\site()->config()->getURL() . 'begin/profile');
         }
     } else {
         \Idno\Core\site()->session()->addMessageAtStart("We couldn't register you.");
         $this->forward($_SERVER['HTTP_REFERER']);
     }
 }
示例#9
0
 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');
         }
     } else {
         \Idno\Core\site()->session()->addMessageAtStart("We couldn't register you.");
         $this->forward($_SERVER['HTTP_REFERER']);
     }
 }
示例#10
0
文件: Idno.php 项目: jirkadus/Known
 /**
  * Retrieves admins for this site
  * @return array
  */
 function getAdmins()
 {
     return User::get(['admin' => true], [], 9999);
 }
示例#11
0
 function getContent()
 {
     $query = $this->getInput('q');
     $offset = (int) $this->getInput('offset');
     $types = $this->getInput('types');
     $friendly_types = array();
     // Check for an empty site
     if (!\Idno\Entities\User::get()) {
         $this->forward(\Idno\Core\Idno::site()->config()->getURL() . 'begin/');
     }
     if (!empty($this->arguments[0])) {
         // If we're on the friendly content-specific URL
         if ($friendly_types = explode('/', $this->arguments[0])) {
             $friendly_types = array_filter($friendly_types);
             if (empty($friendly_types) && !empty($query)) {
                 $friendly_types = array('all');
             }
             $types = array();
             // Run through the URL parameters and set content types appropriately
             foreach ($friendly_types as $friendly_type) {
                 if ($friendly_type == 'all') {
                     $types = \Idno\Common\ContentType::getRegisteredClasses();
                     break;
                 }
                 if ($content_type_class = \Idno\Common\ContentType::categoryTitleToClass($friendly_type)) {
                     $types[] = $content_type_class;
                 }
             }
         }
     } else {
         // If user has content-specific preferences, do something with $friendly_types
         if (empty($query)) {
             $types = \Idno\Core\Idno::site()->config()->getHomepageContentTypes();
         }
     }
     $search = array();
     if (!empty($query)) {
         $search = \Idno\Core\Idno::site()->db()->createSearchArray($query);
     }
     if (empty($types)) {
         $types = \Idno\Common\ContentType::getRegisteredClasses();
     } else {
         if (!is_array($types)) {
             $types = array($types);
         }
         $types[] = '!Idno\\Entities\\ActivityStreamPost';
     }
     $count = \Idno\Entities\ActivityStreamPost::countFromX($types, array());
     $feed = \Idno\Entities\ActivityStreamPost::getFromX($types, $search, array(), \Idno\Core\Idno::site()->config()->items_per_page, $offset);
     if (\Idno\Core\Idno::site()->session()->isLoggedIn()) {
         $create = \Idno\Common\ContentType::getRegistered();
         // If we can't create an object of this type, hide from the button bar
         foreach ($create as $key => $obj) {
             if (!$obj->createable) {
                 unset($create[$key]);
             }
         }
     } else {
         $create = false;
     }
     if (!empty(\Idno\Core\Idno::site()->config()->description)) {
         $description = \Idno\Core\Idno::site()->config()->description;
     } else {
         $description = 'An independent social website, powered by Known.';
     }
     // If we have a feed, set our last modified flag to the time of the latest returned entry
     if (!empty($feed)) {
         if (is_array($feed)) {
             $feed = array_filter($feed);
             $this->setLastModifiedHeader(reset($feed)->updated);
         }
     }
     if (!empty(\Idno\Core\Idno::site()->config()->homepagetitle)) {
         $title = \Idno\Core\Idno::site()->config()->homepagetitle;
     } else {
         $title = \Idno\Core\Idno::site()->config()->title;
     }
     $t = \Idno\Core\Idno::site()->template();
     $t->__(array('title' => $title, 'description' => $description, 'content' => $friendly_types, 'body' => $t->__(array('items' => $feed, 'contentTypes' => $create, 'offset' => $offset, 'count' => $count, 'subject' => $query, 'content' => $friendly_types))->draw('pages/home')))->drawPage();
 }