Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

AdminpasswordHandler.php 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. # $Id: AdminpasswordHandler.php 1749 2015-03-17 21:07:59Z christian_boltz $
  3. class AdminpasswordHandler extends PFAHandler {
  4. protected $db_table = 'admin';
  5. protected $id_field = 'username';
  6. # do not skip empty password fields
  7. protected $skip_empty_pass = false;
  8. protected function no_domain_field() {
  9. # PFAHandler die()s if domain field is not set. Disable this behaviour for AdminHandler.
  10. }
  11. protected function validate_new_id() {
  12. # unused in AdminpasswordHandler, but must be defined
  13. }
  14. # init $this->struct, $this->db_table and $this->id_field
  15. protected function initStruct() {
  16. # TODO: shorter PALANG labels ;-)
  17. $this->struct=array(
  18. # field name allow display in... type $PALANG label $PALANG description default / options / ...
  19. # editing? form list
  20. 'username' => pacol( 0, 1, 1, 'text', 'admin' , '' ),
  21. 'oldpass' => pacol( 1, 1, 0, 'pass', 'pPassword_password_current' , '', '', '',
  22. /*not_in_db*/ 1 ),
  23. 'password' => pacol( 1, 1, 0, 'pass', 'pPassword_password' , '' ),
  24. 'password2' => pacol( 1, 1, 0, 'pass', 'pPassword_password2' , '' , '', '',
  25. /*not_in_db*/ 0,
  26. /*dont_write_to_db*/ 1,
  27. /*select*/ 'password as password2'
  28. ),
  29. );
  30. }
  31. public function init($id) {
  32. # hardcode to logged in admin
  33. if ($this->admin_username == '') die("No admin logged in");
  34. $this->id = $this->admin_username;
  35. $this->values['username'] = $this->id;
  36. $this->struct['username']['default'] = $this->id;
  37. # hardcode to edit mode
  38. $this->new = 0;
  39. return parent::init($this->id);
  40. }
  41. public function initMsg() {
  42. $this->msg['error_already_exists'] = 'admin_already_exists'; # probably unused
  43. $this->msg['error_does_not_exist'] = 'admin_does_not_exist'; # probably unused
  44. $this->msg['confirm_delete'] = 'confirm_delete_admin'; # probably unused
  45. $this->msg['logname'] = 'edit_password';
  46. $this->msg['store_error'] = 'pPassword_result_error';
  47. $this->msg['successmessage'] = 'pPassword_result_success';
  48. }
  49. public function webformConfig() {
  50. return array(
  51. # $PALANG labels
  52. 'formtitle_create' => 'pPassword_welcome',
  53. 'formtitle_edit' => 'pPassword_welcome',
  54. 'create_button' => 'change_password',
  55. # various settings
  56. 'required_role' => 'admin',
  57. 'listview' => 'main.php',
  58. 'early_init' => 1,
  59. 'hardcoded_edit' => true,
  60. );
  61. }
  62. /**
  63. * check if old password is correct
  64. */
  65. protected function _validate_oldpass($field, $val) {
  66. if ( $this->login($this->id, $val) ) {
  67. return true;
  68. }
  69. $this->errormsg[$field] = Config::lang('pPassword_password_current_text_error');
  70. return false;
  71. }
  72. /**
  73. * skip default validation (check if password is good enough) for old password
  74. */
  75. protected function _inp_pass($field, $val) {
  76. if ($field == 'oldpass') return true;
  77. return parent::_inp_pass($field, $val);
  78. }
  79. /**
  80. * compare password / password2 field
  81. * error message will be displayed at the password2 field
  82. */
  83. protected function _validate_password2($field, $val) {
  84. return $this->compare_password_fields('password', 'password2');
  85. }
  86. }
  87. /* vim: set expandtab softtabstop=4 tabstop=4 shiftwidth=4: */