Skip to content

Commit

Permalink
Code standard for app code
Browse files Browse the repository at this point in the history
  • Loading branch information
phil-davis authored and DeepDiver1975 committed Aug 21, 2018
1 parent 0a5f6e1 commit 9467ac3
Show file tree
Hide file tree
Showing 17 changed files with 23 additions and 33 deletions.
7 changes: 3 additions & 4 deletions appinfo/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,8 @@
// only load notification JS code in the logged in layout page (not public links not login page)
$request = \OC::$server->getRequest();
if (\OC::$server->getUserSession() !== null && \OC::$server->getUserSession()->getUser() !== null
&& substr($request->getScriptName(), 0 - strlen('/index.php')) === '/index.php'
&& substr($request->getPathInfo(), 0, strlen('/s/')) !== '/s/'
&& substr($request->getPathInfo(), 0, strlen('/login')) !== '/login') {

&& \substr($request->getScriptName(), 0 - \strlen('/index.php')) === '/index.php'
&& \substr($request->getPathInfo(), 0, \strlen('/s/')) !== '/s/'
&& \substr($request->getPathInfo(), 0, \strlen('/login')) !== '/login') {
\OCP\Util::addScript('password_policy', 'notification');
}
3 changes: 1 addition & 2 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@
use OCA\PasswordPolicy\Notifier;

