Merge branch 'dev' into dev-installer
This commit is contained in:
commit
4e013310b0
8 changed files with 48 additions and 27 deletions
|
@ -152,12 +152,12 @@ class Auth
|
|||
|
||||
|
||||
/**
|
||||
* Checks the new password entered by user on certain criteria, and throws an Exception if its invalid.
|
||||
* Checks the new password entered by user on certain criteria, and throws an exception if its invalid.
|
||||
*
|
||||
* @param string $password
|
||||
* @param string $passwordRepeated
|
||||
*
|
||||
* @throws Exception Codes explained below
|
||||
* @throws AuthException Codes explained below
|
||||
* 2: One password field is empty
|
||||
* 3: Passwords aren't equal
|
||||
* 4: Passwort is too snort
|
||||
|
@ -166,22 +166,22 @@ class Auth
|
|||
{
|
||||
// Check if one passwort input is empty
|
||||
if(empty($password)){
|
||||
throw new Exception("First password field was'nt filled out.", 2);
|
||||
throw new AuthException("First password field was'nt filled out.", 2);
|
||||
}
|
||||
if(empty($passwordRepeated)){
|
||||
throw new Exception("Repeat password field was'nt filled out.", 2);
|
||||
throw new AuthException("Repeat password field was'nt filled out.", 2);
|
||||
}
|
||||
|
||||
// Check if password are equal
|
||||
if($password !== $passwordRepeated){
|
||||
throw new Exception("The repeated password must be equal to the first one.", 3);
|
||||
throw new AuthException("The repeated password must be equal to the first one.", 3);
|
||||
}
|
||||
|
||||
// Check if password length is okay
|
||||
if(Config::has('password.min_length')
|
||||
&& strlen($password) < Config::get('password.min_length')
|
||||
){
|
||||
throw new Exception("Passwords must be at least ".Config::get('password.min_length')." characters long.", 4);
|
||||
throw new AuthException("Passwords must be at least ".Config::get('password.min_length')." characters long.", 4);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
6
include/php/classes/AuthException.php
Normal file
6
include/php/classes/AuthException.php
Normal file
|
@ -0,0 +1,6 @@
|
|||
<?php
|
||||
|
||||
class AuthException extends Exception
|
||||
{
|
||||
|
||||
}
|
|
@ -49,8 +49,11 @@ abstract class AbstractRedirect extends AbstractModel
|
|||
'source' => Config::get('schema.attributes.aliases.source', 'source'),
|
||||
'destination' => Config::get('schema.attributes.aliases.destination', 'destination'),
|
||||
'multi_hash' => Config::get('schema.attributes.aliases.multi_source', 'multi_source'),
|
||||
'is_created_by_user' => Config::get('schema.attributes.aliases.is_created_by_user', 'is_created_by_user'),
|
||||
);
|
||||
|
||||
if(Config::get('options.enable_user_redirects', false)){
|
||||
static::$attributeDbAttributeMapping['is_created_by_user'] = Config::get('schema.attributes.aliases.is_created_by_user', 'is_created_by_user');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -59,9 +59,15 @@ class User extends AbstractModel
|
|||
'username' => Config::get('schema.attributes.users.username', 'username'),
|
||||
'domain' => Config::get('schema.attributes.users.domain', 'domain'),
|
||||
'password_hash' => Config::get('schema.attributes.users.password', 'password'),
|
||||
'mailbox_limit' => Config::get('schema.attributes.users.mailbox_limit'),
|
||||
'max_user_redirects' => Config::get('schema.attributes.users.max_user_redirects'),
|
||||
);
|
||||
|
||||
if(Config::get('options.enable_mailbox_limits', false)){
|
||||
static::$attributeDbAttributeMapping['mailbox_limit'] = Config::get('schema.attributes.users.mailbox_limit');
|
||||
}
|
||||
|
||||
if(Config::get('options.enable_user_redirects', false)){
|
||||
static::$attributeDbAttributeMapping['max_user_redirects'] = Config::get('schema.attributes.users.max_user_redirects');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -76,14 +82,14 @@ class User extends AbstractModel
|
|||
$this->setUsername($data[static::attr('username')]);
|
||||
$this->setDomain($data[static::attr('domain')]);
|
||||
$this->setPasswordHash($data[static::attr('password_hash')]);
|
||||
$this->setMailboxLimit(Config::get('options.enable_mailbox_limits', false)
|
||||
? intval($data[static::attr('mailbox_limit')])
|
||||
: 0
|
||||
);
|
||||
$this->setMaxUserRedirects(Config::get('options.enable_user_redirects', false)
|
||||
? intval($data[static::attr('max_user_redirects')])
|
||||
: 0
|
||||
);
|
||||
|
||||
if(Config::get('options.enable_mailbox_limits', false)){
|
||||
$this->setMailboxLimit($data[static::attr('mailbox_limit')]);
|
||||
}
|
||||
|
||||
if(Config::get('options.enable_user_redirects', false)){
|
||||
$this->setMaxUserRedirects($data[static::attr('max_user_redirects')]);
|
||||
}
|
||||
|
||||
$this->setAttribute('role', static::getRoleByEmail($this->getEmail()));
|
||||
}
|
||||
|
@ -410,7 +416,7 @@ class User extends AbstractModel
|
|||
* @param string $password
|
||||
* @param string $passwordRepeated
|
||||
*
|
||||
* @throws Exception
|
||||
* @throws AuthException
|
||||
*/
|
||||
public function changePassword($password, $passwordRepeated)
|
||||
{
|
||||
|
|
|
@ -144,9 +144,12 @@ if(isset($_POST['savemode'])){
|
|||
AbstractRedirect::attr('source') => $sourceAddress,
|
||||
AbstractRedirect::attr('destination') => emailsToString($inputDestinations),
|
||||
AbstractRedirect::attr('multi_hash') => $hash,
|
||||
AbstractRedirect::attr('is_created_by_user') => false,
|
||||
);
|
||||
|
||||
if(Config::get('options.enable_user_redirects', false)){
|
||||
$data[AbstractRedirect::attr('is_created_by_user')] = false;
|
||||
}
|
||||
|
||||
AbstractRedirect::createAndSave($data);
|
||||
}
|
||||
}
|
||||
|
@ -190,9 +193,12 @@ if(isset($_POST['savemode'])){
|
|||
AbstractRedirect::attr('source') => $inputSource,
|
||||
AbstractRedirect::attr('destination') => $inputDestination,
|
||||
AbstractRedirect::attr('multi_hash') => $hash,
|
||||
AbstractRedirect::attr('is_created_by_user') => false,
|
||||
);
|
||||
|
||||
if(Config::get('options.enable_user_redirects', false)){
|
||||
$data[AbstractRedirect::attr('is_created_by_user')] = false;
|
||||
}
|
||||
|
||||
$a = AbstractRedirect::createAndSave($data);
|
||||
}
|
||||
|
||||
|
|
|
@ -71,7 +71,7 @@ if(!is_null($saveMode)){
|
|||
try{
|
||||
$userToEdit->changePassword($inputPassword, $inputPasswordRepeated);
|
||||
}
|
||||
catch(Exception $passwordInvalidException){
|
||||
catch(AuthException $passwordInvalidException){
|
||||
Message::getInstance()->fail($passwordInvalidException->getMessage());
|
||||
$passwordError = true;
|
||||
}
|
||||
|
@ -141,7 +141,7 @@ if(!is_null($saveMode)){
|
|||
// Redirect user to user list
|
||||
Router::redirect("admin/listusers/?created=1");
|
||||
}
|
||||
catch(Exception $passwordInvalidException){
|
||||
catch(AuthException $passwordInvalidException){
|
||||
Message::getInstance()->fail($passwordInvalidException->getMessage());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ if(isset($_POST['password']) && isset($_POST['password_repeat'])){
|
|||
|
||||
Message::getInstance()->success("Password changed successfully!");
|
||||
}
|
||||
catch(Exception $passwordInvalidException){
|
||||
catch(AuthException $passwordInvalidException){
|
||||
Message::getInstance()->fail($passwordInvalidException->getMessage());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -127,7 +127,7 @@ class AuthTest extends TestCase
|
|||
|
||||
|
||||
/**
|
||||
* @expectedException Exception
|
||||
* @expectedException AuthException
|
||||
* @expectedExceptionCode 2
|
||||
*/
|
||||
public function testValidateNewPasswordFirstEmpty()
|
||||
|
@ -137,7 +137,7 @@ class AuthTest extends TestCase
|
|||
|
||||
|
||||
/**
|
||||
* @expectedException Exception
|
||||
* @expectedException AuthException
|
||||
* @expectedExceptionCode 2
|
||||
*/
|
||||
public function testValidateNewPasswordLastEmpty()
|
||||
|
@ -147,7 +147,7 @@ class AuthTest extends TestCase
|
|||
|
||||
|
||||
/**
|
||||
* @expectedException Exception
|
||||
* @expectedException AuthException
|
||||
* @expectedExceptionCode 3
|
||||
*/
|
||||
public function testValidateNewPasswordNotEqual()
|
||||
|
@ -158,7 +158,7 @@ class AuthTest extends TestCase
|
|||
|
||||
|
||||
/**
|
||||
* @expectedException Exception
|
||||
* @expectedException AuthException
|
||||
* @expectedExceptionCode 4
|
||||
*/
|
||||
public function testValidateNewPasswordTooShort()
|
||||
|
|
Loading…
Add table
Reference in a new issue