Add own exception class for auth, so catching of auth exceptions wont catch all exceptions anymore
This commit is contained in:
parent
29dc137f0e
commit
2926d3fab2
6 changed files with 20 additions and 14 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
|
||||
{
|
||||
|
||||
}
|
|
@ -410,7 +410,7 @@ class User extends AbstractModel
|
|||
* @param string $password
|
||||
* @param string $passwordRepeated
|
||||
*
|
||||
* @throws Exception
|
||||
* @throws AuthException
|
||||
*/
|
||||
public function changePassword($password, $passwordRepeated)
|
||||
{
|
||||
|
|
|
@ -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