0
0
mirror of https://github.com/postfixadmin/postfixadmin.git synced 2024-09-19 19:22:14 +02:00
postfixadmin/model/AdminpasswordHandler.php

124 lines
3.7 KiB
PHP
Raw Normal View History

<?php
2022-06-28 14:46:11 +02:00
# $Id$
2021-03-22 10:28:28 +01:00
class AdminpasswordHandler extends PFAHandler
{
protected $db_table = 'admin';
protected $id_field = 'username';
# do not skip empty password fields
protected $skip_empty_pass = false;
2021-04-13 22:19:16 +02:00
protected function no_domain_field()
{
return true;
}
2021-04-13 22:19:16 +02:00
protected function validate_new_id()
{
return true;
}
# init $this->struct, $this->db_table and $this->id_field
2021-04-13 22:19:16 +02:00
protected function initStruct()
{
# TODO: shorter PALANG labels ;-)
$this->struct = array(
# field name allow display in... type $PALANG label $PALANG description default / options / ...
# editing? form list
'username' => pacol(0, 1, 1, 'text', 'admin' , ''),
2018-12-27 22:43:11 +01:00
'oldpass' => pacol(1, 1, 0, 'pass', 'pPassword_password_current' , '', '', array(),
/*not_in_db*/ 1),
'password' => pacol(1, 1, 0, 'pass', 'pPassword_password' , ''),
2018-12-27 22:43:11 +01:00
'password2' => pacol(1, 1, 0, 'pass', 'pPassword_password2' , '' , '', array(),
/*not_in_db*/ 0,
/*dont_write_to_db*/ 1,
/*select*/ 'password as password2'
),
);
}
2022-06-28 14:46:11 +02:00
public function init(string $id): bool
2021-04-13 22:19:16 +02:00
{
# hardcode to logged in admin
2018-01-26 15:45:57 +01:00
if ($this->admin_username == '') {
die("No admin logged in");
}
$this->id = $this->admin_username;
$this->values['username'] = $this->id;
$this->struct['username']['default'] = $this->id;
# hardcode to edit mode
$this->new = 0;
return parent::init($this->id);
}
2021-04-13 22:19:16 +02:00
public function initMsg()
{
$this->msg['error_already_exists'] = 'admin_already_exists'; # probably unused
$this->msg['error_does_not_exist'] = 'admin_does_not_exist'; # probably unused
$this->msg['confirm_delete'] = 'confirm_delete_admin'; # probably unused
$this->msg['logname'] = 'edit_password';
$this->msg['store_error'] = 'pPassword_result_error';
$this->msg['successmessage'] = 'pPassword_result_success';
}
2021-04-13 22:19:16 +02:00
public function webformConfig()
{
return array(
# $PALANG labels
'formtitle_create' => 'pPassword_welcome',
'formtitle_edit' => 'pPassword_welcome',
'create_button' => 'change_password',
# various settings
'required_role' => 'admin',
'listview' => 'main.php',
'early_init' => 1,
'hardcoded_edit' => true,
);
}
/**
* check if old password is correct
*/
2021-04-13 22:19:16 +02:00
protected function _validate_oldpass($field, $val)
{
$l = new Login('admin');
2020-09-25 22:33:26 +02:00
if ($l->login($this->id, $val)) {
return true;
}
$this->errormsg[$field] = Config::lang('pPassword_password_current_text_error');
return false;
}
/**
* skip default validation (check if password is good enough) for old password
*/
2021-04-13 22:19:16 +02:00
protected function _inp_pass($field, $val)
{
2018-01-26 15:45:57 +01:00
if ($field == 'oldpass') {
return true;
}
return parent::_inp_pass($field, $val);
}
/**
* compare password / password2 field
* error message will be displayed at the password2 field
*/
2021-04-13 22:19:16 +02:00
protected function _validate_password2($field, $val)
{
return $this->compare_password_fields('password', 'password2');
}
}
/* vim: set expandtab softtabstop=4 tabstop=4 shiftwidth=4: */