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.

AdminpasswordHandler.php 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. # $Id$
  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 == '') {
  34. die("No admin logged in");
  35. }
  36. $this->id = $this->admin_username;
  37. $this->values['username'] = $this->id;
  38. $this->struct['username']['default'] = $this->id;
  39. # hardcode to edit mode
  40. $this->new = 0;
  41. return parent::init($this->id);
  42. }
  43. public function initMsg() {
  44. $this->msg['error_already_exists'] = 'admin_already_exists'; # probably unused
  45. $this->msg['error_does_not_exist'] = 'admin_does_not_exist'; # probably unused
  46. $this->msg['confirm_delete'] = 'confirm_delete_admin'; # probably unused
  47. $this->msg['logname'] = 'edit_password';
  48. $this->msg['store_error'] = 'pPassword_result_error';
  49. $this->msg['successmessage'] = 'pPassword_result_success';
  50. }
  51. public function webformConfig() {
  52. return array(
  53. # $PALANG labels
  54. 'formtitle_create' => 'pPassword_welcome',
  55. 'formtitle_edit' => 'pPassword_welcome',
  56. 'create_button' => 'change_password',
  57. # various settings
  58. 'required_role' => 'admin',
  59. 'listview' => 'main.php',
  60. 'early_init' => 1,
  61. 'hardcoded_edit' => true,
  62. );
  63. }
  64. /**
  65. * check if old password is correct
  66. */
  67. protected function _validate_oldpass($field, $val) {
  68. if ($this->login($this->id, $val)) {
  69. return true;
  70. }
  71. $this->errormsg[$field] = Config::lang('pPassword_password_current_text_error');
  72. return false;
  73. }
  74. /**
  75. * skip default validation (check if password is good enough) for old password
  76. */
  77. protected function _inp_pass($field, $val) {
  78. if ($field == 'oldpass') {
  79. return true;
  80. }
  81. return parent::_inp_pass($field, $val);
  82. }
  83. /**
  84. * compare password / password2 field
  85. * error message will be displayed at the password2 field
  86. */
  87. protected function _validate_password2($field, $val) {
  88. return $this->compare_password_fields('password', 'password2');
  89. }
  90. }
  91. /* vim: set expandtab softtabstop=4 tabstop=4 shiftwidth=4: */