示例#1
0
 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');
 }
示例#2
0
文件: User.php 项目: hank/Known
 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: '******'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;
 }
示例#3
0
 function getActor()
 {
     if (is_string($this->actor)) {
         return User::getByUUID($this->actor);
     }
     return $this->actor;
 }
示例#4
0
 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;
 }
示例#5
0
 function postContent()
 {
     $this->createGatekeeper();
     $user = \Idno\Core\site()->session()->currentUser();
     if ($uuid = $this->getInput('uuid')) {
         if (!($new_user = \Idno\Entities\User::getByUUID($uuid)) && !($new_user = \Idno\Entities\User::getByProfileURL($uuid)) && !($new_user = \Idno\Entities\RemoteUser::getByUUID($uuid)) && !($new_user = \Idno\Entities\RemoteUser::getByProfileURL($uuid))) {
             // No user found, so create it if it's remote
             if (!\Idno\Entities\User::isLocalUUID($uuid)) {
                 \Idno\Core\site()->logging->log("Creating new remote user", LOGLEVEL_DEBUG);
                 $new_user = new \Idno\Entities\RemoteUser();
                 // Populate with data
                 $new_user->setTitle($this->getInput('name'));
                 $new_user->setHandle($this->getInput('nickname'));
                 $new_user->email = $this->getInput('email');
                 $new_user->setUrl($uuid);
                 if (!$new_user->save()) {
                     throw new \Exception("There was a problem saving the new remote user.");
                 }
             }
         } else {
             \Idno\Core\site()->logging->log("New user found as " . $new_user->uuid, LOGLEVEL_DEBUG);
         }
         if ($new_user) {
             \Idno\Core\site()->logging->log("Trying a follow", LOGLEVEL_DEBUG);
             if ($user->addFollowing($new_user)) {
                 \Idno\Core\site()->logging->log("User added to following", LOGLEVEL_DEBUG);
                 if ($user->save()) {
                     \Idno\Core\site()->logging->log("Following saved", LOGLEVEL_DEBUG);
                     \Idno\Core\site()->session()->addMessage("You are now following " . $new_user->getTitle());
                 }
             } else {
                 \Idno\Core\site()->logging->log('Could not follow user for some reason (probably already following)', LOGLEVEL_DEBUG);
             }
         } else {
             throw new \Exception('Sorry, that user doesn\'t exist!');
         }
     } else {
         throw new \Exception("No UUID, please try that again!");
     }
 }
示例#6
0
 /**
  * Retrieves a link that will allow the current user to log into the hub page at $endpoint
  *
  * @param $endpoint
  * @param $callback
  * @return bool|string
  */
 function getRemoteLink($endpoint, $callback)
 {
     $user = site()->session()->currentUser();
     $user = User::getByUUID($user->getUUID());
     site()->session()->refreshSessionUser($user);
     if ($this->userIsRegistered($user)) {
         if (!empty($user->hub_settings['token'])) {
             $time = time();
             $signature = hash_hmac('sha1', $user->hub_settings['token'] . $time, $user->hub_settings['secret']);
             return $this->server . $endpoint . '?token=' . urlencode($user->hub_settings['token']) . '&time=' . $time . '&signature=' . $signature . '&callback=' . urlencode($callback);
         }
     }
     return false;
 }
示例#7
0
文件: Session.php 项目: benwerd/Known
 /**
  * If we're logged in, refresh the current session user.
  */
 function refreshCurrentSessionuser()
 {
     if (!$this->currentUser() && !empty($_SESSION['user_uuid'])) {
         $this->user = User::getByUUID($_SESSION['user_uuid']);
     } else {
         if ($this->isLoggedIn()) {
             $user_uuid = $this->currentUserUUID();
             if ($user = User::getByUUID($user_uuid)) {
                 $this->refreshSessionUser($user);
             } else {
                 $this->logUserOff();
             }
         }
     }
 }
