Passed
Push — master ( 50dbde...ac9260 )
by Morris
12:33
created

WipeController::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 3
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * @copyright Copyright (c) 2019, Roeland Jago Douma <[email protected]>
7
 *
8
 * @author Roeland Jago Douma <[email protected]>
9
 *
10
 * @license GNU AGPL version 3 or any later version
11
 *
12
 * This program is free software: you can redistribute it and/or modify
13
 * it under the terms of the GNU Affero General Public License as
14
 * published by the Free Software Foundation, either version 3 of the
15
 * License, or (at your option) any later version.
16
 *
17
 * This program is distributed in the hope that it will be useful,
18
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
 * GNU Affero General Public License for more details.
21
 *
22
 * You should have received a copy of the GNU Affero General Public License
23
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
24
 *
25
 */
26
27
namespace OC\Core\Controller;
28
29
use OC\Authentication\Exceptions\InvalidTokenException;
30
use OC\Authentication\Token\RemoteWipe;
31
use OCP\AppFramework\Controller;
32
use OCP\AppFramework\Http;
33
use OCP\AppFramework\Http\JSONResponse;
34
use OCP\IRequest;
35
36
class WipeController extends Controller {
37
38
	/** @var RemoteWipe */
39
	private $remoteWipe;
40
41
	public function __construct(string $appName,
42
								IRequest $request,
43
								RemoteWipe $remoteWipe) {
44
		parent::__construct($appName, $request);
45
46
		$this->remoteWipe = $remoteWipe;
47
	}
48
49
	/**
50
	 * @NoAdminRequired
51
	 * @NoCSRFRequired
52
	 * @PublicPage
53
	 *
54
	 * @AnonRateThrottle(limit=10, period=300)
55
	 *
56
	 * @param string $token
57
	 *
58
	 * @return JSONResponse
59
	 */
60
	public function checkWipe(string $token): JSONResponse {
61
		try {
62
			if ($this->remoteWipe->start($token)) {
63
				return new JSONResponse([
64
					'wipe' => true
65
				]);
66
			}
67
68
			return new JSONResponse([], Http::STATUS_NOT_FOUND);
69
		} catch (InvalidTokenException $e) {
70
			return new JSONResponse([], Http::STATUS_NOT_FOUND);
71
		}
72
	}
73
74
75
	/**
76
	 * @NoAdminRequired
77
	 * @NoCSRFRequired
78
	 * @PublicPage
79
	 *
80
	 * @AnonRateThrottle(limit=10, period=300)
81
	 *
82
	 * @param string $token
83
	 *
84
	 * @return JSONResponse
85
	 */
86
	public function wipeDone(string $token): JSONResponse {
87
		try {
88
			if ($this->remoteWipe->finish($token)) {
89
				return new JSONResponse([]);
90
			}
91
92
			return new JSONResponse([], Http::STATUS_NOT_FOUND);
93
		} catch (InvalidTokenException $e) {
94
			return new JSONResponse([], Http::STATUS_NOT_FOUND);
95
		}
96
	}
97
98
}
99