Example #1
0
 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/');
 }
Example #2
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();
                         }
                     }
                 }
             }
         }
     });
 }
Example #3
0
 function postContent()
 {
     $this->adminGatekeeper();
     // Flag that a site export has been requested
     \Idno\Core\site()->config->export_last_requested = time();
     \Idno\Core\site()->config->export_in_progress = 1;
     \Idno\Core\site()->config->save();
     $this->forward(\Idno\Core\site()->config()->getDisplayURL() . 'admin/export/', false);
     ignore_user_abort(true);
     // This is dangerous, but we need export to continue
     session_write_close();
     header('Connection: close');
     header('Content-length: ' . (string) ob_get_length());
     @ob_end_flush();
     // Return output to the browser
     @ob_end_clean();
     @flush();
     sleep(10);
     // Pause
     set_time_limit(0);
     // Eliminate time limit - this could take a while
     // Remove the previous export file
     if (!empty(\Idno\Core\site()->config()->export_file_id)) {
         if ($file = File::getByID(\Idno\Core\site()->config()->export_file_id)) {
             $file->remove();
             \Idno\Core\site()->config->export_file_id = false;
             \Idno\Core\site()->config->export_filename = false;
             \Idno\Core\site()->config->save();
         }
     }
     if ($path = Migration::createCompressedArchive()) {
         $filename = \Idno\Core\site()->config()->host . '.zip';
         /*                    header('Content-disposition: attachment;filename=' . $filename);
                               if ($fp = fopen($path, 'r')) {
                                   while ($content = fread($fp, 4096)) {
                                       echo $content;
                                   }
                               }
                               fclose($fp);*/
         if ($file = File::createFromFile($path, $filename)) {
             @unlink($path);
             \Idno\Core\site()->config->export_filename = $filename;
             \Idno\Core\site()->config->export_file_id = $file;
             \Idno\Core\site()->config->export_in_progress = 0;
             \Idno\Core\site()->config->save();
             $mail = new Email();
             $mail->setHTMLBodyFromTemplate('admin/export');
             $mail->addTo(\Idno\Core\site()->session()->currentUser()->email);
             $mail->setSubject("Your data export is ready");
             $mail->send();
         }
         exit;
     }
 }
Example #4
0
 /**
  * Saves this invitation and sends it to the appropriate email address
  * @param $email
  * @return bool|int
  */
 function sendToEmail($email)
 {
     if ($this->associateWithEmail($email)) {
         $this->save();
         $message = new Email();
         $message->addTo($email);
         $message->setSubject(\Idno\Core\site()->session()->currentUser()->getTitle() . " has invited you to join " . \Idno\Core\site()->config()->title . '!');
         $message->setHTMLBodyFromTemplate('account/invite', ['email' => $email, 'code' => $this->code, 'inviter' => \Idno\Core\site()->session()->currentUser()->getTitle()]);
         return $message->send();
     }
     return false;
 }
Example #5
0
 /**
  * Register user-related events
  */
 static function registerEvents()
 {
     // Hook to add user data to webfinger
     \Idno\Core\site()->addEventHook('webfinger', function (\Idno\Core\Event $event) {
         $eventdata = $event->data();
         $user = $eventdata['object'];
         $links = $event->response();
         if (empty($links)) {
             $links = array();
         }
         if ($user instanceof User) {
             $links = array(array('rel' => 'http://webfinger.net/rel/avatar', 'href' => $user->getIcon()), array('rel' => 'http://webfinger.net/rel/profile-page', 'href' => $user->getURL()));
         }
         $event->setResponse($links);
     });
     // Refresh session user whenever it is saved
     \Idno\Core\site()->addEventHook('saved', function (\Idno\Core\Event $event) {
         $eventdata = $event->data();
         $user = $eventdata['object'];
         if ($user instanceof User) {
             if ($currentUser = \Idno\Core\site()->session()->currentUser()) {
                 if ($user->getUUID() == $currentUser->getUUID()) {
                     \Idno\Core\site()->session()->refreshSessionUser($user);
                 }
             }
         }
     });
     // Email notifications
     \Idno\Core\site()->addEventHook('notify', function (\Idno\Core\Event $event) {
         $eventdata = $event->data();
         $user = $eventdata['user'];
         $eventdata = $event->data();
         if ($user instanceof User && ($context = $eventdata['context'])) {
             if (empty($user->notifications['email']) || $user->notifications['email'] == 'all' || $user->notifications['email'] == 'comment' && in_array($context, array('comment', 'reply'))) {
                 $eventdata = $event->data();
                 $vars = $eventdata['vars'];
                 if (empty($vars)) {
                     $vars = array();
                 }
                 $eventdata = $event->data();
                 $vars['object'] = $eventdata['object'];
                 if (filter_var($user->email, FILTER_VALIDATE_EMAIL)) {
                     $email = new Email();
                     $email->setSubject($eventdata['message']);
                     $email->setHTMLBodyFromTemplate($eventdata['message_template'], $vars);
                     $email->addTo($user->email);
                     $email->send();
                 }
             }
         }
     });
 }