示例#8
0
 /**
  * Adds an annotation to the entity.
  * @param string $subtype Annotation subtype. 'comment' etc.
  * @param string $owner_name Name of the annotation's owner
  * @param string $owner_url Annotation owner's URL
  * @param string $owner_image Annotation owner's image, if one exists (include a blank string otherwise)
  * @param string $content Content of the annotation
  * @param string|null $annotation_url If included, the existing URL of this annotation
  * @param int $time The UNIX timestamp associated with this annotation (if set to 0, as is default, will be current time)
  * @param string $title The title associated with this annotation (blank by default)
  * @param bool $send_notification Should this call trigger a notifiation? (Default: yes)
  * @return bool Depending on success
  */
 function addAnnotation($subtype, $owner_name, $owner_url, $owner_image, $content, $annotation_url = null, $time = null, $title = '', $send_notification = true)
 {
     if (empty($subtype)) {
         return false;
     }
     if (empty($annotation_url)) {
         $annotation_url = $this->getURL() . '/annotations/' . md5(time() . $content);
         // Invent a URL for this annotation
     }
     $post_existed = false;
     if ($existing_annotations = $this->getAnnotations($subtype)) {
         foreach ($existing_annotations as $existing_local_url => $existing_annotation) {
             if ($existing_annotation['permalink'] == $annotation_url) {
                 $local_url = $existing_local_url;
                 $post_existed = true;
             }
         }
     }
     if (empty($local_url)) {
         $local_url = $this->getURL() . '/annotations/' . md5(time() . $content);
         // Invent a URL for this annotation if we don't have one already
     }
     if (empty($time)) {
         $time = time();
     } else {
         $time = (int) $time;
     }
     $annotation = array('permalink' => $annotation_url, 'owner_name' => $owner_name, 'owner_url' => $owner_url, 'owner_image' => $owner_image, 'content' => $content, 'time' => $time, 'title' => $title);
     $annotations = $this->annotations;
     if (empty($annotations)) {
         $annotations = array();
     }
     if (empty($annotations[$subtype])) {
         $annotations[$subtype] = array();
     }
     // Ask whether it's ok to save this annotation (allows filtering)
     if (!\Idno\Core\Idno::site()->triggerEvent('annotation/save', array('annotation' => $annotation, 'object' => $this))) {
         return false;
         // Something prevented the annotation from being saved.
     }
     $annotations[$subtype][$local_url] = $annotation;
     $this->annotations = $annotations;
     $this->save();
     \Idno\Core\Idno::site()->triggerEvent('annotation/add/' . $subtype, array('annotation' => $annotation, 'object' => $this));
     if ($recipients = $this->getAnnotationOwnerUUIDs(true)) {
         $recipients[] = $this->getOwnerID();
         $recipients = array_unique($recipients);
     } else {
         $recipients = array($this->getOwnerID());
     }
     if ($send_notification) {
         foreach ($recipients as $recipient_uuid) {
             if (Idno::site()->session()->isLoggedIn()) {
                 if ($recipient_uuid == Idno::site()->session()->currentUserUUID()) {
                     // Don't bother sending a notification to the user performing the action
                     // Note: for received webmentions, no user will ever be logged in, so this only applies to local comments
                     continue;
                 }
             }
             // Don't send a notification to the commenter
             if ($recipient_uuid === $owner_url) {
                 continue;
             }
             if ($recipient = User::getByUUID($recipient_uuid)) {
                 $send = true;
                 switch ($subtype) {
                     case 'mention':
                     case 'reply':
                         if ($recipient_uuid == $this->getOwnerID()) {
                             $subject = $owner_name . ' replied to your post!';
                         } else {
                             $subject = $owner_name . ' replied!';
                         }
                         $notification_template = 'content/notification/reply';
                         $context = 'reply';
                         break;
                     case 'like':
                         if ($recipient_uuid == $this->getOwnerID()) {
                             $subject = $owner_name . ' liked your post!';
                         } else {
                             $send = false;
                         }
                         $notification_template = 'content/notification/like';
                         $context = 'like';
                         break;
                     case 'share':
                         if ($recipient_uuid == $this->getOwnerID()) {
                             $subject = $owner_name . ' reshared your post!';
                         } else {
                             $send = false;
                         }
                         $notification_template = 'content/notification/share';
                         $context = 'share';
                         break;
                     case 'rsvp':
                         $subject = $owner_name . ' RSVPed!';
                         $notification_template = 'content/notification/rsvp';
                         $context = 'rsvp';
                         break;
                 }
                 if ($send == true && $post_existed == false) {
                     if (empty($subject)) {
                         $subject = '';
                     }
                     if (!empty($notification_template) && !empty($context) && $send_notification) {
                         $notif = new \Idno\Entities\Notification();
                         $notif->setOwner($recipient);
                         $notif->setMessage($subject);
                         $notif->setMessageTemplate($notification_template);
                         $notif->setActor($owner_url);
                         $notif->setVerb($context);
                         $notif->setObject($annotation);
                         $notif->setTarget($this);
                         $notif->save();
                         $recipient->notify($notif);
                     }
                 }
             }
         }
     }
     return true;
 }
