Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

composer.phar
/vendor/
/node_modules

/js

/tests/clover.xml

4 changes: 4 additions & 0 deletions appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,8 @@
<commands>
<command>OCA\TwoFactorAdmin\Command\Generate</command>
</commands>

<settings>
<admin>OCA\TwoFactorAdmin\Settings\AdminSettings</admin>
</settings>
</info>
34 changes: 34 additions & 0 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

declare(strict_types=1);

/**
* @copyright 2019 Christoph Wurst <christoph@winzerhof-wurst.at>
*
* @author 2019 Christoph Wurst <christoph@winzerhof-wurst.at>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

return [
'routes' => [
[
'name' => 'adminCode#create',
'url' => '/api/admin/code',
'verb' => 'POST'
],
]
];
3 changes: 3 additions & 0 deletions krankerl.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
[package]
before_cmds = [
"composer install --no-dev -o",
"npm i",
"npm run build",
]

exclude = [
Expand All @@ -23,6 +25,7 @@ exclude = [
"phpunit*xml",
"screenshots",
".scrutinizer.yml",
"src",
"tests",
".travis.yml",
".tx",
Expand Down
4 changes: 3 additions & 1 deletion lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@

class Application extends App {

public const APP_ID = 'twofactor_admin';

public function __construct(array $urlParams = []) {
parent::__construct('twofactor_admin', $urlParams);
parent::__construct(self::APP_ID, $urlParams);

$container = $this->getContainer();

Expand Down
71 changes: 71 additions & 0 deletions lib/Controller/AdminCodeController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php

declare(strict_types=1);

/**
* @copyright 2019 Christoph Wurst <christoph@winzerhof-wurst.at>
*
* @author 2019 Christoph Wurst <christoph@winzerhof-wurst.at>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

namespace OCA\TwoFactorAdmin\Controller;

use OCA\TwoFactorAdmin\AppInfo\Application;
use OCA\TwoFactorAdmin\Service\CodeStorage;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\JSONResponse;
use OCP\IRequest;
use OCP\IUserManager;

class AdminCodeController extends Controller {

/** @var IUserManager */
private $userManager;

/** @var CodeStorage */
private $codeStorage;

public function __construct(IRequest $request,
IUserManager $userManager,
CodeStorage $codeStorage) {
parent::__construct(Application::APP_ID, $request);
$this->codeStorage = $codeStorage;
$this->userManager = $userManager;
}

/**
* @param string $uid
*
* @return JSONResponse
*/
public function create(string $uid): JSONResponse {
$user = $this->userManager->get($uid);

if ($user === null) {
return new JSONResponse(null, Http::STATUS_NOT_FOUND);
}

return new JSONResponse([
'code' => $this->codeStorage->generateCode($user),
'validFor' => CodeStorage::CODE_TTL,
]);
}

}

46 changes: 46 additions & 0 deletions lib/Settings/AdminSettings.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

declare(strict_types=1);

/**
* @copyright 2019 Christoph Wurst <christoph@winzerhof-wurst.at>
*
* @author 2019 Christoph Wurst <christoph@winzerhof-wurst.at>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

namespace OCA\TwoFactorAdmin\Settings;

use OCA\TwoFactorAdmin\AppInfo\Application;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\Settings\ISettings;

class AdminSettings implements ISettings {

public function getForm() {
return new TemplateResponse(Application::APP_ID, 'settings-admin');
}

public function getSection() {
return 'security';
}

public function getPriority() {
return 90;
}

}
Loading