17 require_once SQ_CORE_PACKAGE_PATH.
'/page/page.inc';
18 require_once SQ_FUDGE_PATH.
'/general/text.inc';
19 require_once SQ_LIB_PATH.
'/html_form/html_form.inc';
42 var $default_state =
'request';
55 $this->_ser_attrs = TRUE;
56 parent::__construct($assetid);
79 $val[
'subject'] = translate(
'cms_password_reset_email_subject');
80 $val[
'text_format'] = translate(
'cms_password_reset_email_msg',
'%asset_attribute_username%',
'%password_reset_url%');
81 $val[
'html_format'] =
'<p>'.translate(
'cms_password_reset_email_msg',
'%asset_attribute_username%',
'<a href="%password_reset_url%">%password_reset_url%</a>').
'</p>';
82 $val[
'from'] = SQ_CONF_SYSTEM_NAME.
' <'.SQ_CONF_DEFAULT_EMAIL.
'>';
83 $this->setAttrVAlue(
'request_email_format', $val);
85 return parent::create($link);
100 if (!parent::_createAdditional($link))
return FALSE;
103 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset(
'user_group');
104 $group_link = Array(
'asset' => &$this,
'link_type' => SQ_LINK_TYPE_2,
'is_dependant' => 1,
'is_exclusive' => 1,
'value' =>
'pending_accounts');
108 $group->setAttrValue(
'name', translate(
'cms_password_reset_pending_group'));
109 if (!$group->create($group_link))
return FALSE;
110 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($group);
113 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset(
'bodycopy');
114 $copy_link = Array(
'asset' => &$this,
'link_type' => SQ_LINK_TYPE_2,
'is_dependant' => 1,
'is_exclusive' => 1,
'value' =>
'');
118 $copy_link[
'value'] = $value;
120 $bodycopy->setAttrValue(
'name', $details[
'name']);
121 unset($details[
'name']);
122 if (!$bodycopy->create($copy_link, $details)) {
125 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($bodycopy);
141 $allowed_links = parent::_getAllowedLinks();
143 $allowed_links[SQ_LINK_TYPE_2][
'bodycopy'] = Array(
'card' => count($this->
_getBodycopies()),
'exclusive' => TRUE);
144 $allowed_links[SQ_LINK_TYPE_2][
'user_group'] = Array(
'card' =>
'1',
'exclusive' => TRUE);
146 return $allowed_links;
161 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
163 $password_reset_action = $this->default_state;
164 if (isset($_REQUEST[
'action'])) {
165 $password_reset_action = $_REQUEST[
'action'];
169 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
186 if (!isset($vars[
'keywords']))
return;
189 $parents = $GLOBALS[
'SQ_SYSTEM']->am->getParents($broadcaster->id,
'bodycopy', TRUE);
190 $type_links = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($this->
id, SQ_LINK_TYPE_2,
'bodycopy');
191 foreach ($type_links as $link_info) {
192 if (isset($parents[$link_info[
'minorid']])) {
193 $bodycopy_type = $link_info[
'value'];
198 if (!isset($bodycopy_type) || empty($bodycopy_type)) {
201 if (!in_array($bodycopy_type, array_keys($this->
_getBodycopies()))) {
206 $tmp_type = strtr($bodycopy_type,
'_',
' ');
207 $tmp_type = ucwords($tmp_type);
208 $tmp_type = preg_replace(
'/\s+/',
'', $tmp_type);
209 $type_func =
'_get'.$tmp_type.
'Keywords';
211 if (method_exists($this, $type_func)) {
212 $vars[
'keywords'] = array_merge($vars[
'keywords'], $this->$type_func());
228 if (empty($action)) $action = $this->default_state;
231 $tmp_process = strtr($action,
'_',
' ');
232 $tmp_process = ucwords($tmp_process);
233 $tmp_process = preg_replace(
'/\s+/',
'', $tmp_process);
234 $process_func =
'_print'.$tmp_process.
'Action';
236 if (method_exists($this, $process_func)) {
237 return $this->$process_func();
255 $replacements[
'password_reset_error'] =
'';
274 $replacements = Array();
275 if (!isset($_POST[
'username']) || empty($_POST[
'username'])) {
276 $replacements[
'password_reset_error'] = translate(
'cms_password_reset_message_empty_username');
279 $username = $_POST[
'username'];
280 $auth_folder = $GLOBALS[
'SQ_SYSTEM']->am->getSystemAsset(
'authentication_folder');
281 if (is_null($auth_folder)) {
282 trigger_localised_error(
'SYS0249', E_USER_ERROR);
285 $auth_systems = $auth_folder->getAuthSystems();
288 foreach ($auth_systems as $systemid) {
289 $system = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($systemid);
290 if (is_null($system))
continue;
292 if (method_exists($system,
'locateUser')) {
293 $user = $system->locateUser($username);
294 if (!is_null($user) && $user->canLogin()) {
301 if (is_null($user)) {
304 if ($this->
attr(
'invalid_user_error')) {
305 $replacements[
'password_reset_error'] = translate(
'cms_password_reset_message_invalid_username');
310 foreach ($user->getAvailableKeywords() as $keyword => $description) {
311 $replacements[$keyword] = $user->getKeywordReplacement($keyword);
314 if (!$user_hash) $failure = TRUE;
320 $email_replacements = $replacements;
321 $email_replacements[
'password_reset_url'] = current_url().
'?action=reset&prid='.$user_hash;
323 $email_attr = $this->
getAttribute(
'request_email_format');
324 $email_value = unserialize($email_attr->value);
325 $email_value[
'to'][] = $user->attr(
'email');
326 $email_attr->value = serialize($email_value);
328 @$email_attr->sendMail($email_replacements);
350 $replacements = Array();
351 $replacements[
'password_reset_error'] =
'';
355 if (!isset($_REQUEST[
'prid']) || empty($_REQUEST[
'prid'])) {
356 $replacements[
'password_reset_error'] = translate(
'cms_password_reset_message_no_prid');
358 $prid = $_REQUEST[
'prid'];
360 if (empty($user_link)) {
361 $replacements[
'password_reset_error'] = translate(
'cms_password_reset_message_invalid_prid');
363 $userid = $user_link[
'minorid'];
364 $user = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($userid);
365 if (is_null($user)) {
366 $replacements[
'password_reset_error'] = translate(
'cms_password_reset_message_no_user');
368 foreach ($user->getAvailableKeywords() as $keyword => $description) {
369 $replacements[$keyword] = $user->getKeywordReplacement($keyword);
392 $replacements = Array();
393 $replacements[
'password_reset_error'] =
'';
397 if (!isset($_POST[
'password']) || empty($_POST[
'password'])) {
398 $replacements[
'password_reset_error'] = translate(
'cms_password_reset_message_empty_password');
399 }
else if (!isset($_REQUEST[
'prid']) || empty($_REQUEST[
'prid'])) {
400 $replacements[
'password_reset_error'] = translate(
'cms_password_reset_message_no_prid');
402 $password_parts = array_unique($_POST[
'password']);
404 $prid = $_REQUEST[
'prid'];
406 if (empty($user_link)) {
407 $replacements[
'password_reset_error'] = translate(
'cms_password_reset_message_invalid_prid');
409 $userid = $user_link[
'minorid'];
410 $user = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($userid);
411 if (is_null($user)) {
412 $replacements[
'password_reset_error'] = translate(
'cms_password_reset_message_no_user');
414 foreach ($user->getAvailableKeywords() as $keyword => $description) {
415 $replacements[$keyword] = $user->getKeywordReplacement($keyword);
420 if (count($password_parts) == 1) {
423 $action =
'reset_receipt';
425 $replacements[
'password_reset_error'] = translate(
'cms_password_reset_message_generic_password_error');
428 $replacements[
'password_reset_error'] = translate(
'cms_password_reset_message_different_passwords');
435 hidden_field(
'prid', $prid);
436 $field = ob_get_clean();
455 $replacements = Array();
459 $keywords = $bodycopy->getKeywords();
461 foreach ($keywords as $keyword) {
462 if (!in_array($keyword, array_keys($new_replacements))) {
465 $replacements[$keyword] = $new_replacements[$keyword];
468 $bodycopy->setKeywordReplacements($replacements);
469 $bodycopy->printBody();
473 if (in_array($action, Array(
'request',
'reset'))) {
474 return $this->
_buildForm(ob_get_clean(), $action.
'_receipt');
476 return ob_get_clean();
496 ?><form
id=
"<?php echo $this->getPrefix() ?>_<?php echo $action; ?>_form" method=
"post" action=
"<?php echo htmlentities(replace_query_string_vars(Array())); ?>" enctype=
"multipart/form-data">
497 <?php echo hidden_field(
'action', $action); ?>
498 <?php echo $body_contents; ?>
500 return ob_get_clean();
516 $GLOBALS[
'SQ_SYSTEM']->setRunLevel(SQ_RUN_LEVEL_FORCED);
517 $result = @$user->setAttrValue(
'password', $new_password);
520 $user->saveAttributes();
523 if ($parentid == 0)
return FALSE;
525 $parent = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($parentid,
'user_group');
526 if (is_null($parent))
return FALSE;
529 $links = $GLOBALS[
'SQ_SYSTEM']->am->getLinkByAsset($parentid, $user->id, SQ_LINK_TYPE_1, NULL,
'major', TRUE);
530 foreach ($links as $link) {
531 $parent->deleteLink($link[
'linkid']);
534 $GLOBALS[
'SQ_SYSTEM']->restoreRunLevel();
537 $GLOBALS[
'SQ_SYSTEM']->loginUser($user);
557 if (empty($assetid))
return FALSE;
560 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid);
561 if (is_null($asset))
return FALSE;
564 if ($parentid == 0)
return FALSE;
567 $parent = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($parentid,
'user_group');
568 if (is_null($parent))
return FALSE;
570 $GLOBALS[
'SQ_SYSTEM']->setRunLevel(SQ_RUN_LEVEL_FORCED);
571 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
574 $links = $GLOBALS[
'SQ_SYSTEM']->am->getLinkByAsset($parent->id, $assetid, SQ_LINK_TYPE_1, NULL,
'major', TRUE);
575 foreach ($links as $link) {
576 $GLOBALS[
'SQ_SYSTEM']->am->deleteAssetLink($link[
'linkid']);
579 $hash_value = MD5(implode(
'::', Array($this->
id, $asset->id, $asset->name, (time() * rand()))));
581 $return_value = FALSE;
582 if ($parent->createLink($asset, SQ_LINK_TYPE_1, $hash_value)) {
583 $return_value = $hash_value;
586 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
587 $GLOBALS[
'SQ_SYSTEM']->restoreRunLevel();
590 return $return_value;
608 if (empty($value))
return Array();
611 if ($parentid == 0)
return FALSE;
615 return $GLOBALS[
'SQ_SYSTEM']->am->getLink($parentid, SQ_LINK_TYPE_1,
'', FALSE, $value);
630 $keywords[
'submit_button'] =
'The submit button';
631 $keywords[
'password_reset_error'] =
'Error messages';
648 $keywords[
'username_input'] =
'The input field for username';
680 $keywords[
'password_input'] =
'The input fields for password reset (new and confirmation password input fields)';
681 $keywords[
'password_new'] =
'Input field for the new password';
682 $keywords[
'password_confirmation'] =
'Input field for the Confirmation of the new password';
713 if (isset($_POST[
'username'])) {
714 $value = $_POST[
'username'];
718 text_box(
'username',
'');
719 return ob_get_clean();
733 password_box(
'password[]');
734 password_box(
'password[]');
735 return ob_get_clean();
749 password_box(
'password[]');
750 return ob_get_clean();
764 password_box(
'password[]');
765 return ob_get_clean();
779 submit_button(
'', translate(
'submit'));
780 return ob_get_clean();
793 $link = $GLOBALS[
'SQ_SYSTEM']->am->getLink($this->
id, SQ_LINK_TYPE_2,
'user_group', FALSE,
'pending_accounts');
794 if (empty($link))
return 0;
796 return $link[
'minorid'];
813 $bodycopy_data = $GLOBALS[
'SQ_SYSTEM']->am->getLink($this->
id, SQ_LINK_TYPE_2,
'bodycopy', TRUE, $link_value,
'major',
'1');
814 if (empty($bodycopy_data)) $null;
816 $bodycopy = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($bodycopy_data[
'minorid'], $bodycopy_data[
'minor_type_code']);
817 if (is_null($bodycopy)) $null;
833 $res[
'request'][
'name'] = translate(
'cms_password_reset_request');
834 $res[
'request'][
'content'] =
'<p>%password_reset_error%</p><p>'.translate(
'cms_password_reset_request_msg').
'</p><p>%username_input% %submit_button% </p>';
836 $res[
'request_receipt'][
'name'] = translate(
'cms_password_reset_request_receipt');
837 $res[
'request_receipt'][
'content'] =
'<p>'.translate(
'cms_password_reset_request_receipt_msg').
'</p>';
839 $res[
'reset'][
'name'] = translate(
'cms_password_reset_reset');
840 $res[
'reset'][
'content'] =
'<p>%password_reset_error%</p><p>'.translate(
'cms_password_reset_reset_msg').
'</p><p>%password_input% %submit_button%</p>';
842 $res[
'reset_receipt'][
'name'] = translate(
'cms_password_reset_reset_receipt');
843 $res[
'reset_receipt'][
'content'] =
'<p>'.translate(
'cms_password_reset_reset_receipt_msg').
'</p>';