示例#9
0
 /**
  * Can a specified user (either an explicitly specified user ID
  * or the currently logged-in user if this is left blank) edit
  * this entity?
  *
  * @param string $user_id
  * @return true|false
  */
 function canEdit($user_id = '')
 {
     if (!\Idno\Core\site()->session()->isLoggedOn()) {
         return false;
     }
     if (!\Idno\Core\site()->canWrite()) {
         return false;
     }
     if (empty($user_id)) {
         $user_id = \Idno\Core\site()->session()->currentUserUUID();
     }
     if ($user_id = \Idno\Core\site()->session()->currentUserUUID()) {
         $user = \Idno\Core\site()->session()->currentUser();
     } else {
         $user = User::getByUUID($user_id);
     }
     if ($user->isAdmin()) {
         return true;
     }
     if ($this->getOwnerID() == $user_id) {
         return true;
     }
     return \Idno\Core\site()->triggerEvent('canEdit', ['object' => $this, 'user_id' => $user_id], false);
 }
示例#10
0
 function postContent()
 {
     $this->createGatekeeper();
     $user = \Idno\Core\site()->session()->currentUser();
     if ($uuid = $this->getInput('uuid')) {
         if (!($new_user = \Idno\Entities\User::getByUUID($uuid)) && !($new_user = \Idno\Entities\User::getByProfileURL($uuid)) && !($new_user = \Idno\Entities\RemoteUser::getByUUID($uuid)) && !($new_user = \Idno\Entities\RemoteUser::getByProfileURL($uuid))) {
             // No user found, so create it if it's remote
             if (!\Idno\Entities\User::isLocalUUID($uuid)) {
                 \Idno\Core\site()->logging->log("Creating new remote user", LOGLEVEL_DEBUG);
                 $new_user = new \Idno\Entities\RemoteUser();
                 // Populate with data
                 $new_user->setTitle($this->getInput('name'));
                 $new_user->setHandle($this->getInput('nickname'));
                 $new_user->email = $this->getInput('email');
                 $new_user->setUrl($uuid);
                 // TODO: Get a profile URL - get it from passed photo variable, upload to local and treat as avatar.
                 if (!$new_user->save()) {
                     throw new \Exception("There was a problem saving the new remote user.");
                 }
             }
         } else {
             \Idno\Core\site()->logging->log("New user found as " . $new_user->uuid, LOGLEVEL_DEBUG);
         }
         if ($new_user) {
             \Idno\Core\site()->logging->log("Trying a follow", LOGLEVEL_DEBUG);
             if ($user->addFollowing($new_user)) {
                 \Idno\Core\site()->logging->log("User added to following", LOGLEVEL_DEBUG);
                 if ($user->save()) {
                     \Idno\Core\site()->logging->log("Following saved", LOGLEVEL_DEBUG);
                     // Ok, we've saved the new user, now, lets subscribe to their feeds
                     if ($feed = \Idno\Core\site()->reader()->getFeedObject($new_user->getURL())) {
                         \Idno\Core\site()->session()->addMessage("You are now following " . $new_user->getTitle() . ', would you like to subscribe to their feed?');
                         $this->forward(\Idno\Core\site()->config()->getURL() . 'following/confirm/?feed=' . urlencode($new_user->getURL()));
                     }
                     \Idno\Core\site()->session()->addMessage("You are now following " . $new_user->getTitle());
                 }
             } else {
                 \Idno\Core\site()->logging->log('Could not follow user for some reason (probably already following)', LOGLEVEL_DEBUG);
                 \Idno\Core\site()->session()->addErrorMessage('You\'re already following ' . $this->getInput('name'));
             }
         } else {
             throw new \Exception('Sorry, that user doesn\'t exist!');
         }
     } else {
         throw new \Exception("No UUID, please try that again!");
     }
 }
