Source for file change_password.act.php

Documentation is available at change_password.act.php

  1. <?php
  2.  
  3. /**
  4. * @package polyphony.user
  5. *
  6. * @copyright Copyright &copy; 2005, Middlebury College
  7. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  8. *
  9. * @version $Id: change_password.act.php,v 1.6 2007/09/19 14:04:58 adamfranco Exp $
  10. */
  11.  
  12. require_once(POLYPHONY."/main/library/AbstractActions/MainWindowAction.class.php");
  13.  
  14. /**
  15. * This file will allow the user to change their HarmoniDB password.
  16. *
  17. * @since 10/24/05
  18. * @author Christopher W. Shubert
  19. *
  20. * @package polyphony.user
  21. *
  22. * @copyright Copyright &copy; 2005, Middlebury College
  23. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  24. *
  25. * @version $Id: change_password.act.php,v 1.6 2007/09/19 14:04:58 adamfranco Exp $
  26. */
  27. class change_passwordAction
  28. extends MainWindowAction
  29. {
  30. /**
  31. * Check Authorizations
  32. *
  33. * @return boolean
  34. * @access public
  35. * @since 4/26/05
  36. */
  37. function isAuthorizedToExecute () {
  38. $authN = Services::getService("AuthN");
  39. return $authN->isUserAuthenticated(new Type ("Authentication",
  40. "edu.middlebury.harmoni", "Harmoni DB"));
  41. }
  42. function getUnauthorizedMessage() {
  43. return _("You must be currently Authenticated under 'Harmoni DB'");
  44. }
  45. /**
  46. * Return the heading text for this action, or an empty string.
  47. *
  48. * @return string
  49. * @access public
  50. * @since 4/26/05
  51. */
  52. function getHeadingText () {
  53. return _("Change Your 'Harmoni DB' Password");
  54. }
  55. /**
  56. * Build the content for this action
  57. *
  58. * @return void
  59. * @access public
  60. * @since 4/26/05
  61. */
  62. function buildContent () {
  63. $authN = Services::getService("AuthN");
  64. $dbAuthType = new Type ("Authentication", "edu.middlebury.harmoni",
  65. "Harmoni DB");
  66. $centerPane =$this->getActionRows();
  67. $id =$authN->getUserId($dbAuthType);
  68. $cacheName = 'change_password_wizard_'.$id->getIdString();
  69. $this->runWizard($cacheName, $centerPane);
  70. }
  71. /**
  72. * creates the wizard
  73. *
  74. * @return object Wizard
  75. * @access public
  76. * @since 10/24/05
  77. */
  78. function createWizard() {
  79. $harmoni = Harmoni::Instance();
  80. $wizard = SimpleWizard::withText(
  81. "\n<h2>"._("Old Password")."</h2>".
  82. "\n<br \>[[old_password]]".
  83. "\n<h2>"._("New Password")."</h2>".
  84. "\n"._("Please enter your new password twice").
  85. "\n<br />[[new_password]]".
  86. "\n<br />[[n_p_again]]".
  87. "<table width='100%' border='0' style='margin-top:20px' >\n".
  88. "<tr>\n".
  89. "</td>\n".
  90. "<td align='left' width='50%'>\n".
  91. "[[_cancel]]".
  92. "<td align='right' width='50%'>\n".
  93. "[[_save]]".
  94. "</td></tr></table>");
  95. $error = $harmoni->request->get("error");
  96. if (!is_null($error))
  97. print $error;
  98. $pass =$wizard->addComponent("old_password", new WPasswordField());
  99. $pass =$wizard->addComponent("new_password", new WPasswordField());
  100. $pass =$wizard->addComponent("n_p_again", new WPasswordField());
  101. $save =$wizard->addComponent("_save",
  102. WSaveButton::withLabel("Change Password"));
  103. $cancel =$wizard->addComponent("_cancel", new WCancelButton());
  104.  
  105. return $wizard;
  106. }
  107. /**
  108. * Save our results. Tearing down and unsetting the Wizard is handled by
  109. * in {@link runWizard()} and does not need to be implemented here.
  110. *
  111. * @param string $cacheName
  112. * @return boolean TRUE if save was successful and tear-down/cleanup of the
  113. * Wizard should ensue.
  114. * @access public
  115. * @since 10/24/05
  116. */
  117. function saveWizard ($cacheName) {
  118. $harmoni = Harmoni::Instance();
  119. $authN = Services::getService("AuthN");
  120. $tokenM = Services::getService("AgentTokenMapping");
  121. $wizard =$this->getWizard($cacheName);
  122. $properties = $wizard->getAllValues();
  123. $dbAuthType = new Type ("Authentication", "edu.middlebury.harmoni",
  124. "Harmoni DB");
  125. $id =$authN->getUserId($dbAuthType);
  126. $it =$tokenM->getMappingsForAgentId($id);
  127.  
  128. while ($it->hasNext()) {
  129. $mapping =$it->next();
  130. if ($mapping->getAuthenticationType() == $dbAuthType)
  131. $tokens =$mapping->getTokens();
  132. }
  133. if (isset($tokens)) {
  134. $authNMethodManager = Services::getService("AuthNMethodManager");
  135. $dbAuthMethod =$authNMethodManager->getAuthNMethodForType($dbAuthType);
  136. $uname = $tokens->getUsername();
  137. // Validate the old password
  138. $oldTokens = $dbAuthMethod->createTokens(
  139. array( 'username' => $uname,
  140. 'password' => $properties['old_password']));
  141. if (!$dbAuthMethod->authenticateTokens($oldTokens)) {
  142. $error = "Invalid old password";
  143. $localizedError = _("Invalid old password, please try again.")."\n<br/>";
  144. }
  145. // Reset the password if old tokens are valid and new tokens are valid
  146. else if (($properties['new_password'] != '') &&
  147. ($properties['new_password'] == $properties['n_p_again'])) {
  148. // Log the action
  149. if (Services::serviceRunning("Logging")) {
  150. $loggingManager = Services::getService("Logging");
  151. $log =$loggingManager->getLogForWriting("Authentication");
  152. $formatType = new Type("logging", "edu.middlebury", "AgentsAndNodes",
  153. "A format in which the acting Agent[s] and the target nodes affected are specified.");
  154. $priorityType = new Type("logging", "edu.middlebury", "Event_Notice",
  155. "Normal events.");
  156. $item = new AgentNodeEntryItem("Modify Agent", "Password changed for:\n<br/>&nbsp; &nbsp; &nbsp;".$uname."\n<br/>&nbsp; &nbsp; &nbsp;".$dbAuthType->getKeyword());
  157. $item->addAgentId($id);
  158. $log->appendLogWithTypes($item, $formatType, $priorityType);
  159. }
  160.  
  161. $t_array = array("username" => $uname,
  162. "password" => $properties['new_password']);
  163. $authNTokens =$dbAuthMethod->createTokens($t_array);
  164. // Add it to the system and login with new password
  165. if ($dbAuthMethod->supportsTokenUpdates()) {
  166. $dbAuthMethod->updateTokens($tokens, $authNTokens);
  167. $harmoni->request->startNamespace("harmoni-authentication");
  168. $harmoni->request->set("username", $uname);
  169. $harmoni->request->set("password",
  170. $properties['new_password']);
  171. $harmoni->request->endNamespace();
  172. $authN->authenticateUser($dbAuthType);
  173. return TRUE;
  174. }
  175. } else {
  176. $error = "Invalid new password";
  177. $localizedError = _("Invalid new password, please try again.")."\n<br/>";
  178. }
  179. }
  180. if (isset($error)) {
  181. // Log the action
  182. if (Services::serviceRunning("Logging")) {
  183. $loggingManager = Services::getService("Logging");
  184. $log =$loggingManager->getLogForWriting("Authentication");
  185. $formatType = new Type("logging", "edu.middlebury", "AgentsAndNodes",
  186. "A format in which the acting Agent[s] and the target nodes affected are specified.");
  187. $priorityType = new Type("logging", "edu.middlebury", "Error",
  188. "Normal events.");
  189. $item = new AgentNodeEntryItem("Modify Agent", "Password change error:\n<br/>&nbsp; &nbsp; &nbsp;".$error."\n<br/>for:\n<br/>&nbsp; &nbsp; &nbsp;".$uname."\n<br/>&nbsp; &nbsp; &nbsp;".$dbAuthType->getKeyword());
  190. $item->addAgentId($id);
  191. $log->appendLogWithTypes($item, $formatType, $priorityType);
  192. }
  193. $this->closeWizard($cacheName);
  194. RequestContext::locationHeader($harmoni->request->quickURL("user",
  195. "change_password", array("error" => $localizedError)));
  196. }
  197. }
  198. /**
  199. * Return the URL that this action should return to when completed.
  200. *
  201. * @return string
  202. * @access public
  203. * @since 10/24/05
  204. */
  205. function getReturnUrl () {
  206. $harmoni = Harmoni::instance();
  207. return $harmoni->request->quickURL("user", "main");
  208. }
  209. }
  210. ?>

Documentation generated on Wed, 19 Sep 2007 10:22:01 -0400 by phpDocumentor 1.3.0RC3