Example #6
0
 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/');
 }
Example #7
0
 function postContent()
 {
     $this->reverseGatekeeper();
     $email_address = $this->getInput('email');
     if ($user = User::getByEmail($email_address)) {
         if ($auth_code = $user->addPasswordRecoveryCode()) {
             $user->save();
             // Save the recovery code to the user
             $t = clone \Idno\Core\site()->template();
             $t->setTemplateType('email');
             $email = new Email();
             $email->setSubject("Password reset");
             $email->addTo($user->email);
             $email->setHTMLBody($t->__(array('email' => $email_address, 'code' => $auth_code))->draw('account/password'));
             $email->send();
             $this->forward(\Idno\Core\site()->config()->getURL() . 'account/password/?sent=true');
         }
     }
     \Idno\Core\site()->session()->addErrorMessage("Oh no! We couldn't find an account associated with that email address.");
     $this->forward(\Idno\Core\site()->config()->getURL() . 'account/password');
 }
Example #8
0
 /**
  * Register user-related events
  */
 static function registerEvents()
 {
     // Hook to add user data to webfinger
     \Idno\Core\Idno::site()->addEventHook('webfinger', function (\Idno\Core\Event $event) {
         $eventdata = $event->data();
         $user = $eventdata['object'];
         $links = $event->response();
         if (empty($links)) {
             $links = array();
         }
         if ($user instanceof User) {
             $links = array(array('rel' => 'http://webfinger.net/rel/avatar', 'href' => $user->getIcon()), array('rel' => 'http://webfinger.net/rel/profile-page', 'href' => $user->getURL()));
         }
         $event->setResponse($links);
     });
     // Refresh session user whenever it is saved
     \Idno\Core\Idno::site()->addEventHook('saved', function (\Idno\Core\Event $event) {
         $eventdata = $event->data();
         $user = $eventdata['object'];
         if ($user instanceof User) {
             if ($currentUser = \Idno\Core\Idno::site()->session()->currentUser()) {
                 if ($user->getUUID() == $currentUser->getUUID()) {
                     \Idno\Core\Idno::site()->session()->refreshSessionUser($user);
                 }
             }
         }
     });
     // Email notifications
     \Idno\Core\Idno::site()->addEventHook('notify', function (\Idno\Core\Event $event) {
         $eventdata = $event->data();
         $user = $eventdata['user'];
         $notification = $eventdata['notification'];
         if ($user instanceof User && !defined('KNOWN_UNIT_TEST')) {
             if (empty($user->notifications['email']) || $user->notifications['email'] == 'all' || $user->notifications['email'] == 'comment' && in_array($notification->type, array('comment', 'reply'))) {
                 if (($obj = $notification->getObject()) && isset($obj['permalink'])) {
                     $permalink = $obj['permalink'];
                 }
                 if (empty($user->notifications['ignored_domains']) || empty($permalink) || !in_array(parse_url($permalink, PHP_URL_HOST), $user->notifications['ignored_domains'])) {
                     if (filter_var($user->email, FILTER_VALIDATE_EMAIL)) {
                         $vars = ['user' => $user, 'notification' => $notification];
                         $email = new Email();
                         $email->setSubject($notification->getMessage());
                         $email->setHTMLBodyFromTemplate($notification->getMessageTemplate(), $vars);
                         $email->setTextBodyFromTemplate($notification->getMessageTemplate(), $vars);
                         $email->addTo($user->email);
                         $email->send();
                     }
                 }
             }
         }
     });
 }