示例#11
0
文件: Idno.php 项目: jirkadus/Known
 /**
  * Can a specified user (either an explicitly specified user ID
  * or the currently logged-in user if this is left blank) publish
  * to the site?
  *
  * @param string $user_id
  * @return true|false
  */
 function canWrite($user_id = '')
 {
     if (!\Idno\Core\Idno::site()->session()->isLoggedOn()) {
         return false;
     }
     if (empty($user_id)) {
         $user_id = \Idno\Core\Idno::site()->session()->currentUserUUID();
     }
     if ($user = \Idno\Entities\User::getByUUID($user_id)) {
         // Remote users can't ever create anything :( - for now
         if ($user instanceof \Idno\Entities\RemoteUser) {
             return false;
         }
         // But local users can
         if ($user instanceof \Idno\Entities\User) {
             if (empty($user->read_only)) {
                 return true;
             }
         }
     }
     return false;
 }
示例#12
0
 /**
  * Refresh the user currently stored in the session
  * @param \Idno\Entities\User $user
  * @return \Idno\Entities\User
  */
 function refreshSessionUser(\Idno\Entities\User $user)
 {
     if ($user = User::getByUUID($user->getUUID())) {
         $_SESSION['user'] = $user;
         return $user;
     }
     return false;
 }
示例#13
0
文件: Session.php 项目: d6-9b/Known
 /**
  * If we're logged in, refresh the current session user.
  */
 function refreshCurrentSessionuser()
 {
     if (!$this->currentUser() && !empty($_SESSION['user_uuid'])) {
         if ($this->user = User::getByUUID($_SESSION['user_uuid'])) {
             if (\Idno\Core\Idno::site()->config()->emailIsBlocked($this->user->email)) {
                 $this->logUserOff();
             }
         }
     } else {
         if ($this->isLoggedIn()) {
             $user_uuid = $this->currentUserUUID();
             if ($user = User::getByUUID($user_uuid)) {
                 $this->refreshSessionUser($user);
             } else {
                 $this->logUserOff();
             }
         }
     }
 }
示例#14
0
 /**
  * Retrieve all posts as an RSS feed
  * @param bool|true $hide_private Should we hide private posts? Default: true.
  * @param string $user_uuid User UUID to export for. Default: all users.
  * @return bool|false|string
  */
 static function getExportRSS($hide_private = true, $user_uuid = '')
 {
     $types = \Idno\Common\ContentType::getRegisteredClasses();
     if ($hide_private) {
         $groups = ['PUBLIC'];
     } else {
         $groups = [];
     }
     if (!empty($user_uuid)) {
         $search = ['owner' => $user_uuid];
         if ($user = User::getByUUID($user_uuid)) {
             $title = $user->getTitle();
             $description = $user->getDescription();
             $base_url = $user_uuid;
         }
     } else {
         $search = [];
         $title = Idno::site()->config()->getTitle();
         $description = Idno::site()->config()->getDescription();
         $base_url = Idno::site()->config()->getDisplayURL();
     }
     if ($feed = \Idno\Common\Entity::getFromX($types, $search, array(), PHP_INT_MAX - 1, 0, $groups)) {
         $rss_theme = new Template();
         $rss_theme->setTemplateType('rss');
         return $rss_theme->__(array('title' => $title, 'description' => $description, 'body' => $rss_theme->__(array('items' => $feed, 'offset' => 0, 'count' => sizeof($feed), 'subject' => [], 'nocdata' => true, 'base_url' => $base_url))->draw('pages/home')))->drawPage(false);
     }
     return false;
 }
