A Qcodo based CMS/ecommerce framework
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

161 lines
5.7 KiB

12 years ago
  1. <?php
  2. if(!defined('QUASICMS') ) die("No quasi.");
  3. if (!defined("ACCOUNTPASSWORDEDITPANEL.CLASS.PHP")){
  4. define("ACCOUNTPASSWORDEDITPANEL.CLASS.PHP",1);
  5. /**
  6. * AccountPasswordEditPanel provides a panel in which the user may
  7. * change their password and username.
  8. *
  9. *@author Erik Winn <erikwinnmail@yahoo.com>
  10. *
  11. *
  12. * $Id: AccountPasswordEditPanel.class.php 286 2008-10-10 23:33:36Z erikwinn $
  13. *@version 0.1
  14. *
  15. *@copyright (C) 2008 by Erik Winn
  16. *@license GPL v.2
  17. This program is free software; you can redistribute it and/or modify
  18. it under the terms of the GNU General Public License as published by
  19. the Free Software Foundation; either version 2 of the License, or
  20. (at your option) any later version.
  21. This program is distributed in the hope that it will be useful,
  22. but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. GNU General Public License for more details.
  25. You should have received a copy of the GNU General Public License
  26. along with this program; if not, write to the Free Software
  27. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA
  28. *
  29. * @package Quasi
  30. * @subpackage Classes
  31. */
  32. class AccountPasswordEditPanel extends QPanel
  33. {
  34. // Local instance of the AccountMetaControl
  35. protected $objAccount;
  36. protected $objControlBlock;
  37. // Controls for Account's Data Fields
  38. public $txtUsername;
  39. public $txtPassword;
  40. public $txtPassword2;
  41. // Buttons
  42. public $btnSave;
  43. public $btnCancel;
  44. // Callback
  45. protected $strClosePanelMethod;
  46. public function __construct($objParentObject,
  47. $objControlBlock,
  48. $strClosePanelMethod,
  49. $intId = null,
  50. $strControlId = null)
  51. {
  52. try {
  53. parent::__construct($objParentObject, $strControlId);
  54. } catch (QCallerException $objExc) {
  55. $objExc->IncrementOffset();
  56. throw $objExc;
  57. }
  58. $this->objControlBlock = $objControlBlock;
  59. $this->objAccount =& IndexPage::$objAccount;
  60. $this->strTemplate = __QUASI_CORE_TEMPLATES__ . '/AccountPasswordEditPanel.tpl.php';
  61. $this->strClosePanelMethod = $strClosePanelMethod;
  62. $this->txtUsername = new QTextBox($this, 'username');
  63. $this->txtUsername->Text = $this->objAccount->Username;
  64. $this->txtUsername->Required = true;
  65. $this->txtUsername->MaxLength = Account::UsernameMaxLength;
  66. $this->txtUsername->Name = QApplication::Translate('Login Name');
  67. $this->txtPassword = new QTextBox($this, 'password');
  68. $this->txtPassword->TextMode = QTextMode::Password;
  69. $this->txtPassword->Name = QApplication::Translate('New Password');
  70. $this->txtPassword->Required = true;
  71. $this->txtPassword2 = new QTextBox($this, 'password2');
  72. $this->txtPassword2->TextMode = QTextMode::Password;
  73. $this->txtPassword2->Name = QApplication::Translate('Confirm Password');
  74. $this->txtPassword2->Required = true;
  75. $this->btnSave = new QButton($this);
  76. $this->btnSave->Text = QApplication::Translate('Save');
  77. if(IndexPage::$blnAjaxOk)
  78. $this->btnSave->AddAction(new QClickEvent(), new QAjaxControlAction($this, 'btnSave_Click'));
  79. else
  80. $this->btnSave->AddAction(new QClickEvent(), new QServerControlAction($this, 'btnSave_Click'));
  81. $this->btnSave->CausesValidation = $this;
  82. $this->btnCancel = new QButton($this);
  83. $this->btnCancel->Text = QApplication::Translate('Cancel');
  84. if(IndexPage::$blnAjaxOk)
  85. $this->btnCancel->AddAction(new QClickEvent(), new QAjaxControlAction($this, 'btnCancel_Click'));
  86. else
  87. $this->btnCancel->AddAction(new QClickEvent(), new QServerControlAction($this, 'btnCancel_Click'));
  88. }
  89. public function Validate()
  90. {
  91. $blnToReturn = true;
  92. if($this->txtPassword->Text !== $this->txtPassword2->Text )
  93. {
  94. $this->txtPassword->Warning = 'Passwords do not match!';
  95. $blnToReturn = false;
  96. }
  97. return $blnToReturn;
  98. }
  99. public function btnSave_Click($strFormId, $strControlId, $strParameter)
  100. {
  101. $this->objAccount->Username = $this->txtUsername->Text;
  102. //paranoid about PHP array/object handling now .. assign first, _then manipulate.
  103. $strPassword = $this->txtPassword->Text;
  104. $this->objAccount->Password = sha1($strPassword);
  105. $this->objAccount->OnetimePassword = false;
  106. $this->objAccount->ValidPassword = true;
  107. $this->objAccount->Save();
  108. $this->CloseSelf(true);
  109. }
  110. public function btnCancel_Click($strFormId, $strControlId, $strParameter)
  111. {
  112. $this->CloseSelf(false);
  113. }
  114. protected function CloseSelf($blnChangesMade)
  115. {
  116. $strMethod = $this->strClosePanelMethod;
  117. $this->objControlBlock->$strMethod($blnChangesMade);
  118. }
  119. public function __get($strName)
  120. {
  121. switch ($strName)
  122. {
  123. case 'Account':
  124. return $this->objAccount ;
  125. default:
  126. try {
  127. return parent::__get($strName);
  128. } catch (QCallerException $objExc) {
  129. $objExc->IncrementOffset();
  130. throw $objExc;
  131. }
  132. }
  133. }
  134. }//end class
  135. }//end define
  136. ?>