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/'); }
/** * Sets the URL slug of this entity to the given non-empty string, modifying it * in the case where the slug is already taken, and returning the modified version * of the slug * @param string $slug * @param int $max_pieces The maximum number of words in the slug (default: 10) * @return bool|string */ function setSlugResilient($slug, $max_pieces = 10) { // UUID max length is 255 chars; slug length <= 255 - (base URL + year + slash) $max_chars = 245 - strlen(\Idno\Core\site()->config()->getDisplayURL()); $slug = $this->prepare_slug($slug, $max_pieces, $max_chars - 10); if (empty($slug)) { return false; } if ($this->setSlug($slug, $max_pieces, $max_chars - 10)) { return true; } // If we've got here, the slug exists, so we need to create a new version $slug_extension = 1; while (!($modified_slug = $this->setSlug($slug . '-' . $slug_extension, $max_pieces * 2, $max_chars))) { $slug_extension++; } return $modified_slug; }