示例#15
0
 /**
  * Adds an annotation to the entity.
  * @param string $subtype Annotation subtype. 'comment' etc.
  * @param string $owner_name Name of the annotation's owner
  * @param string $owner_url Annotation owner's URL
  * @param string $owner_image Annotation owner's image, if one exists (include a blank string otherwise)
  * @param string $content Content of the annotation
  * @param string|null $annotation_url If included, the existing URL of this annotation
  * @param int $time The UNIX timestamp associated with this annotation (if set to 0, as is default, will be current time)
  * @param string $title The title associated with this annotation (blank by default)
  * @param bool $send_notification Should this call trigger a notifiation? (Default: yes)
  * @return bool Depending on success
  */
 function addAnnotation($subtype, $owner_name, $owner_url, $owner_image, $content, $annotation_url = null, $time = null, $title = '', $send_notification = true)
 {
     if (empty($subtype)) {
         return false;
     }
     if (empty($annotation_url)) {
         $annotation_url = $this->getURL() . '/annotations/' . md5(time() . $content);
         // Invent a URL for this annotation
     }
     $post_existed = false;
     if ($existing_annotations = $this->getAnnotations($subtype)) {
         foreach ($existing_annotations as $existing_local_url => $existing_annotation) {
             if ($existing_annotation['permalink'] == $annotation_url) {
                 $local_url = $existing_local_url;
                 $post_existed = true;
             }
         }
     }
     if (empty($local_url)) {
         $local_url = $this->getURL() . '/annotations/' . md5(time() . $content);
         // Invent a URL for this annotation if we don't have one already
     }
     if (empty($time)) {
         $time = time();
     } else {
         $time = (int) $time;
     }
     $annotation = array('permalink' => $annotation_url, 'owner_name' => $owner_name, 'owner_url' => $owner_url, 'owner_image' => $owner_image, 'content' => $content, 'time' => $time, 'title' => $title);
     $annotations = $this->annotations;
     if (empty($annotations)) {
         $annotations = array();
     }
     if (empty($annotations[$subtype])) {
         $annotations[$subtype] = array();
     }
     $annotations[$subtype][$local_url] = $annotation;
     $this->annotations = $annotations;
     $this->save();
     \Idno\Core\Idno::site()->triggerEvent('annotation/add/' . $subtype, array('annotation' => $annotation, 'object' => $this));
     if ($owners = $this->getAnnotationOwnerUUIDs(true)) {
         $owners[] = $this->getOwnerID();
         $owners = array_unique($owners);
     } else {
         $owners = array($this->getOwnerID());
     }
     if ($send_notification) {
         foreach ($owners as $owner_uuid) {
             if (Idno::site()->session()->isLoggedIn()) {
                 if ($owner_uuid == Idno::site()->session()->currentUserUUID()) {
                     // Don't bother sending a notification to the user performing the action
                     continue;
                 }
             }
             if ($owner = User::getByUUID($owner_uuid)) {
                 $send = true;
                 switch ($subtype) {
                     case 'mention':
                     case 'reply':
                         if ($owner_uuid == $this->getOwnerID()) {
                             $subject = $owner_name . ' replied to your post!';
                         } else {
                             $subject = $owner_name . ' replied!';
                         }
                         $notification_template = 'content/notification/reply';
                         $context = 'reply';
                         break;
                     case 'like':
                         if ($owner_uuid == $this->getOwnerID()) {
                             $subject = $owner_name . ' liked your post!';
                         } else {
                             $send = false;
                         }
                         $notification_template = 'content/notification/like';
                         $context = 'like';
                         break;
                     case 'share':
                         if ($owner_uuid == $this->getOwnerID()) {
                             $subject = $owner_name . ' reshared your post!';
                         } else {
                             $send = false;
                         }
                         $notification_template = 'content/notification/share';
                         $context = 'share';
                         break;
                     case 'rsvp':
                         $subject = $owner_name . ' RSVPed!';
                         $notification_template = 'content/notification/rsvp';
                         $context = 'rsvp';
                         break;
                 }
                 if ($send == true && $post_existed == false) {
                     if (empty($subject)) {
                         $subject = '';
                     }
                     if (!empty($notification_template) && !empty($context) && $send_notification) {
                         $owner->notify($subject, $notification_template, $annotation, $context, $this);
                     }
                 }
             }
         }
     }
     return true;
 }
