public function execute(CommandContext $context) { if (!UserStatus::isUser()) { PHPWS_Core::initModClass('hms', 'exception/PermissionException.php'); throw new PermissionException('You do not have permission to request a roommate.'); } $term = $context->get('term'); $requestee = $context->get('username'); $requestor = UserStatus::getUsername(); if (empty($term)) { throw new InvalidArgumentException('Term was not specified.'); } $err = CommandFactory::getCommand('ShowRequestRoommate'); $err->setTerm($term); if (empty($requestee)) { NQ::simple('hms', hms\NotificationView::WARNING, 'You did not enter a username.'); $err->redirect(); } if (!PHPWS_Text::isValidInput($requestee)) { NQ::simple('hms', hms\NotificationView::WARNING, 'You entered an invalid username. Please use letters and numbers only.'); $err->redirect(); } // Attempt to Create Roommate Request PHPWS_Core::initModClass('hms', 'HMS_Roommate.php'); $request = new HMS_Roommate(); try { $request->request($requestor, $requestee, $term); } catch (RoommateCompatibilityException $rre) { NQ::simple('hms', hms\NotificationView::WARNING, $rre->getMessage()); $err->redirect(); } $request->save(); $endTime = $request->calc_req_expiration_date(); $expirationMsg = " expires on " . date('m/d/Y h:i:s a', $endTime); HMS_Activity_Log::log_activity($requestee, ACTIVITY_REQUESTED_AS_ROOMMATE, $requestor, "{$requestor} requested {$requestee}" . $expirationMsg); HMS_Activity_Log::log_activity($requestor, ACTIVITY_REQUESTED_AS_ROOMMATE, $requestee, "{$requestor} requested {$requestee}" . $expirationMsg); // Email both parties PHPWS_Core::initModClass('hms', 'HMS_Email.php'); HMS_Email::send_request_emails($request); // Notify PHPWS_Core::initModClass('hms', 'StudentFactory.php'); $student = StudentFactory::getStudentByUsername($requestee, $term); $name = $student->getName(); $fname = $student->getFirstName(); NQ::simple('hms', hms\NotificationView::SUCCESS, "You have requested {$name} to be your roommate. {$fname} has been emailed, and will need to log into HMS and approve your roommate request."); $cmd = CommandFactory::getCommand('ShowStudentMenu'); $cmd->redirect(); }
public static function save_settings() { $message = null; PHPWS_Settings::set('rss', 'rssfeed', (int) $_POST['rssfeed']); if (!empty($_POST['editor'])) { if (PHPWS_Text::isValidInput($_POST['editor'], 'email')) { PHPWS_Settings::set('rss', 'editor', $_POST['editor']); } else { $message = dgettext('rss', 'Please check editor email format.'); } } else { PHPWS_Settings::set('rss', 'editor', ''); } if (!empty($_POST['webmaster'])) { if (PHPWS_Text::isValidInput($_POST['webmaster'], 'email')) { PHPWS_Settings::set('rss', 'webmaster', $_POST['webmaster']); } else { $message = dgettext('rss', 'Please check webmaster email format.'); } } else { PHPWS_Settings::set('rss', 'webmaster', ''); } if (!empty($_POST['copyright'])) { PHPWS_Settings::set('rss', 'copyright', strip_tags($_POST['copyright'])); } return $message; }
public function setEmailAddress($email_address) { if (empty($email_address)) { $this->email_address = null; return true; } if (!\PHPWS_Text::isValidInput($email_address, 'email')) { throw new \Exception('Improperly formatted email'); } $this->email_address = $email_address; }
private function postSettings() { if (!empty($_POST['login_link']) && preg_match('/[^\\w\\-\\?&=:+\\/]/', $_POST['login_link'])) { $this->errors['login_link'] = 'Login link had non-url characters'; } else { \PHPWS_Settings::set('properties', 'login_link', $_POST['login_link']); } if (!\PHPWS_Text::isValidInput($_POST['email'], 'email')) { $this->errors['email'] = 'Email address is empty or malformed.'; } else { \PHPWS_Settings::set('properties', 'email', $_POST['email']); } \PHPWS_Settings::set('properties', 'roommate_only', (int) isset($_POST['roommate_only'])); if (!isset($this->errors)) { \PHPWS_Settings::save('properties'); return true; } else { return false; } }
public function setEmail($email) { // Trim whitespace and make email address all lowercase $email = strtolower(trim($email)); if (!PHPWS_Text::isValidInput($email, 'email')) { return PHPWS_Error::get(USER_ERR_BAD_EMAIL, 'users', 'setEmail'); } $this->email = $email; if ($this->isDuplicateEmail()) { return PHPWS_Error::get(USER_ERR_DUP_EMAIL, 'users', 'setEmail'); } return true; }
public function postForgot(&$content) { if (empty($_POST['fg_username']) && empty($_POST['fg_email'])) { $content = dgettext('users', 'You must enter either a username or email address.'); return false; } if (!empty($_POST['fg_username'])) { $username = $_POST['fg_username']; if (preg_match('/\'|"/', html_entity_decode(strip_tags($username), ENT_QUOTES))) { $content = dgettext('users', 'User name not found. Check your spelling or enter an email address instead.'); return false; } $db = new PHPWS_DB('users'); $db->addWhere('username', strtolower($username)); $db->addColumn('email'); $db->addColumn('id'); $db->addColumn('deity'); $db->addColumn('authorize'); $user_search = $db->select('row'); if (PHPWS_Error::logIfError($user_search)) { $content = dgettext('users', 'User name not found. Check your spelling or enter an email address instead.'); return false; } elseif (empty($user_search)) { $content = dgettext('users', 'User name not found. Check your spelling or enter an email address instead.'); return false; } else { if ($user_search['deity'] && !ALLOW_DEITY_FORGET) { Security::log(dgettext('users', 'Forgotten password attempt made on a deity account.')); $content = dgettext('users', 'User name not found. Check your spelling or enter an email address instead.'); return false; } if ($user_search['authorize'] != 1) { $content = sprintf(dgettext('users', 'Sorry but your authorization is not checked on this site. Please contact %s for information on reseting your password.'), PHPWS_User::getUserSetting('site_contact')); return false; } if (PHPWS_Core::isPosted()) { $content = dgettext('users', 'Please check your email for a response.'); return true; } if (empty($user_search['email'])) { $content = dgettext('users', 'Your email address is missing from your account. Please contact the site administrators.'); PHPWS_Error::log(USER_ERR_NO_EMAIL, 'users', 'User_Action::postForgot'); return true; } if (User_Action::emailPasswordReset($user_search['id'], $user_search['email'])) { $content = dgettext('users', 'We have sent you an email to reset your password.'); return true; } else { $content = dgettext('users', 'We are currently unable to send out email reminders. Try again later.'); return true; } } } elseif (!empty($_POST['fg_email'])) { $email = $_POST['fg_email']; if (preg_match('/\'|"/', html_entity_decode(strip_tags($email), ENT_QUOTES))) { $content = dgettext('users', 'Email address not found. Please try again.'); return false; } if (!PHPWS_Text::isValidInput($email, 'email')) { $content = dgettext('users', 'Email address not found. Please try again.'); return false; } $db = new PHPWS_DB('users'); $db->addWhere('email', $email); $db->addColumn('username'); $user_search = $db->select('row'); if (PHPWS_Error::logIfError($user_search)) { $content = dgettext('users', 'Email address not found. Please try again.'); return false; } elseif (empty($user_search)) { $content = dgettext('users', 'Email address not found. Please try again.'); return false; } else { if (PHPWS_Core::isPosted()) { $content = dgettext('users', 'Please check your email for a response.'); return true; } if (User_Action::emailUsernameReminder($user_search['username'], $email)) { $content = dgettext('users', 'We have sent you an user name reminder. Please check your email and return to log in.'); return true; } else { $content = dgettext('users', 'We are currently unable to send out email reminders. Try again later.'); return true; } } } }
public function postSheet() { if (empty($_POST['title'])) { $errors[] = dgettext('signup', 'You must give this signup sheet a title.'); } else { $this->sheet->setTitle($_POST['title']); } if (empty($_POST['description'])) { $this->sheet->description = null; } else { $this->sheet->setDescription($_POST['description']); } if (empty($_POST['start_time'])) { $this->sheet->defaultStart(); } else { $this->sheet->start_time = strtotime($_POST['start_time']); if ($this->sheet->start_time < mktime(0, 0, 0, 1, 1, 1970)) { $this->sheet->defaultStart(); } } if (empty($_POST['contact_email'])) { $this->sheet->contact_email = null; } else { $this->sheet->contact_email = $_POST['contact_email']; if (!PHPWS_Text::isValidInput($this->sheet->contact_email, 'email')) { $errors[] = dgettext('signup', 'Contact email improperly formatted.'); } } if (empty($_POST['end_time'])) { $this->sheet->defaultEnd(); } else { $this->sheet->end_time = strtotime($_POST['end_time']); if ($this->sheet->end_time < mktime(0, 0, 0, 1, 1, 1970)) { $this->sheet->defaultEnd(); } } if (isset($_POST['multiple'])) { $this->sheet->multiple = 1; } else { $this->sheet->multiple = 0; } $this->sheet->setExtra1($_POST['extra1']); $this->sheet->setExtra2($_POST['extra2']); $this->sheet->setExtra3($_POST['extra3']); if (isset($errors)) { $this->message = implode('<br />', $errors); return false; } else { return true; } }