/** * Register View for Event * * @return string */ private function register() { //create the view $view = $this->view('register', 'calendar'); //get request varse $eventId = Request::getVar('event_id', ''); //load event data $view->event = new \Components\Events\Models\Event($eventId); //get registrants count $eventsRespondent = new \Components\Events\Tables\Respondent(array('id' => $eventId)); $view->registrants = $eventsRespondent->getCount(); //do we have a registration deadline if ($view->event->get('registerby') == '' || $view->event->get('registerby') == '0000-00-00 00:00:00') { App::redirect(Route::url('index.php?option=' . $this->option . '&cn=' . $this->group->get('cn') . '&active=calendar&action=details&event_id=' . $view->event->get('id')), Lang::txt('This event does not have registration.'), 'warning'); return; } //make sure registration is open $now = Date::toUnix(); $registerby = Date::of($view->event->get('registerby'))->toUnix(); if ($registerby >= $now) { //get the password $password = Request::getVar('passwrd', '', 'post'); //is the event restricted if ($view->event->get('restricted') != '' && $view->event->get('restricted') != $password && !isset($this->register)) { //if we entered a password and it was bad lets tell the user if (isset($password) && $password != '') { $this->setError('The password entered is incorrect.'); } $view->setLayout('register_restricted'); } } else { $view->setLayout('register_closed'); } //push some vars to the view $view->month = $this->month; $view->year = $this->year; $view->group = $this->group; $view->option = $this->option; $view->authorized = $this->authorized; $view->user = $this->user; $view->register = isset($this->register) ? $this->register : null; $view->arrival = isset($this->arrival) ? $this->arrival : null; $view->departure = isset($this->departure) ? $this->departure : null; $view->dietary = isset($this->dietary) ? $this->dietary : null; $view->dinner = isset($this->dinner) ? $this->dinner : null; $view->disability = isset($this->disability) ? $this->disability : null; $view->race = isset($this->race) ? $this->race : null; //add params to view $view->params = new \Hubzero\Config\Registry($view->event->get('params')); if (!$this->user->get('guest')) { $profile = new \Hubzero\User\Profile(); $profile->load($this->user->get('id')); $view->register['first_name'] = $profile->get('givenName'); $view->register['last_name'] = $profile->get('surname'); $view->register['affiliation'] = $profile->get('organization'); $view->register['email'] = $profile->get('email'); $view->register['telephone'] = $profile->get('phone'); $view->register['website'] = $profile->get('url'); } //get any errors if there are any foreach ($this->getErrors() as $error) { $view->setError($error); } //load the view return $view->loadTemplate(); }
/** * Method is called after user data is stored in the database * * @param array $user holds the new user data * @param boolean $isnew true if a new user is stored * @param boolean $success true if user was succesfully stored in the database * @param string $msg message * @return void */ public function onAfterStoreUser($user, $isnew, $succes, $msg) { $xprofile = \Hubzero\User\Profile::getInstance($user['id']); if (!is_object($xprofile)) { $params = Component::params('com_members'); $hubHomeDir = rtrim($params->get('homedir'), '/'); if (empty($hubHomeDir)) { // try to deduce a viable home directory based on sitename or live_site $sitename = strtolower(Config::get('sitename')); $sitename = preg_replace('/^http[s]{0,1}:\\/\\//', '', $sitename, 1); $sitename = trim($sitename, '/ '); $sitename_e = explode('.', $sitename, 2); if (isset($sitename_e[1])) { $sitename = $sitename_e[0]; } if (!preg_match("/^[a-zA-Z]+[\\-_0-9a-zA-Z\\.]+\$/i", $sitename)) { $sitename = ''; } if (empty($sitename)) { $sitename = strtolower(Request::base()); $sitename = preg_replace('/^http[s]{0,1}:\\/\\//', '', $sitename, 1); $sitename = trim($sitename, '/ '); $sitename_e = explode('.', $sitename, 2); if (isset($sitename_e[1])) { $sitename = $sitename_e[0]; } if (!preg_match("/^[a-zA-Z]+[\\-_0-9a-zA-Z\\.]+\$/i", $sitename)) { $sitename = ''; } } $hubHomeDir = DS . 'home'; if (!empty($sitename)) { $hubHomeDir .= DS . $sitename; } if (!empty($hubHomeDir)) { $db = App::get('db'); $component = new JTableExtension($this->database); $component->load($component->find(array('element' => 'com_members', 'type' => 'component'))); $params = new \Hubzero\Config\Registry($component->params); $params->set('homedir', $hubHomeDir); $component->params = $params->toString(); $component->store(); } } $xprofile = new \Hubzero\User\Profile(); $xprofile->set('gidNumber', $params->get('gidNumber', '100')); $xprofile->set('gid', $params->get('gid', 'users')); $xprofile->set('uidNumber', $user['id']); $xprofile->set('homeDirectory', $hubHomeDir . DS . $user['username']); $xprofile->set('loginShell', '/bin/bash'); $xprofile->set('ftpShell', '/usr/lib/sftp-server'); $xprofile->set('name', $user['name']); $xprofile->set('email', $user['email']); $xprofile->set('emailConfirmed', '3'); $xprofile->set('username', $user['username']); $xprofile->set('regIP', $_SERVER['REMOTE_ADDR']); $xprofile->set('emailConfirmed', -rand(1, pow(2, 31) - 1)); $xprofile->set('public', $params->get('privacy', 0)); if (isset($_SERVER['REMOTE_HOST'])) { $xprofile->set('regHost', $_SERVER['REMOTE_HOST']); } $xprofile->set('registerDate', Date::toSql()); $result = $xprofile->create(); if (!$result) { return new Exception('Unable to create \\Hubzero\\User\\Profile record', 500); } } else { $update = false; $params = Component::params('com_members'); if ($xprofile->get('username') != $user['username']) { $xprofile->set('username', $user['username']); $update = true; } if ($xprofile->get('name') != $user['name']) { $xprofile->set('name', $user['name']); $update = true; } if ($xprofile->get('email') != $user['email']) { $xprofile->set('email', $user['email']); $xprofile->set('emailConfirmed', 0); $update = true; } if ($xprofile->get('emailConfirmed') == '') { $xprofile->set('emailConfirmed', '3'); $update = true; } if ($xprofile->get('gid') == '') { $xprofile->set('gid', $params->get('gid', 'users')); $update = true; } if ($xprofile->get('gidNumber') == '') { $xprofile->set('gidNumber', $params->get('gidNumber', '100')); $update = true; } if ($xprofile->get('loginShell') == '') { $xprofile->set('loginShell', '/bin/bash'); $update = true; } if ($xprofile->get('ftpShell') == '') { $xprofile->set('ftpShell', '/usr/lib/sftp-server'); // This isn't right, but we're using an empty shell as an indicator that we should also update default privacy $xprofile->set('public', $params->get('privacy', 0)); $update = true; } if ($update) { $xprofile->update(); } } // Check if quota exists for the user $params = Component::params('com_members'); if ($params->get('manage_quotas', false)) { require_once PATH_CORE . DS . 'components' . DS . 'com_members' . DS . 'tables' . DS . 'users_quotas.php'; require_once PATH_CORE . DS . 'components' . DS . 'com_members' . DS . 'tables' . DS . 'quotas_classes.php'; $quota = new \Components\Members\Tables\UsersQuotas($this->database); $quota->load(array('user_id' => $user['id'])); if (!$quota->id) { $class = new \Components\Members\Tables\QuotasClasses($this->database); $class->load(array('alias' => 'default')); if ($class->id) { $quota->set('user_id', $user['id']); $quota->set('class_id', $class->id); $quota->set('soft_blocks', $class->soft_blocks); $quota->set('hard_blocks', $class->hard_blocks); $quota->set('soft_files', $class->soft_files); $quota->set('hard_files', $class->hard_files); $quota->store(); } } } }
/** * Save one or more authors * * @param integer $show Display author list when done? * @param integer $id Resource ID * @param array $authorsNew Authors to add * @return void */ public function saveTask($show = 1, $id = 0, $authorsNew = array()) { // Incoming resource ID if (!$id) { $id = Request::getInt('pid', 0); } if (!$id) { $this->setError(Lang::txt('COM_TOOLS_CONTRIBUTE_NO_ID')); if ($show) { $this->displayTask($id); } return; } // Incoming authors $authid = Request::getInt('authid', 0, 'post'); $authorsNewstr = trim(Request::getVar('new_authors', '', 'post')); $role = Request::getVar('role', '', 'post'); // Turn the string into an array of usernames $authorsNew = empty($authorsNew) ? explode(',', $authorsNewstr) : $authorsNew; // Instantiate a resource/contributor association object $rc = new \Components\Resources\Tables\Contributor($this->database); $rc->subtable = 'resources'; $rc->subid = $id; // Get the last child in the ordering $order = $rc->getLastOrder($id, 'resources'); $order = $order + 1; // new items are always last // Was there an ID? (this will come from the author <select>) if ($authid) { // Check if they're already linked to this resource $rc->loadAssociation($authid, $id, 'resources'); if ($rc->authorid) { $this->setError(Lang::txt('USER_IS_ALREADY_AUTHOR', $authid)); } else { // Perform a check to see if they have a contributors page. If not, we'll need to make one $xprofile = new \Hubzero\User\Profile(); $xprofile->load($authid); if ($xprofile) { $this->_authorCheck($authid); // New record $rc->authorid = $authid; $rc->ordering = $order; $rc->name = addslashes($xprofile->get('name')); $rc->role = addslashes($role); $rc->organization = addslashes($xprofile->get('organization')); $rc->createAssociation(); $order++; } } } // Do we have new authors? if (!empty($authorsNew)) { jimport('joomla.user.helper'); // loop through each one for ($i = 0, $n = count($authorsNew); $i < $n; $i++) { $cid = trim($authorsNew[$i]); if (is_numeric($cid)) { $uid = intval($cid); } else { $cid = strtolower($cid); // Find the user's account info $uid = \JUserHelper::getUserId($cid); if (!$uid) { $this->setError(Lang::txt('COM_CONTRIBUTE_UNABLE_TO_FIND_USER_ACCOUNT', $cid)); continue; } } $user = User::getInstance($uid); if (!is_object($user)) { $this->setError(Lang::txt('COM_CONTRIBUTE_UNABLE_TO_FIND_USER_ACCOUNT', $cid)); continue; } $uid = $user->get('id'); if (!$uid) { $this->setError(Lang::txt('COM_CONTRIBUTE_UNABLE_TO_FIND_USER_ACCOUNT', $cid)); continue; } // Check if they're already linked to this resource $rcc = new \Components\Resources\Tables\Contributor($this->database); $rcc->loadAssociation($uid, $id, 'resources'); if ($rcc->authorid) { $this->setError(Lang::txt('USER_IS_ALREADY_AUTHOR', $cid)); continue; } $this->_authorCheck($uid); $xprofile = \Hubzero\User\Profile::getInstance($user->get('id')); $rcc->subtable = 'resources'; $rcc->subid = $id; $rcc->authorid = $uid; $rcc->ordering = $order; $rcc->name = $xprofile->get('name'); $rcc->role = $role; $rcc->organization = $xprofile->get('organization'); if (!$rcc->createAssociation()) { $this->setError($rcc->getError()); } $order++; } } if ($show) { // Push through to the authors view $this->displayTask($id); } }
/** * Processes the password set form * * @return void */ public function settingpasswordTask() { // Check for request forgeries Session::checkToken('post') or exit(Lang::txt('JINVALID_TOKEN')); // Get the token and user id from the verification process $token = User::getState('com_users.reset.token', null); $id = User::getState('com_users.reset.user', null); $no_html = Request::getInt('no_html', 0); // Check the token and user id if (empty($token) || empty($id)) { throw new Exception(Lang::txt('COM_MEMBERS_CREDENTIALS_ERROR_TOKENS_MISSING'), 403); } // Get the user object $user = \Hubzero\User\User::oneOrFail($id); // Check for a user and that the tokens match if ($user->tokens()->latest()->token !== $token) { App::redirect(Route::url('index.php?option=' . $this->_option . '&task=setpassword', false), Lang::txt('COM_MEMBERS_CREDENTIALS_ERROR_USER_NOT_FOUND'), 'warning'); return; } // Make sure the user isn't blocked if ($user->block) { App::redirect(Route::url('index.php?option=' . $this->_option . '&task=setpassword', false), Lang::txt('COM_MEMBERS_CREDENTIALS_ERROR_USER_NOT_FOUND'), 'warning'); return; } // Instantiate profile classs $profile = new \Hubzero\User\Profile(); $profile->load($id); if (\Hubzero\User\Helper::isXDomainUser($user->id)) { throw new Exception(Lang::txt('COM_MEMBERS_CREDENTIALS_ERROR_LINKED_ACCOUNT'), 403); } $password_rules = \Hubzero\Password\Rule::getRules(); $password1 = trim(Request::getVar('password1', null)); $password2 = trim(Request::getVar('password2', null)); if (!empty($password1)) { $msg = \Hubzero\Password\Rule::validate($password1, $password_rules, $profile->get('username')); } else { $msg = array(); } require_once dirname(dirname(__DIR__)) . DS . 'helpers' . DS . 'utility.php'; $error = false; $changing = true; if (!$password1 || !$password2) { $error = Lang::txt('COM_MEMBERS_CREDENTIALS_ERROR_PASSWORD_TWICE'); } elseif ($password1 != $password2) { $error = Lang::txt('COM_MEMBERS_CREDENTIALS_ERROR_PASSWORD_DONT_MATCH'); } elseif (!\Components\Members\Helpers\Utility::validpassword($password1)) { $error = Lang::txt('COM_MEMBERS_CREDENTIALS_ERROR_PASSWORD_INVALID'); } elseif (!empty($msg)) { $error = Lang::txt('COM_MEMBERS_CREDENTIALS_ERROR_PASSWORD_FAILS_REQUIREMENTS'); } // If we're resetting password to the current password, just return true // That way you can't reset the counter on your current password, or invalidate it by putting it into history if (\Hubzero\User\Password::passwordMatches($profile->get('uidNumber'), $password1)) { $error = false; $changing = false; $result = true; } if ($error) { if ($no_html) { $response = array('success' => false, 'message' => $error); echo json_encode($response); die; } else { App::redirect(Route::url('index.php?option=' . $this->_option . '&task=setpassword', false), $error, 'warning'); return; } } if ($changing) { // Encrypt the password and update the profile $result = \Hubzero\User\Password::changePassword($profile->get('username'), $password1); } // Save the changes if (!$result) { if ($no_html) { $response = array('success' => false, 'message' => Lang::txt('COM_MEMBERS_CREDENTIALS_ERROR_GENERIC')); echo json_encode($response); die; } else { App::redirect(Route::url('index.php?option=' . $this->_option . '&task=setpassword', false), Lang::txt('COM_MEMBERS_CREDENTIALS_ERROR_GENERIC'), 'warning'); return; } } // Flush the user data from the session User::setState('com_users.reset.token', null); User::setState('com_users.reset.user', null); if ($no_html) { $response = array('success' => true, 'redirect' => Route::url('index.php?option=com_users&view=login', false)); echo json_encode($response); die; } else { // Everything went well...go to the login page App::redirect(Route::url('index.php?option=com_users&view=login', false), Lang::txt('COM_MEMBERS_CREDENTIALS_PASSWORD_RESET_COMPLETE'), 'passed'); } }
<fieldset> <legend><?php echo Lang::txt('PLG_GROUPS_MEMBERS_ASSIGN_ROLE'); ?> </legend> <label for="uid"> <input type="hidden" name="uid" value="<?php echo $this->escape($this->uid); ?> " id="uid" /> <?php $u = new \Hubzero\User\Profile(); $u->load($this->uid); $current_roles = array(); $roles = $u->getGroupMemberRoles($u->get('uidNumber'), $this->group->get('gidNumber')); if ($roles) { foreach ($roles as $role) { $current_roles[] = $role['name']; } } ?> <strong><?php echo Lang::txt('PLG_GROUPS_MEMBERS_MEMBER'); ?> : </strong> <?php echo $this->escape($u->get('name')); ?> </label> <label for="roles">
/** * Change registered email * * @return void */ public function changeTask() { // Set the pathway $this->_buildPathway(); // Set the page title $this->_buildTitle(); // Check if the user is logged in if (User::isGuest()) { $return = base64_encode(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller . '&task=' . $this->_task, false, true)); App::redirect(Route::url('index.php?option=com_users&view=login&return=' . $return, false), Lang::txt('COM_MEMBERS_REGISTER_ERROR_LOGIN_TO_UPDATE'), 'warning'); return; } $xprofile = \Hubzero\User\Profile::getInstance(User::get('id')); $login = $xprofile->get('username'); $email = $xprofile->get('email'); $email_confirmed = $xprofile->get('emailConfirmed'); // Instantiate a new view $this->view->title = Lang::txt('COM_MEMBERS_REGISTER_CHANGE'); $this->view->login = $login; $this->view->email = $email; $this->view->email_confirmed = $email_confirmed; $this->view->success = false; // Incoming $return = urldecode(Request::getVar('return', '/')); $this->view->return = $return; // Check if a new email was submitted $pemail = Request::getVar('email', '', 'post'); $update = Request::getVar('update', '', 'post'); if ($update) { if (!$pemail) { $this->setError(Lang::txt('COM_MEMBERS_REGISTER_ERROR_INVALID_EMAIL')); } if ($pemail && \Components\Members\Helpers\Utility::validemail($pemail)) { // Check if the email address was actually changed if ($pemail == $email) { // Addresses are the same! Redirect App::redirect($return, '', 'message', true); } else { // New email submitted - attempt to save it $xprofile = \Hubzero\User\Profile::getInstance($login); if ($xprofile) { $dtmodify = Date::toSql(); $xprofile->set('email', $pemail); $xprofile->set('modifiedDate', $dtmodify); if ($xprofile->update()) { $user = User::getInstance($login); $user->set('email', $pemail); $user->save(); } else { $this->setError(Lang::txt('COM_MEMBERS_REGISTER_ERROR_UPDATING_ACCOUNT')); } } else { $this->setError(Lang::txt('COM_MEMBERS_REGISTER_ERROR_UPDATING_ACCOUNT')); } // Any errors returned? if (!$this->getError()) { // No errors // Attempt to send a new confirmation code $confirm = \Components\Members\Helpers\Utility::genemailconfirm(); $xprofile = new \Hubzero\User\Profile(); $xprofile->load($login); $xprofile->set('emailConfirmed', $confirm); $xprofile->update(); $subject = Config::get('sitename') . ' ' . Lang::txt('COM_MEMBERS_REGISTER_EMAIL_CONFIRMATION'); $eview = new \Hubzero\Mail\View(array('name' => 'emails', 'layout' => 'confirm')); $eview->option = $this->_option; $eview->controller = $this->_controller; $eview->sitename = Config::get('sitename'); $eview->login = $login; $eview->name = $xprofile->get('name'); $eview->registerDate = $xprofile->get('registerDate'); $eview->baseURL = $this->baseURL; $eview->confirm = $confirm; $msg = new \Hubzero\Mail\Message(); $msg->setSubject($subject)->addTo($pemail)->addFrom(Config::get('mailfrom'), Config::get('sitename') . ' Administrator')->addHeader('X-Component', $this->_option); $message = $eview->loadTemplate(false); $message = str_replace("\n", "\r\n", $message); $msg->addPart($message, 'text/plain'); $eview->setLayout('confirm_html'); $message = $eview->loadTemplate(); $message = str_replace("\n", "\r\n", $message); $msg->addPart($message, 'text/html'); if (!$msg->send()) { $this->setError(Lang::txt('COM_MEMBERS_REGISTER_ERROR_EMAILING_CONFIRMATION', $pemail)); } // Show the success form $this->view->success = true; } } } else { $this->setError(Lang::txt('COM_MEMBERS_REGISTER_ERROR_INVALID_EMAIL')); } } // Output the view if ($this->getError()) { $this->view->email = $pemail; $this->view->setError($this->getError()); } $this->view->display(); }
/** * Set local password * * @return void - redirect to members account page */ private function setlocalpass() { // Logged in? if ($this->user->get('guest')) { App::redirect(Route::url('index.php?option=com_users&view=login&return=' . base64_encode(Route::url('index.php?option=' . $this->option . '&task=myaccount&active=account&action=setlocalpass'))), Lang::txt('You must be a logged in to access this area.'), 'warning'); return; } // Get the token from the user state variable $token = User::getState($this->option . 'token'); // First check to make sure they're not trying to jump to this page without first verifying their token if (is_null($token)) { // Tsk tsk, no sneaky business App::redirect(Route::url('index.php?option=' . $this->option . '&id=' . $this->user->get('id') . '&active=account&task=sendtoken'), Lang::txt('You must first verify your email address by inputting the token.'), 'error'); return; } // Get the password input $password1 = Request::getVar('password1', null, 'post', 'string', JREQUEST_ALLOWRAW); $password2 = Request::getVar('password2', null, 'post', 'string', JREQUEST_ALLOWRAW); $change = Request::getVar('change', '', 'post'); // Create the view $view = new \Hubzero\Plugin\View(array('folder' => 'members', 'element' => 'account', 'name' => 'setlocalpassword', 'layout' => 'setlocalpass')); // Add a few more variables to the view $view->option = $this->option; $view->id = $this->user->get('id'); // Get the password rules $password_rules = \Hubzero\Password\Rule::getRules(); // Get the password rule descriptions $view->password_rules = array(); foreach ($password_rules as $rule) { if (!empty($rule['description'])) { $view->password_rules[] = $rule['description']; } } // Blank form request (no data submitted) if (empty($change)) { $view->notifications = $this->getPluginMessage() ? $this->getPluginMessage() : array(); return $view->loadTemplate(); } // Check for request forgeries Request::checkToken(); // Load some needed libraries jimport('joomla.user.helper'); // Initiate profile classs $profile = new \Hubzero\User\Profile(); $profile->load($this->user->get('id')); // Fire the onBeforeStoreUser trigger Event::trigger('user.onBeforeStoreUser', array($this->user->getProperties(), false)); // Validate the password against password rules if (!empty($password1)) { $msg = \Hubzero\Password\Rule::validate($password1, $password_rules, $profile->get('username')); } else { $msg = array(); } // Verify password $passrules = false; if (!$password1 || !$password2) { $this->setError(Lang::txt('MEMBERS_PASS_MUST_BE_ENTERED_TWICE')); } elseif ($password1 != $password2) { $this->setError(Lang::txt('MEMBERS_PASS_NEW_CONFIRMATION_MISMATCH')); } elseif (!empty($msg)) { $this->setError(Lang::txt('Password does not meet site password requirements. Please choose a password meeting all the requirements listed.')); $passrules = true; } // Were there any errors? if ($this->getError()) { $change = array(); $change['_missing']['password'] = $this->getError(); if (!empty($msg) && $passrules) { //$change = $msg; } if (Request::getInt('no_html', 0)) { echo json_encode($change); exit; } else { $view->setError($this->getError()); return $view->loadTemplate(); } } // No errors, so let's move on - encrypt the password and update the profile $result = \Hubzero\User\Password::changePassword($profile->get('uidNumber'), $password1); // Save the changes if (!$result) { $view->setError(Lang::txt('MEMBERS_PASS_CHANGE_FAILED')); return $view->loadTemplate(); } // Fire the onAfterStoreUser trigger Event::trigger('user.onAfterStoreUser', array($this->user->getProperties(), false, null, $this->getError())); // Flush the variables from the session User::setState($this->option . 'token', null); // Redirect if (Request::getInt('no_html', 0)) { echo json_encode(array("success" => true, "redirect" => Route::url($this->member->getLink() . '&active=account'))); exit; } else { // Redirect user to confirm view page App::redirect(Route::url($this->member->getLink() . '&active=account'), Lang::txt('Password reset successful'), 'passed'); } return; }
/** * @since 1.6 */ function processResetComplete($data) { // Get the form. $form = $this->getResetCompleteForm(); // Check for an error. if ($form instanceof Exception) { return $form; } // Filter and validate the form data. $data = $form->filter($data); $return = $form->validate($data); // Check for an error. if ($return instanceof Exception) { return $return; } // Check the validation results. if ($return === false) { // Get the validation messages from the form. foreach ($form->getErrors() as $message) { $this->setError($message); } return false; } // Get the token and user id from the confirmation process. $app = JFactory::getApplication(); $token = $app->getUserState('com_users.reset.token', null); $id = $app->getUserState('com_users.reset.user', null); // Check the token and user id. if (empty($token) || empty($id)) { return new Exception(Lang::txt('COM_USERS_RESET_COMPLETE_TOKENS_MISSING'), 403); } // Get the user object. $user = User::getInstance($id); // Check for a user and that the tokens match. if (empty($user) || $user->activation !== $token) { $this->setError(Lang::txt('COM_USERS_USER_NOT_FOUND')); return false; } // Make sure the user isn't blocked. if ($user->block) { $this->setError(Lang::txt('COM_USERS_USER_BLOCKED')); return false; } // Initiate profile classs $profile = new \Hubzero\User\Profile(); $profile->load($id); if (\Hubzero\User\Helper::isXDomainUser($user->get('id'))) { App::abort(403, Lang::txt('This is a linked account. To change your password you must change it using the procedures available where the account you are linked to is managed.')); return; } $password_rules = \Hubzero\Password\Rule::getRules(); $password1 = $data['password1']; $password2 = $data['password2']; if (!empty($password1)) { $msg = \Hubzero\Password\Rule::validate($password1, $password_rules, $profile->get('username')); } else { $msg = array(); } include_once PATH_CORE . DS . 'components' . DS . 'com_members' . DS . 'helpers' . DS . 'utility.php'; if (!$password1 || !$password2) { $this->setError(Lang::txt('you must enter your new password twice to ensure we have it correct')); } elseif ($password1 != $password2) { $this->setError(Lang::txt('the new password and confirmation you entered do not match. Please try again')); } elseif (!\Components\Members\Helpers\Utility::validpassword($password1)) { $this->setError(Lang::txt('the password you entered was invalid password. You may be using characters that are not allowed')); } elseif (!empty($msg)) { $this->setError(Lang::txt('the password does not meet site password requirements. Please choose a password meeting all the requirements listed below.')); } if ($this->getError()) { $this->setError($this->getError()); return false; } // Encrypt the password and update the profile $result = \Hubzero\User\Password::changePassword($profile->get('username'), $password1); // Save the changes if (!$result) { $this->setError(Lang::txt('There was an error changing your password.')); return false; } // Flush the user data from the session. $app->setUserState('com_users.reset.token', null); $app->setUserState('com_users.reset.user', null); return true; }
/** * Dashboard * * @return void */ public function dashboardTask() { // Login required if (User::isGuest()) { \Notify::warning(Lang::txt('COM_JOBS_PLEASE_LOGIN_ACCESS_EMPLOYER')); $this->login(); return; } // Incoming message $this->_msg_passed = $this->_msg_passed ? $this->_msg_passed : Request::getVar('msg', ''); $uid = Request::getInt('uid', User::get('id')); if ($uid && User::get('id') != $uid && !$this->_admin) { // not authorized App::abort(403, Lang::txt('ALERTNOTAUTH')); } $uid = $uid ? $uid : User::get('id'); $admin = $this->_admin && !$this->_emp && User::get('id') == $uid ? 1 : 0; // Make sure we have special admin subscription if ($admin) { $this->_authorizeEmployer(1); } // Get the member's info $profile = new \Hubzero\User\Profile(); $profile->load($uid); // load Employer $employer = new Employer($this->database); if (!$employer->loadEmployer($uid) && !$this->_admin) { // send to subscription page App::redirect(Route::url('index.php?option=com_jobs&task=subscribe')); return; } else { if ($admin) { $employer->id = 1; } else { if (!isset($employer->id)) { App::abort(404, Lang::txt('COM_JOBS_ERROR_EMPLOYER_NOT_FOUND')); } } } // do we have a subscription already? $subscription = new Subscription($this->database); if (!$subscription->load($employer->subscriptionid) && !$this->_admin) { // send to subscription page App::redirect(Route::url('index.php?option=com_jobs&task=subscribe')); return; } $service = new Service($this->database); if (!$service->loadService('', $subscription->serviceid) && !$this->_admin) { App::abort(404, Lang::txt('COM_JOBS_ERROR_SERVICE_NOT_FOUND')); } else { // get service params like maxads $this->_getServiceParams($service); } // Get current stats for dashboard $jobstats = new JobStats($this->database); $stats = $jobstats->getStats($uid, 'employer', $admin); // Get job postings $job = new Job($this->database); $myjobs = $job->get_my_openings($uid, 0, $admin); $activejobs = $job->countMyActiveOpenings($uid, 1, $admin); // Push some styles to the template $this->css(); // Push some scripts to the template $this->js(); // Set page title $this->_buildTitle(); // Set the pathway $this->_buildPathway(); // Output HTML $this->view->title = $this->_title; $this->view->config = $this->config; $this->view->admin = $this->_admin; $this->view->masterAdmin = $this->_masterAdmin; $this->view->emp = 1; $this->view->task = $this->_task; $this->view->option = $this->_option; $this->view->updated = 0; $this->view->myjobs = $myjobs; $this->view->activejobs = $activejobs; $this->view->subscription = $subscription; $this->view->employer = $employer; $this->view->service = $service; $this->view->login = $profile->get('username'); $this->view->uid = $uid; $this->view->stats = $stats; // Set any errors if ($this->getError()) { \Notify::error($this->getError()); } $this->view->setName('dashboard')->setLayout('default')->display(); }
/** * Display a form for registering for an event * * @return void */ public function eventregisterTask() { // Get some needed info $offset = $this->offset; $year = $this->year; $month = $this->month; $day = $this->day; $option = $this->_option; // Incoming $id = Request::getInt('id', 0, 'request'); // Ensure we have an ID if (!$id) { App::redirect(Route::url('index.php?option=' . $this->_option)); return; } // Load event $event = new Event($this->database); $event->load($id); // Ensure we have an event if (!$event->title || $event->registerby == '0000-00-00 00:00:00') { App::Redirect(Route::url('index.php?option=' . $this->_option)); return; } $auth = true; if ($this->config->getCfg('adminlevel')) { $auth = $this->_authorize(); } $bits = explode('-', $event->publish_up); $eyear = $bits[0]; $emonth = $bits[1]; $edbits = explode(' ', $bits[2]); $eday = $edbits[0]; // Set the page title Document::setTitle(Lang::txt(strtoupper($this->_name)) . ': ' . Lang::txt('EVENTS_REGISTER') . ': ' . stripslashes($event->title)); // Set the pathway if (Pathway::count() <= 0) { Pathway::append(Lang::txt(strtoupper($this->_name)), 'index.php?option=' . $this->_option); } Pathway::append($eyear, 'index.php?option=' . $this->_option . '&year=' . $eyear); Pathway::append($emonth, 'index.php?option=' . $this->_option . '&year=' . $eyear . '&month=' . $emonth); Pathway::append($eday, 'index.php?option=' . $this->_option . '&year=' . $eyear . '&month=' . $emonth . '&day=' . $eday); Pathway::append(stripslashes($event->title), 'index.php?option=' . $this->_option . '&task=details&id=' . $event->id); Pathway::append(Lang::txt('EVENTS_REGISTER'), 'index.php?option=' . $this->_option . '&task=details&id=' . $event->id . '&page=register'); $page = new Page($this->database); $page->alias = $this->_task; // Get the pages for this workshop $pages = $page->loadPages($event->id); // Check if registration is still open $registerby = strtotime($event->registerby); $now = time(); $register = array(); if (!User::isGuest()) { $profile = new \Hubzero\User\Profile(); $profile->load(User::get('id')); $register['firstname'] = $profile->get('givenName'); $register['lastname'] = $profile->get('surname'); $register['affiliation'] = $profile->get('organization'); $register['email'] = $profile->get('email'); $register['telephone'] = $profile->get('phone'); $register['website'] = $profile->get('url'); } // Is the registration open? if ($registerby >= $now) { // Is the registration restricted? if ($event->restricted) { $passwrd = Request::getVar('passwrd', '', 'post'); if ($event->restricted == $passwrd) { // Instantiate a view $this->view->setLayout('default'); $this->view->state = 'open'; } else { // Instantiate a view $this->view->setLayout('restricted'); $this->view->state = 'restricted'; } } else { // Instantiate a view $this->view->setLayout('default'); $this->view->state = 'open'; } } else { // Instantiate a view $this->view->setLayout('closed'); $this->view->state = 'closed'; } // Output HTML $this->view->setName('register'); $this->view->option = $this->_option; $this->view->title = Lang::txt(strtoupper($this->_name)) . ': ' . Lang::txt('EVENTS_REGISTER'); $this->view->task = $this->_task; $this->view->year = $year; $this->view->month = $month; $this->view->day = $day; $this->view->offset = $offset; $this->view->event = $event; $this->view->authorized = $auth; $this->view->page = $page; $this->view->pages = $pages; $this->view->register = $register; $this->view->arrival = null; $this->view->departure = null; foreach ($this->getErrors() as $error) { $this->view->setError($error); } $this->view->display(); }
/** * Method is called after user data is stored in the database * * @param array $user holds the new user data * @param boolean $isnew true if a new user is stored * @param boolean $success true if user was succesfully stored in the database * @param string $msg message * @return void */ public function onAfterStoreUser($user, $isnew, $success, $msg) { $xprofile = \Hubzero\User\Profile::getInstance($user['id']); if (!is_object($xprofile)) { $params = Component::params('com_members'); $hubHomeDir = rtrim($params->get('homedir'), '/'); if (empty($hubHomeDir)) { // try to deduce a viable home directory based on sitename or live_site $sitename = strtolower(Config::get('sitename')); $sitename = preg_replace('/^http[s]{0,1}:\\/\\//', '', $sitename, 1); $sitename = trim($sitename, '/ '); $sitename_e = explode('.', $sitename, 2); if (isset($sitename_e[1])) { $sitename = $sitename_e[0]; } if (!preg_match("/^[a-zA-Z]+[\\-_0-9a-zA-Z\\.]+\$/i", $sitename)) { $sitename = ''; } if (empty($sitename)) { $sitename = strtolower(Request::base()); $sitename = preg_replace('/^http[s]{0,1}:\\/\\//', '', $sitename, 1); $sitename = trim($sitename, '/ '); $sitename_e = explode('.', $sitename, 2); if (isset($sitename_e[1])) { $sitename = $sitename_e[0]; } if (!preg_match("/^[a-zA-Z]+[\\-_0-9a-zA-Z\\.]+\$/i", $sitename)) { $sitename = ''; } } $hubHomeDir = DS . 'home'; if (!empty($sitename)) { $hubHomeDir .= DS . $sitename; } if (!empty($hubHomeDir)) { $db = App::get('db'); $component = new JTableExtension($this->database); $component->load($component->find(array('element' => 'com_members', 'type' => 'component'))); $params = new \Hubzero\Config\Registry($component->params); $params->set('homedir', $hubHomeDir); $component->params = $params->toString(); $component->store(); } } $xprofile = new \Hubzero\User\Profile(); $xprofile->set('gidNumber', $params->get('gidNumber', '100')); $xprofile->set('gid', $params->get('gid', 'users')); $xprofile->set('uidNumber', $user['id']); $xprofile->set('homeDirectory', isset($user['homeDirectory']) ? $user['homeDirectory'] : $hubHomeDir . DS . $user['username']); $xprofile->set('loginShell', isset($user['loginShell']) ? $user['loginShell'] : '/bin/bash'); $xprofile->set('ftpShell', isset($user['ftpShell']) ? $user['ftpShell'] : '/usr/lib/sftp-server'); $xprofile->set('name', $user['name']); $xprofile->set('email', $user['email']); $xprofile->set('username', $user['username']); $xprofile->set('regIP', $_SERVER['REMOTE_ADDR']); //$xprofile->set('emailConfirmed', '3'); $xprofile->set('emailConfirmed', isset($user['activation']) ? $user['activation'] : -rand(1, pow(2, 31) - 1)); $xprofile->set('public', $params->get('privacy', 0)); if (isset($_SERVER['REMOTE_HOST'])) { $xprofile->set('regHost', $_SERVER['REMOTE_HOST']); } $xprofile->set('registerDate', Date::toSql()); $result = $xprofile->create(); if (!$result) { return new Exception('Unable to create \\Hubzero\\User\\Profile record', 500); } } else { $update = false; $params = Component::params('com_members'); if ($xprofile->get('username') != $user['username']) { $xprofile->set('username', $user['username']); $update = true; } if ($xprofile->get('name') != $user['name']) { $xprofile->set('name', $user['name']); $update = true; } // Fix missing surname/given name as well if ($xprofile->get('name') && (!$xprofile->get('surname') || !$xprofile->get('givenName'))) { $firstname = $xprofile->get('givenName'); $middlename = $xprofile->get('middleName'); $lastname = $xprofile->get('surname'); $words = array_map('trim', explode(' ', $xprofile->get('name'))); $count = count($words); if ($count == 1) { $firstname = $words[0]; } else { if ($count == 2) { $firstname = $words[0]; $lastname = $words[1]; } else { if ($count == 3) { $firstname = $words[0]; $middlename = $words[1]; $lastname = $words[2]; } else { $firstname = $words[0]; $lastname = $words[$count - 1]; $middlename = $words[1]; for ($i = 2; $i < $count - 1; $i++) { $middlename .= ' ' . $words[$i]; } } } } $firstname = trim($firstname); if ($firstname) { $xprofile->set('givenName', $firstname); } $middlename = trim($middlename); if ($middlename) { $xprofile->set('middleName', $middlename); } $lastname = trim($lastname); if ($lastname) { $xprofile->set('surname', $lastname); } $update = true; } if ($xprofile->get('email') != $user['email']) { $xprofile->set('email', $user['email']); $xprofile->set('emailConfirmed', 0); $update = true; } if ($xprofile->get('emailConfirmed') == '') { $xprofile->set('emailConfirmed', '3'); $update = true; } if ($xprofile->get('gid') == '') { $xprofile->set('gid', $params->get('gid', 'users')); $update = true; } if ($xprofile->get('gidNumber') == '') { $xprofile->set('gidNumber', $params->get('gidNumber', '100')); $update = true; } if ($xprofile->get('loginShell') == '') { $xprofile->set('loginShell', '/bin/bash'); $update = true; } if ($xprofile->get('ftpShell') == '') { $xprofile->set('ftpShell', '/usr/lib/sftp-server'); // This isn't right, but we're using an empty shell as an indicator that we should also update default privacy $xprofile->set('public', $params->get('privacy', 0)); $update = true; } if ($update) { $xprofile->update(); } } // Check if quota exists for the user $params = Component::params('com_members'); if ($params->get('manage_quotas', false)) { require_once PATH_CORE . DS . 'components' . DS . 'com_members' . DS . 'models' . DS . 'quota.php'; $quota = Components\Members\Models\Quota::all()->whereEquals('user_id', $user['id'])->row(); if (!$quota->get('id')) { $class = Components\Members\Models\Quota\Category::defaultEntry(); if ($class->get('id')) { $quota->set('user_id', $user['id']); $quota->set('class_id', $class->get('id')); $quota->set('soft_blocks', $class->get('soft_blocks')); $quota->set('hard_blocks', $class->get('hard_blocks')); $quota->set('soft_files', $class->get('soft_files')); $quota->set('hard_files', $class->get('hard_files')); $quota->save(); } } } if ($success) { Event::trigger('members.onMemberAfterSave', array($user, $isnew, $success, $msg)); } }
public function uploadcsvTask() { // Check for request forgeries Request::checkToken(); // See if we have a file $csvFile = Request::getVar('csvFile', false, 'files', 'array'); $sId = Request::getVar('sId', ''); if (isset($csvFile['name']) && $csvFile['name'] && $csvFile['type'] == 'text/csv') { if (($handle = fopen($csvFile['tmp_name'], "r")) !== FALSE) { $inserted = 0; $skipped = array(); $ignored = array(); while (($line = fgetcsv($handle, 1000, ",")) !== FALSE) { if (!empty($line[0])) { $usr = new \Hubzero\User\Profile(trim($line[0])); $uId = $usr->get('uidNumber'); if ($uId) { $res = RestrictionsHelper::addSkuUser($uId, $sId); if ($res) { $inserted++; } else { $skipped[] = $usr; } } else { $ignored[] = $line[0]; } } } fclose($handle); } else { $this->view->setError('Could not read the file.'); } } else { $this->view->setError('No file or bad file was uploaded. Please make sure you upload the CSV formated file.'); } // Output the HTML $this->view->sId = $sId; $this->view->inserted = $inserted; $this->view->skipped = $skipped; $this->view->ignored = $ignored; $this->view->display(); }
/** * Display host entries for a member * * @param object $profile \Hubzero\User\Profile * @return void */ public function displayTask($profile = null) { // Incoming if (!$profile) { $id = Request::getInt('id', 0, 'get'); $profile = new \Hubzero\User\Profile(); $profile->load($id); } // Get a list of all hosts $this->view->rows = $profile->get('host'); $this->view->id = $profile->get('uidNumber'); // Set any errors if ($this->getError()) { $this->view->setError($this->getError()); } // Output the HTML $this->view->setLayout('display')->display(); }