This repository has been archived by the owner on Jan 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #113 from nextcloud/enhancement/php7
Make app strict
- Loading branch information
Showing
12 changed files
with
68 additions
and
122 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,8 +1,10 @@ | ||
<?php | ||
|
||
declare(strict_types = 1); | ||
|
||
/** | ||
* @author Christoph Wurst <[email protected]> | ||
* @copyright Copyright (c) 2016 Christoph Wurst <[email protected]> | ||
* @copyright Copyright (c) 2018 Christoph Wurst <[email protected]> | ||
* | ||
* Two-factor U2F | ||
* | ||
|
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 |
---|---|---|
@@ -1,8 +1,10 @@ | ||
<?php | ||
|
||
declare(strict_types = 1); | ||
|
||
/** | ||
* @author Christoph Wurst <[email protected]> | ||
* @copyright Copyright (c) 2016 Christoph Wurst <[email protected]> | ||
* @copyright Copyright (c) 2018 Christoph Wurst <[email protected]> | ||
* | ||
* Two-factor U2F | ||
* | ||
|
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 |
---|---|---|
@@ -1,13 +1,15 @@ | ||
<?php | ||
|
||
declare(strict_types = 1); | ||
|
||
/** | ||
* Nextcloud - U2F 2FA | ||
* | ||
* This file is licensed under the Affero General Public License version 3 or | ||
* later. See the COPYING file. | ||
* | ||
* @author Christoph Wurst <[email protected]> | ||
* @copyright Christoph Wurst 2016 | ||
* @copyright Christoph Wurst 2018 | ||
*/ | ||
|
||
namespace OCA\TwoFactorU2F\Controller; | ||
|
@@ -28,36 +30,28 @@ class SettingsController extends Controller { | |
/** @var IUserSession */ | ||
private $userSession; | ||
|
||
/** | ||
* @param string $appName | ||
* @param IRequest $request | ||
* @param U2FManager $manager | ||
* @param IUserSession $userSession | ||
*/ | ||
public function __construct($appName, IRequest $request, U2FManager $manager, IUserSession $userSession) { | ||
public function __construct(string $appName, IRequest $request, U2FManager $manager, IUserSession $userSession) { | ||
parent::__construct($appName, $request); | ||
$this->manager = $manager; | ||
$this->userSession = $userSession; | ||
} | ||
|
||
/** | ||
* @NoAdminRequired | ||
* @return JSONResponse | ||
*/ | ||
public function state() { | ||
return [ | ||
public function state(): JSONResponse { | ||
return new JSONResponse([ | ||
'devices' => $this->manager->getDevices($this->userSession->getUser()) | ||
]; | ||
]); | ||
} | ||
|
||
/** | ||
* @NoAdminRequired | ||
* @PasswordConfirmationRequired | ||
* @UseSession | ||
* @return JSONResponse | ||
*/ | ||
public function startRegister() { | ||
return $this->manager->startRegistration($this->userSession->getUser()); | ||
public function startRegister(): JSONResponse { | ||
return new JSONResponse($this->manager->startRegistration($this->userSession->getUser())); | ||
} | ||
|
||
/** | ||
|
@@ -67,21 +61,19 @@ public function startRegister() { | |
* @param string $registrationData | ||
* @param string $clientData | ||
* @param string|null $name device name, given by user | ||
* @return JSONResponse | ||
*/ | ||
public function finishRegister($registrationData, $clientData, $name = null) { | ||
return $this->manager->finishRegistration($this->userSession->getUser(), $registrationData, $clientData, $name); | ||
public function finishRegister(string $registrationData, string $clientData, string $name = null): JSONResponse { | ||
return new JSONResponse($this->manager->finishRegistration($this->userSession->getUser(), $registrationData, $clientData, $name)); | ||
} | ||
|
||
/** | ||
* @NoAdminRequired | ||
* @PasswordConfirmationRequired | ||
* | ||
* @param int $id | ||
* @return JSONResponse | ||
*/ | ||
public function remove($id) { | ||
return $this->manager->removeDevice($this->userSession->getUser(), $id); | ||
public function remove(int $id): JSONResponse { | ||
return new JSONResponse($this->manager->removeDevice($this->userSession->getUser(), $id)); | ||
} | ||
|
||
} |
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 |
---|---|---|
@@ -1,13 +1,15 @@ | ||
<?php | ||
|
||
declare(strict_types = 1); | ||
|
||
/** | ||
* Nextcloud - U2F 2FA | ||
* | ||
* This file is licensed under the Affero General Public License version 3 or | ||
* later. See the COPYING file. | ||
* | ||
* @author Christoph Wurst <[email protected]> | ||
* @copyright Christoph Wurst 2016 | ||
* @copyright Christoph Wurst 2018 | ||
*/ | ||
|
||
namespace OCA\TwoFactorU2F\Db; | ||
|
@@ -38,7 +40,7 @@ class Registration extends Entity implements JsonSerializable { | |
protected $counter; | ||
protected $name; | ||
|
||
public function jsonSerialize() { | ||
public function jsonSerialize(): array { | ||
return [ | ||
'id' => $this->getId(), | ||
'userId' => $this->getUserId(), | ||
|
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 |
---|---|---|
@@ -1,13 +1,15 @@ | ||
<?php | ||
|
||
declare(strict_types = 1); | ||
|
||
/** | ||
* Nextcloud - U2F 2FA | ||
* | ||
* This file is licensed under the Affero General Public License version 3 or | ||
* later. See the COPYING file. | ||
* | ||
* @author Christoph Wurst <[email protected]> | ||
* @copyright Christoph Wurst 2016 | ||
* @copyright Christoph Wurst 2018 | ||
*/ | ||
|
||
namespace OCA\TwoFactorU2F\Db; | ||
|
@@ -26,9 +28,8 @@ public function __construct(IDBConnection $db) { | |
/** | ||
* @param IUser $user | ||
* @param int $id | ||
* @return Registration | ||
*/ | ||
public function findRegistration(IUser $user, $id) { | ||
public function findRegistration(IUser $user, $id): Registration { | ||
/* @var $qb IQueryBuilder */ | ||
$qb = $this->db->getQueryBuilder(); | ||
|
||
|
@@ -48,7 +49,7 @@ public function findRegistration(IUser $user, $id) { | |
* @param IUser $user | ||
* @return Registration[] | ||
*/ | ||
public function findRegistrations(IUser $user) { | ||
public function findRegistrations(IUser $user): array { | ||
/* @var $qb IQueryBuilder */ | ||
$qb = $this->db->getQueryBuilder(); | ||
|
||
|
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 |
---|---|---|
@@ -1,13 +1,15 @@ | ||
<?php | ||
|
||
declare(strict_types = 1); | ||
|
||
/** | ||
* Nextcloud - U2F 2FA | ||
* | ||
* This file is licensed under the Affero General Public License version 3 or | ||
* later. See the COPYING file. | ||
* | ||
* @author Christoph Wurst <[email protected]> | ||
* @copyright Christoph Wurst 2016 | ||
* @copyright Christoph Wurst 2018 | ||
*/ | ||
|
||
namespace OCA\TwoFactorU2F\Provider; | ||
|
@@ -26,49 +28,36 @@ class U2FProvider implements IProvider { | |
/** @var U2FManager */ | ||
private $manager; | ||
|
||
/** | ||
* @param IL10N $l10n | ||
* @param U2FManager $manager | ||
*/ | ||
public function __construct(IL10N $l10n, U2FManager $manager) { | ||
$this->l10n = $l10n; | ||
$this->manager = $manager; | ||
} | ||
|
||
/** | ||
* Get unique identifier of this 2FA provider | ||
* | ||
* @return string | ||
*/ | ||
public function getId() { | ||
public function getId(): string { | ||
return 'u2f'; | ||
} | ||
|
||
/** | ||
* Get the display name for selecting the 2FA provider | ||
* | ||
* @return string | ||
*/ | ||
public function getDisplayName() { | ||
public function getDisplayName(): string { | ||
return 'U2F device'; | ||
} | ||
|
||
/** | ||
* Get the description for selecting the 2FA provider | ||
* | ||
* @return string | ||
*/ | ||
public function getDescription() { | ||
public function getDescription(): string { | ||
return $this->l10n->t('Authenticate with an U2F device'); | ||
} | ||
|
||
/** | ||
* Get the template for rending the 2FA provider view | ||
* | ||
* @param IUser $user | ||
* @return Template | ||
*/ | ||
public function getTemplate(IUser $user) { | ||
public function getTemplate(IUser $user): Template { | ||
$reqs = $this->manager->startAuthenticate($user); | ||
|
||
$tmpl = new Template('twofactor_u2f', 'challenge'); | ||
|
@@ -79,20 +68,16 @@ public function getTemplate(IUser $user) { | |
/** | ||
* Verify the given challenge | ||
* | ||
* @param IUser $user | ||
* @param string $challenge | ||
*/ | ||
public function verifyChallenge(IUser $user, $challenge) { | ||
public function verifyChallenge(IUser $user, $challenge): bool { | ||
return $this->manager->finishAuthenticate($user, $challenge); | ||
} | ||
|
||
/** | ||
* Decides whether 2FA is enabled for the given user | ||
* | ||
* @param IUser $user | ||
* @return boolean | ||
*/ | ||
public function isTwoFactorAuthEnabledForUser(IUser $user) { | ||
public function isTwoFactorAuthEnabledForUser(IUser $user): bool { | ||
return count($this->manager->getDevices($user)) > 0; | ||
} | ||
|
||
|
Oops, something went wrong.