示例#16
0
文件: Users.php 项目: emory/Known
 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);
                             if (empty($name)) {
                                 $name = $user->handle;
                             }
                             $user->setTitle($name);
                             $user->save();
                         } else {
                             if (empty($handle)) {
                                 \Idno\Core\site()->session()->addMessage("Please create a username.");
                             }
                             if (strlen($handle) > 32) {
                                 \Idno\Core\site()->session()->addMessage("Your username is too long.");
                             }
                             if (substr_count($handle, '/')) {
                                 \Idno\Core\site()->session()->addMessage("Usernames can't contain a slash ('/') character.");
                             }
                             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?");
                             }
                         }
                     } 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("User " . $user->getHandle() . " was created. You may wish to email them to let them know.");
             } else {
                 \Idno\Core\site()->session()->addMessageAtStart("We couldn't register that user.");
             }
             break;
         case 'block_emails':
             $emails = $this->getInput('blocked_emails');
             preg_match_all('/[a-z\\d._%+-]+@[a-z\\d.-]+\\.[a-z]{2,4}\\b/i', $emails, $matches);
             $block_count = 0;
             if (!empty($matches[0])) {
                 if (is_array($matches[0])) {
                     foreach ($matches[0] as $email) {
                         if (\Idno\Core\site()->config()->addBlockedEmail($email)) {
                             $block_count++;
                         }
                     }
                     \Idno\Core\site()->config()->save();
                 }
             }
             if ($block_count > 1) {
                 \Idno\Core\site()->session()->addMessage("{$block_count} emails were blocked.");
             } else {
                 if ($block_count == 1) {
                     \Idno\Core\site()->session()->addMessage("The email address was blocked.");
                 } else {
                     \Idno\Core\site()->session()->addMessage("No email addresses were found.");
                 }
             }
             break;
         case 'unblock_emails':
             $emails = $this->getInput('blocked_emails');
             preg_match_all('/[a-z\\d._%+-]+@[a-z\\d.-]+\\.[a-z]{2,4}\\b/i', $emails, $matches);
             $block_count = 0;
             if (!empty($matches[0])) {
                 if (is_array($matches[0])) {
                     foreach ($matches[0] as $email) {
                         if (\Idno\Core\site()->config()->removeBlockedEmail($email)) {
                             $block_count++;
                         }
                     }
                     \Idno\Core\site()->config()->save();
                 }
             }
             if ($block_count > 1) {
                 \Idno\Core\site()->session()->addMessage("{$block_count} emails were unblocked.");
             } else {
                 if ($block_count == 1) {
                     \Idno\Core\site()->session()->addMessage("The email address was unblocked.");
                 } else {
                     \Idno\Core\site()->session()->addMessage("No email addresses were found.");
                 }
             }
             break;
     }
     $this->forward(\Idno\Core\site()->config()->getURL() . 'admin/users');
 }
示例#17
0
文件: Hub.php 项目: avewrigley/idno
 /**
  * Register the current user with the Known hub. The site must have been registered first.
  *
  * @param bool $user
  * @return bool
  */
 function registerUser($user = false)
 {
     if (empty($user)) {
         $user = site()->session()->currentUser();
     }
     if ($user instanceof User) {
         $user = User::getByUUID($user->getUUID());
         $web_client = new Webservice();
         $contents = json_encode($user);
         $time = time();
         $details = $this->loadDetails();
         $results = $web_client->post($this->server . 'hub/user/register', ['content' => $contents, 'time' => $time, 'auth_token' => $details['auth_token'], 'signature' => hash_hmac('sha1', $contents . $time . $details['auth_token'], $details['secret'])]);
         return true;
     }
     return false;
 }