class Application extends App {

public function __construct (array $urlParams = []) {
public function __construct(array $urlParams = []) {
parent::__construct('password_policy', $urlParams);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Authentication/AccountModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function check(IUser $user) {
if ($forcePasswordChange) {
$redirectUrl = $this->request->getRequestUri();
$response = new RedirectResponse(
$this->urlGenerator->linkToRoute( 'password_policy.password.show', [
$this->urlGenerator->linkToRoute('password_policy.password.show', [
'redirect_url' => $redirectUrl
])
);
Expand Down
4 changes: 1 addition & 3 deletions lib/Command/ExpirePassword.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
use Symfony\Component\Console\Output\OutputInterface;
use OCP\AppFramework\Utility\ITimeFactory;


class ExpirePassword extends Command {
/**
* Catchall for general errors
Expand Down Expand Up @@ -64,7 +63,6 @@ class ExpirePassword extends Command {
/** @var OldPasswordMapper */
private $mapper;


/**
* ExpirePassword constructor.
*
Expand Down Expand Up @@ -200,7 +198,7 @@ protected function execute(InputInterface $input, OutputInterface $output) {
* @param $inputExpireDate
* @param IUser $user
*/
protected function setPasswordExpiry(\DateTime $expireDate, \DateTime $oldDate, \DateTimeZone $timeZone, $inputExpireDate , IUser $user) {
protected function setPasswordExpiry(\DateTime $expireDate, \DateTime $oldDate, \DateTimeZone $timeZone, $inputExpireDate, IUser $user) {
$expireDate->setTimezone($timeZone);
$expireDate->setTimestamp($this->timeFactory->getTime());
$expireDate->modify($inputExpireDate);
Expand Down
2 changes: 1 addition & 1 deletion lib/Controller/PasswordController.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public function show($redirect_url) {
*/
public function update($current_password, $new_password, $confirm_password, $redirect_url) {
$user = $this->userSession->getUser();
if(($user !== null) && !$this->userManager->checkPassword($user->getUID(), $current_password)) {
if (($user !== null) && !$this->userManager->checkPassword($user->getUID(), $current_password)) {
return $this->createPasswordTemplateResponse(
$redirect_url,
$this->l10n->t('Old password is wrong.')
Expand Down
2 changes: 1 addition & 1 deletion lib/Controller/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public function getPriority() {

public function getPanel() {
$template = new Template('password_policy', 'admin');
foreach(self::DEFAULTS as $key => $default) {
foreach (self::DEFAULTS as $key => $default) {
$value = $this->config->getAppValue('password_policy', $key, $default);
if (isset(self::CONVERSIONS[$key]['out'])) {
$convertFuncName = self::CONVERSIONS[$key]['out'];
Expand Down
4 changes: 2 additions & 2 deletions lib/Db/OldPassword.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
namespace OCA\PasswordPolicy\Db;

use OCP\AppFramework\Db\Entity;

/**
* @method int getId()
* @method void setId(\int $id)
Expand All @@ -33,7 +34,6 @@
* @method void setChangeTime(\int $changeTime)
*/
class OldPassword extends Entity {

const EXPIRED = 'expired';

/** @var string $uid */
Expand All @@ -48,4 +48,4 @@ class OldPassword extends Entity {
public function getPassword() {
return $this->password;
}
}
}
1 change: 0 additions & 1 deletion lib/Db/OldPasswordMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
use OCP\IDBConnection;

class OldPasswordMapper extends Mapper {

public function __construct(IDBConnection $db) {
parent::__construct($db, 'user_password_history');
}
Expand Down
6 changes: 3 additions & 3 deletions lib/HooksHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ public function updateLinkExpiry($params) {

if ($days !== null) {
$date = new \DateTime();
$date->setTime(0,0,0);
$date->setTime(0, 0, 0);
$date->add(new \DateInterval('P'.$days.'D'));

if ($params['expirationDate'] === null) {
Expand Down Expand Up @@ -272,7 +272,7 @@ protected function forcePasswordChange($firstLogin = null, IUser $user = null) {
*/
private function getUser(GenericEvent $event) {
$user = $event->getArgument('user');
if(!$user instanceof IUser) {
if (!$user instanceof IUser) {
throw new \UnexpectedValueException("'$user' is not an instance of IUser.");
}
return $user;
Expand Down Expand Up @@ -319,7 +319,7 @@ public function checkAdminRequestedPasswordChange(GenericEvent $event) {
public function checkForcePasswordChangeOnFirstLogin(GenericEvent $event) {
$this->fixDI();
$user = $event->getSubject();
if(!$user instanceof IUser) {
if (!$user instanceof IUser) {
throw new \UnexpectedValueException("'$user' is not an instance of IUser.");
}
// If option is enabled in security settings check first login
Expand Down
2 changes: 0 additions & 2 deletions lib/Rules/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,4 @@ class Base {
public function __construct(IL10N $l10n) {
$this->l10n = $l10n;
}

}

1 change: 0 additions & 1 deletion lib/Rules/Length.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,4 @@ public function verify($password, $val) {
$this->l10n->t('The password is too short. At least %d characters are required.', [$val]));
}
}

}
1 change: 0 additions & 1 deletion lib/Rules/Lowercase.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,4 @@ private function countLowercase($s) {
}
return $count;
}

}
4 changes: 2 additions & 2 deletions lib/Rules/Numbers.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function verify($password, $val) {
}
}

private function countDigits( $str ) {
return \preg_match_all( '/[0-9]/', $str );
private function countDigits($str) {
return \preg_match_all('/[0-9]/', $str);
}
}
4 changes: 2 additions & 2 deletions lib/Rules/PasswordHistory.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@ public function __construct(
* @throws PolicyException
*/
public function verify($password, $val, $uid) {
if(empty($uid)) {
if (empty($uid)) {
return;
}
$oldPasswords = $this->mapper->getOldPasswords(
$uid,
$val
);
foreach($oldPasswords as $oldPassword) {
foreach ($oldPasswords as $oldPassword) {
if ($this->hasher->verify($password, $oldPassword->getPassword())) {
throw new PolicyException(
$this->l10n->t('The password must be different than your previous %d passwords.', [$val])
Expand Down
8 changes: 3 additions & 5 deletions lib/Rules/Special.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function verify($password, $val, $allowedSpecialChars) {
$special = $this->stripAlphaNumeric($password);
if (!empty($allowedSpecialChars) && !empty($special)) {
$allowedSpecialCharsAsArray = \str_split($allowedSpecialChars);
$s = \array_filter(\str_split($special), function($char) use ($allowedSpecialCharsAsArray){
$s = \array_filter(\str_split($special), function ($char) use ($allowedSpecialCharsAsArray) {
return !\in_array($char, $allowedSpecialCharsAsArray, true);
});
if (\count($s) > 0) {
Expand Down Expand Up @@ -63,9 +63,7 @@ public function verify($password, $val, $allowedSpecialChars) {
}
}

private function stripAlphaNumeric( $string ) {
return \preg_replace( '/[a-z0-9]/i', '', $string );
private function stripAlphaNumeric($string) {
return \preg_replace('/[a-z0-9]/i', '', $string);
}

}

1 change: 0 additions & 1 deletion lib/Rules/Uppercase.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,4 @@ private function countUppercase($s) {
}
return $count;
}

}
4 changes: 3 additions & 1 deletion templates/password.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@
?>
</div>
</h1>
<?php if (isset($_['error'])) { ?><div id="error" class="warning"><?php p($_['error']) ?></div> <?php } ?>
<?php if (isset($_['error'])) {
?><div id="error" class="warning"><?php p($_['error']) ?></div> <?php
} ?>
<input type="hidden" name="redirect_url" value="<?php p($_['redirect_url']) ?>" />
<input type="hidden" name="app" value="oca-password-policy" />
<input type="hidden" name="requesttoken" value="<?php p($_['requesttoken']) ?>" id="requesttoken">
Expand Down

0 comments on commit 9467ac3

Please sign in to comment.