You've already forked postfixadmin
mirror of
https://github.com/postfixadmin/postfixadmin.git
synced 2025-08-06 06:42:37 +03:00
composer format
This commit is contained in:
@@ -80,9 +80,8 @@ class AdminpasswordHandler extends PFAHandler {
|
||||
* check if old password is correct
|
||||
*/
|
||||
protected function _validate_oldpass($field, $val) {
|
||||
|
||||
$l = new Login('admin', 'username');
|
||||
if($l->login($this->id, $val)) {
|
||||
if ($l->login($this->id, $val)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@@ -1,13 +1,11 @@
|
||||
<?php
|
||||
|
||||
|
||||
class Login
|
||||
{
|
||||
class Login {
|
||||
private $table;
|
||||
private $id_field;
|
||||
|
||||
public function __construct(string $tableName, string $idField)
|
||||
{
|
||||
public function __construct(string $tableName, string $idField) {
|
||||
$this->table = table_by_key($tableName);
|
||||
$this->id_field = $idField;
|
||||
}
|
||||
@@ -19,9 +17,7 @@ class Login
|
||||
* @param string $password
|
||||
* @return boolean true on successful login (i.e. password matches etc)
|
||||
*/
|
||||
public function login($username, $password): bool
|
||||
{
|
||||
|
||||
public function login($username, $password): bool {
|
||||
$active = db_get_boolean(true);
|
||||
$query = "SELECT password FROM {$this->table} WHERE {$this->id_field} = :username AND active = :active";
|
||||
|
||||
@@ -48,9 +44,7 @@ class Login
|
||||
* @return false|string
|
||||
* @throws Exception
|
||||
*/
|
||||
public function generatePasswordRecoveryCode(string $username)
|
||||
{
|
||||
|
||||
public function generatePasswordRecoveryCode(string $username) {
|
||||
$sql = "SELECT count(1) FROM {$this->table} WHERE {$this->id_field} = :username AND active = :active";
|
||||
|
||||
$active = db_get_boolean(true);
|
||||
@@ -88,9 +82,7 @@ class Login
|
||||
* @return boolean true on success; false on failure
|
||||
* @throws \Exception if invalid user, or db update fails.
|
||||
*/
|
||||
public function changePassword($username, $new_password, $old_password): bool
|
||||
{
|
||||
|
||||
public function changePassword($username, $new_password, $old_password): bool {
|
||||
list(/*NULL*/, $domain) = explode('@', $username);
|
||||
|
||||
$login = new Login($this->table, $this->id_field);
|
||||
|
@@ -57,8 +57,7 @@ if ($_SERVER['REQUEST_METHOD'] == "POST") {
|
||||
$h = new AdminHandler();
|
||||
|
||||
$login = new Login('admin', $h->getId_field());
|
||||
if($login->login($fUsername, $fPassword)) {
|
||||
|
||||
if ($login->login($fUsername, $fPassword)) {
|
||||
init_session($fUsername, true);
|
||||
|
||||
# they've logged in, so see if they are a domain admin, as well.
|
||||
|
@@ -48,7 +48,8 @@ if ($_SERVER['REQUEST_METHOD'] == "POST") {
|
||||
|
||||
$h = new MailboxHandler();
|
||||
|
||||
$login = new Login('mailbox', 'username');;
|
||||
$login = new Login('mailbox', 'username');
|
||||
;
|
||||
if ($login->login($fUsername, $fPassword)) {
|
||||
init_session($fUsername, false);
|
||||
header("Location: main.php");
|
||||
|
@@ -38,8 +38,7 @@ if ($context === 'admin' && !Config::read('forgotten_admin_password_reset') || $
|
||||
die('Password reset is disabled by configuration option: forgotten_admin_password_reset');
|
||||
}
|
||||
|
||||
function sendCodebyEmail($to, $username, $code)
|
||||
{
|
||||
function sendCodebyEmail($to, $username, $code) {
|
||||
$https = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ? 'https' : 'http';
|
||||
|
||||
$_SERVER['REQUEST_SCHEME'] = isset($_SERVER['REQUEST_SCHEME']) ? $_SERVER['REQUEST_SCHEME'] : $https;
|
||||
@@ -49,8 +48,7 @@ function sendCodebyEmail($to, $username, $code)
|
||||
return smtp_mail($to, Config::read('admin_email'), Config::Lang('pPassword_welcome'), Config::read('admin_smtp_password'), Config::lang_f('pPassword_recovery_email_body', $url));
|
||||
}
|
||||
|
||||
function sendCodebySMS($to, $username, $code)
|
||||
{
|
||||
function sendCodebySMS($to, $username, $code) {
|
||||
$text = Config::lang_f('pPassword_recovery_sms_body', $code);
|
||||
|
||||
$function = Config::read('sms_send_function');
|
||||
|
@@ -72,7 +72,6 @@ if ($_SERVER['REQUEST_METHOD'] == "POST") {
|
||||
}
|
||||
|
||||
if ($error == 0) {
|
||||
|
||||
try {
|
||||
if ($login->changePassword($username, $fPassword, $fPassword_current)) {
|
||||
flash_info(Config::Lang_f('pPassword_result_success', $username));
|
||||
|
@@ -44,8 +44,7 @@ $server = new Zend_XmlRpc_Server();
|
||||
* @param string $password
|
||||
* @return boolean true on success, else false.
|
||||
*/
|
||||
function login($username, $password)
|
||||
{
|
||||
function login($username, $password) {
|
||||
$h = new MailboxHandler();
|
||||
$login = new Login('mailbox', 'username');
|
||||
if ($login->login($username, $password)) {
|
||||
@@ -68,16 +67,14 @@ if (!isset($_SESSION['authenticated'])) {
|
||||
echo $server->handle();
|
||||
|
||||
|
||||
class UserProxy
|
||||
{
|
||||
class UserProxy {
|
||||
|
||||
/**
|
||||
* @param string $old_password
|
||||
* @param string $new_password
|
||||
* @return boolean true on success
|
||||
*/
|
||||
public function changePassword($old_password, $new_password)
|
||||
{
|
||||
public function changePassword($old_password, $new_password) {
|
||||
$uh = new MailboxHandler();
|
||||
$username = $_SESSION['sessid']['username'] ?? '';
|
||||
|
||||
@@ -96,7 +93,6 @@ class UserProxy
|
||||
} catch (\Exception $e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -104,20 +100,17 @@ class UserProxy
|
||||
* @param string $password
|
||||
* @return boolean true if successful.
|
||||
*/
|
||||
public function login($username, $password)
|
||||
{
|
||||
public function login($username, $password) {
|
||||
$login = new Login('mailbox', 'username');
|
||||
return $login->login($username, $password);
|
||||
}
|
||||
}
|
||||
|
||||
class VacationProxy
|
||||
{
|
||||
class VacationProxy {
|
||||
/**
|
||||
* @return boolean true if the vacation is removed successfully. Else false.
|
||||
*/
|
||||
public function remove()
|
||||
{
|
||||
public function remove() {
|
||||
$vh = new VacationHandler($_SESSION['sessid']['username']);
|
||||
return $vh->remove();
|
||||
}
|
||||
@@ -126,8 +119,7 @@ class VacationProxy
|
||||
* @return boolean true if vacation stuff is enabled in this instance of postfixadmin
|
||||
* and the user has the ability to make changes to it.
|
||||
*/
|
||||
public function isVacationSupported()
|
||||
{
|
||||
public function isVacationSupported() {
|
||||
$vh = new VacationHandler($_SESSION['sessid']['username']);
|
||||
return $vh->vacation_supported();
|
||||
}
|
||||
@@ -135,8 +127,7 @@ class VacationProxy
|
||||
/**
|
||||
* @return boolean true if the user has an active vacation record etc.
|
||||
*/
|
||||
public function checkVacation()
|
||||
{
|
||||
public function checkVacation() {
|
||||
$vh = new VacationHandler($_SESSION['sessid']['username']);
|
||||
return $vh->check_vacation();
|
||||
}
|
||||
@@ -144,8 +135,7 @@ class VacationProxy
|
||||
/**
|
||||
* @return array|bool - either array of vacation details or boolean false if the user has none.
|
||||
*/
|
||||
public function getDetails()
|
||||
{
|
||||
public function getDetails() {
|
||||
$vh = new VacationHandler($_SESSION['sessid']['username']);
|
||||
return $vh->get_details();
|
||||
}
|
||||
@@ -159,20 +149,17 @@ class VacationProxy
|
||||
* @return boolean true on success.
|
||||
* Whatiis @replyType?? for
|
||||
*/
|
||||
public function setAway($subject, $body, $interval_time = 0, $activeFrom = '2000-01-01', $activeUntil = '2099-12-31')
|
||||
{
|
||||
public function setAway($subject, $body, $interval_time = 0, $activeFrom = '2000-01-01', $activeUntil = '2099-12-31') {
|
||||
$vh = new VacationHandler($_SESSION['sessid']['username']);
|
||||
return $vh->set_away($subject, $body, $interval_time, $activeFrom, $activeUntil);
|
||||
}
|
||||
}
|
||||
|
||||
class AliasProxy
|
||||
{
|
||||
class AliasProxy {
|
||||
/**
|
||||
* @return array - array of aliases this user has. Array may be empty.
|
||||
*/
|
||||
public function get()
|
||||
{
|
||||
public function get() {
|
||||
$ah = new AliasHandler();
|
||||
$ah->init($_SESSION['sessid']['username']);
|
||||
/* I see no point in returning special addresses to the user. */
|
||||
@@ -186,8 +173,7 @@ class AliasProxy
|
||||
* @param string flag to set ('forward_and_store' or 'remote_only')
|
||||
* @return boolean true
|
||||
*/
|
||||
public function update($addresses, $flags)
|
||||
{
|
||||
public function update($addresses, $flags) {
|
||||
$ah = new AliasHandler();
|
||||
$ah->init($_SESSION['sessid']['username']);
|
||||
|
||||
@@ -213,8 +199,7 @@ class AliasProxy
|
||||
* @return boolean true if the user has 'store_and_forward' set.
|
||||
* (i.e. their email address is also in the alias table). IF it returns false, then it's 'remote_only'
|
||||
*/
|
||||
public function hasStoreAndForward()
|
||||
{
|
||||
public function hasStoreAndForward() {
|
||||
$ah = new AliasHandler();
|
||||
$ah->init($_SESSION['sessid']['username']);
|
||||
$ah->view();
|
||||
|
@@ -1,10 +1,7 @@
|
||||
<?php
|
||||
|
||||
class AliasHandlerTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
class AliasHandlerTest extends \PHPUnit\Framework\TestCase {
|
||||
protected function setUp(): void {
|
||||
// Fake being an admin.
|
||||
$_SESSION = [
|
||||
'sessid' => [
|
||||
@@ -14,8 +11,7 @@ class AliasHandlerTest extends \PHPUnit\Framework\TestCase
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
protected function tearDown(): void {
|
||||
$_SESSION = [];
|
||||
db_query('DELETE FROM alias');
|
||||
db_query('DELETE FROM domain_admins');
|
||||
@@ -24,8 +20,7 @@ class AliasHandlerTest extends \PHPUnit\Framework\TestCase
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
public function testBasic()
|
||||
{
|
||||
public function testBasic() {
|
||||
$x = new AliasHandler();
|
||||
$list = $x->getList("");
|
||||
$this->assertTrue($list);
|
||||
@@ -34,8 +29,7 @@ class AliasHandlerTest extends \PHPUnit\Framework\TestCase
|
||||
}
|
||||
|
||||
|
||||
public function testCannotAddAliasUntilDomainIsThere()
|
||||
{
|
||||
public function testCannotAddAliasUntilDomainIsThere() {
|
||||
|
||||
// Fake us being an admin.
|
||||
|
||||
@@ -69,8 +63,7 @@ class AliasHandlerTest extends \PHPUnit\Framework\TestCase
|
||||
/**
|
||||
* @see https://github.com/postfixadmin/postfixadmin/pull/375 and https://github.com/postfixadmin/postfixadmin/issues/358
|
||||
*/
|
||||
public function testCannotAddAliasThatPointsToItself()
|
||||
{
|
||||
public function testCannotAddAliasThatPointsToItself() {
|
||||
// Fake being an admin.
|
||||
$_SESSION = [
|
||||
'sessid' => [
|
||||
@@ -153,8 +146,7 @@ class AliasHandlerTest extends \PHPUnit\Framework\TestCase
|
||||
], $x->errormsg);
|
||||
}
|
||||
|
||||
public function testAddingDataEtc()
|
||||
{
|
||||
public function testAddingDataEtc() {
|
||||
|
||||
// Fake being an admin.
|
||||
$_SESSION = [
|
||||
@@ -207,8 +199,7 @@ class AliasHandlerTest extends \PHPUnit\Framework\TestCase
|
||||
}
|
||||
|
||||
|
||||
private function addDomain(string $domain, string $username): void
|
||||
{
|
||||
private function addDomain(string $domain, string $username): void {
|
||||
// Fake being an admin.
|
||||
$_SESSION = [
|
||||
'sessid' => [
|
||||
@@ -265,12 +256,9 @@ class AliasHandlerTest extends \PHPUnit\Framework\TestCase
|
||||
foreach ($expected as $k => $v) {
|
||||
$this->assertEquals($v, $result[$domain][$k]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function testYouCannotAddMoreAliasesThanTheDomainLimit()
|
||||
{
|
||||
|
||||
public function testYouCannotAddMoreAliasesThanTheDomainLimit() {
|
||||
$this->addDomain('example.com', 'admin');
|
||||
|
||||
// default limit is 11 aliases.... so it should exit once we get past that.
|
||||
@@ -288,7 +276,6 @@ class AliasHandlerTest extends \PHPUnit\Framework\TestCase
|
||||
|
||||
|
||||
foreach (range(1, 7) as $char) {
|
||||
|
||||
$newAlias = $char . '-test@example.com';
|
||||
|
||||
$x = new AliasHandler(1, 'admin', true);
|
||||
@@ -335,13 +322,10 @@ class AliasHandlerTest extends \PHPUnit\Framework\TestCase
|
||||
'address' => "You have reached your limit to create aliases!",
|
||||
0 => "one or more values are invalid!"
|
||||
], $x->errormsg);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function testLoadsOfAliasesGetHandledByPager()
|
||||
{
|
||||
|
||||
public function testLoadsOfAliasesGetHandledByPager() {
|
||||
$this->addDomain('example.com', 'admin');
|
||||
|
||||
// default limit is 11 aliases.... so it should exit once we get past that.
|
||||
@@ -369,7 +353,6 @@ class AliasHandlerTest extends \PHPUnit\Framework\TestCase
|
||||
$this->assertEquals(88, $domain['mailboxes']);
|
||||
|
||||
foreach (range(1, 80) as $char) {
|
||||
|
||||
$newAlias = $char . '-test@example.com';
|
||||
|
||||
$x = new AliasHandler(1, 'admin', true);
|
||||
@@ -401,6 +384,5 @@ class AliasHandlerTest extends \PHPUnit\Framework\TestCase
|
||||
|
||||
$this->assertEquals(5, count($results));
|
||||
$this->assertTrue(isset($results['31-test@example.com']));
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -1,9 +1,7 @@
|
||||
<?php
|
||||
|
||||
class DomainHandlerTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public function testBasic()
|
||||
{
|
||||
class DomainHandlerTest extends \PHPUnit\Framework\TestCase {
|
||||
public function testBasic() {
|
||||
$x = new DomainHandler();
|
||||
|
||||
$list = $x->getList("");
|
||||
@@ -15,8 +13,7 @@ class DomainHandlerTest extends \PHPUnit\Framework\TestCase
|
||||
$this->assertEmpty($results);
|
||||
}
|
||||
|
||||
public function testAddAndUpdate()
|
||||
{
|
||||
public function testAddAndUpdate() {
|
||||
// Fake being an admin.
|
||||
$_SESSION = [
|
||||
'sessid' => [
|
||||
@@ -101,7 +98,5 @@ class DomainHandlerTest extends \PHPUnit\Framework\TestCase
|
||||
|
||||
$this->assertEquals(99, $d['aliases']);
|
||||
$this->assertEquals(88, $d['mailboxes']);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -1,10 +1,7 @@
|
||||
<?php
|
||||
|
||||
class LoginTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
class LoginTest extends \PHPUnit\Framework\TestCase {
|
||||
public function setUp(): void {
|
||||
$this->cleanUp();
|
||||
|
||||
db_execute("INSERT INTO domain(`domain`, description, transport) values ('example.com', 'test', 'foo')", [], true);
|
||||
@@ -24,20 +21,17 @@ VALUES(:username, :password, :name, :maildir, :local_part, :domain)",
|
||||
}
|
||||
|
||||
|
||||
public function tearDown(): void
|
||||
{
|
||||
public function tearDown(): void {
|
||||
$this->cleanUp();
|
||||
parent::tearDown(); // TODO: Change the autogenerated stub
|
||||
}
|
||||
|
||||
private function cleanUp()
|
||||
{
|
||||
private function cleanUp() {
|
||||
db_query('DELETE FROM mailbox');
|
||||
db_query('DELETE FROM domain');
|
||||
}
|
||||
|
||||
public function testInvalidUsers()
|
||||
{
|
||||
public function testInvalidUsers() {
|
||||
$login = new Login('mailbox', 'username');
|
||||
|
||||
$this->assertFalse($login->login('test', 'password'));
|
||||
@@ -46,23 +40,18 @@ VALUES(:username, :password, :name, :maildir, :local_part, :domain)",
|
||||
}
|
||||
|
||||
|
||||
public function testValidLogin()
|
||||
{
|
||||
public function testValidLogin() {
|
||||
$login = new Login('mailbox', 'username');
|
||||
|
||||
$this->assertFalse($login->login('test', 'password'));
|
||||
$this->assertFalse($login->login('test', 'foobar'));
|
||||
$this->assertFalse($login->login('', ''));
|
||||
|
||||
}
|
||||
|
||||
public function testPasswordRecovery()
|
||||
{
|
||||
|
||||
public function testPasswordRecovery() {
|
||||
$login = new Login('mailbox', 'username');
|
||||
$this->assertFalse($login->generatePasswordRecoveryCode(''));
|
||||
$this->assertFalse($login->generatePasswordRecoveryCode('doesnotexist'));
|
||||
$this->assertNotEmpty($login->generatePasswordRecoveryCode('test@example.com'));
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -20,7 +20,6 @@ class MailboxHandlerTest extends \PHPUnit\Framework\TestCase {
|
||||
$results = $x->result();
|
||||
|
||||
$this->assertEmpty($results);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user