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/'); }
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/'); }