model.authent-local.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. // Copyright (C) 2010 Combodo SARL
  3. //
  4. // This program is free software; you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation; version 3 of the License.
  7. //
  8. // This program is distributed in the hope that it will be useful,
  9. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. // GNU General Public License for more details.
  12. //
  13. // You should have received a copy of the GNU General Public License
  14. // along with this program; if not, write to the Free Software
  15. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16. /**
  17. * Authent Local
  18. * User authentication Module, password stored in the local database
  19. *
  20. * @author Erwan Taloc <erwan.taloc@combodo.com>
  21. * @author Romain Quetiez <romain.quetiez@combodo.com>
  22. * @author Denis Flaven <denis.flaven@combodo.com>
  23. * @license http://www.opensource.org/licenses/gpl-3.0.html LGPL
  24. */
  25. class UserLocal extends UserInternal
  26. {
  27. public static function Init()
  28. {
  29. $aParams = array
  30. (
  31. "category" => "addon/authentication",
  32. "key_type" => "autoincrement",
  33. "name_attcode" => "login",
  34. "state_attcode" => "",
  35. "reconc_keys" => array(),
  36. "db_table" => "priv_user_local",
  37. "db_key_field" => "id",
  38. "db_finalclass_field" => "",
  39. "display_template" => "",
  40. );
  41. MetaModel::Init_Params($aParams);
  42. MetaModel::Init_InheritAttributes();
  43. MetaModel::Init_AddAttribute(new AttributeOneWayPassword("password", array("allowed_values"=>null, "sql"=>"pwd", "default_value"=>null, "is_null_allowed"=>false, "depends_on"=>array())));
  44. // Display lists
  45. MetaModel::Init_SetZListItems('details', array('contactid', 'first_name', 'email', 'login', 'password', 'language', 'profile_list', 'allowed_org_list')); // Attributes to be displayed for the complete details
  46. MetaModel::Init_SetZListItems('list', array('first_name', 'last_name', 'login')); // Attributes to be displayed for a list
  47. // Search criteria
  48. MetaModel::Init_SetZListItems('standard_search', array('login', 'contactid')); // Criteria of the std search form
  49. MetaModel::Init_SetZListItems('advanced_search', array('login', 'contactid')); // Criteria of the advanced search form
  50. }
  51. public function CheckCredentials($sPassword)
  52. {
  53. $oPassword = $this->Get('password'); // ormPassword object
  54. // Cannot compare directly the values since they are hashed, so
  55. // Let's ask the password to compare the hashed values
  56. if ($oPassword->CheckPassword($sPassword))
  57. {
  58. return true;
  59. }
  60. return false;
  61. }
  62. public function TrustWebServerContext()
  63. {
  64. return true;
  65. }
  66. public function CanChangePassword()
  67. {
  68. // For now everyone can change their password..
  69. return true;
  70. }
  71. public function CanLogOff()
  72. {
  73. // Internal authentication allows everybody to log off
  74. return true;
  75. }
  76. public function ChangePassword($sOldPassword, $sNewPassword)
  77. {
  78. $oPassword = $this->Get('password'); // ormPassword object
  79. // Cannot compare directly the values since they are hashed, so
  80. // Let's ask the password to compare the hashed values
  81. if ($oPassword->CheckPassword($sOldPassword))
  82. {
  83. $this->Set('password', $sNewPassword);
  84. $oChange = MetaModel::NewObject("CMDBChange");
  85. $oChange->Set("date", time());
  86. $sUserString = CMDBChange::GetCurrentUserName();
  87. $oChange->Set("userinfo", $sUserString);
  88. $oChange->DBInsert();
  89. $this->DBUpdateTracked($oChange, true);
  90. return true;
  91. }
  92. return false;
  93. }
  94. }
  95. ?>