-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce DataUtilityServiceProvider
- Lack of a better name… - Shares a method to validate a string against our password policy - Shares a method to transform a given string to the (likely) group mailbox name
- Loading branch information
Showing
1 changed file
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php | ||
namespace SOG\Dashboard; | ||
|
||
|
||
use Silex\Application; | ||
use Silex\ServiceProviderInterface; | ||
|
||
/** | ||
* Class DataUtilityServiceProvider | ||
* @package SOG\Dashboard | ||
*/ | ||
class DataUtilityServiceProvider implements ServiceProviderInterface | ||
{ | ||
|
||
/** | ||
* Check if the given password complies with our password policy. | ||
* | ||
* @param string $password | ||
* @param int $minLength The minimum length for the password | ||
* @param string $regex The regex for checking the password character classes | ||
* @return bool True if the given password complies with the password policy, false otherwise. | ||
*/ | ||
private static function checkPasswordPolicy($password, $minLength = 8, $regex = '/[A-Za-z].*[0-9]|[0-9].*[A-Za-z]/') | ||
{ | ||
if (strlen($password) < $minLength) { | ||
return false; | ||
} | ||
if (preg_match($regex, $password) === 0) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
/** | ||
* Replaces certain prefixes of an OU to retrieve the mailbox name. | ||
* | ||
* @param string $ou | ||
* @return string The modified string | ||
*/ | ||
private static function getMailFromOu($ou) | ||
{ | ||
$ou = strtolower($ou); | ||
$prefixes = [ | ||
'ak_', 'lg_', 'ressort_' | ||
]; | ||
return str_replace($prefixes, '', $ou); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function register(Application $app) | ||
{ | ||
$app['check_password_policy'] = $app->protect(function () { | ||
return call_user_func_array('self::checkPasswordPolicy', func_get_args()); | ||
}); | ||
$app['get_mail_from_ou'] = $app->protect(function () { | ||
return call_user_func_array('self::getMailFromOu', func_get_args()); | ||
}); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function boot(Application $app) | ||
{ | ||
// nothing to do here | ||
} | ||
} |