Completed
Push — master ( 5873a0...ffe254 )
by Björn
33:28 queued 24:09
created

OCSController::getIdentityProof()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 8
nc 2
nop 1
dl 0
loc 13
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 *
4
 * @author Roeland Jago Douma <[email protected]>
5
 *
6
 * @license GNU AGPL version 3 or any later version
7
 *
8
 * This program is free software: you can redistribute it and/or modify
9
 * it under the terms of the GNU Affero General Public License as
10
 * published by the Free Software Foundation, either version 3 of the
11
 * License, or (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU Affero General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU Affero General Public License
19
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
 *
21
 */
22
namespace OC\Core\Controller;
23
24
use OC\CapabilitiesManager;
25
use OC\Security\Bruteforce\Throttler;
26
use OC\Security\IdentityProof\Manager;
27
use OCP\AppFramework\Http\DataResponse;
28
use OCP\IRequest;
29
use OCP\IUserManager;
30
use OCP\IUserSession;
31
32
class OCSController extends \OCP\AppFramework\OCSController {
33
34
	/** @var CapabilitiesManager */
35
	private $capabilitiesManager;
36
	/** @var IUserSession */
37
	private $userSession;
38
	/** @var IUserManager */
39
	private $userManager;
40
	/** @var Manager */
41
	private $keyManager;
42
	/** @var Throttler */
43
	private $throttler;
44
45
	/**
46
	 * OCSController constructor.
47
	 *
48
	 * @param string $appName
49
	 * @param IRequest $request
50
	 * @param CapabilitiesManager $capabilitiesManager
51
	 * @param IUserSession $userSession
52
	 * @param IUserManager $userManager
53
	 * @param Throttler $throttler
54
	 * @param Manager $keyManager
55
	 */
56
	public function __construct($appName,
57
								IRequest $request,
58
								CapabilitiesManager $capabilitiesManager,
59
								IUserSession $userSession,
60
								IUserManager $userManager,
61
								Throttler $throttler,
62
								Manager $keyManager) {
63
		parent::__construct($appName, $request);
64
		$this->capabilitiesManager = $capabilitiesManager;
65
		$this->userSession = $userSession;
66
		$this->userManager = $userManager;
67
		$this->throttler = $throttler;
68
		$this->keyManager = $keyManager;
69
	}
70
71
	/**
72
	 * @PublicPage
73
	 *
74
	 * @return DataResponse
75
	 */
76
	public function getConfig() {
77
		$data = [
78
			'version' => '1.7',
79
			'website' => 'Nextcloud',
80
			'host' => $this->request->getServerHost(),
81
			'contact' => '',
82
			'ssl' => 'false',
83
		];
84
85
		return new DataResponse($data);
86
	}
87
88
	/**
89
	 * @NoAdminRequired
90
	 * @return DataResponse
91
	 */
92
	public function getCapabilities() {
93
		$result = [];
94
		list($major, $minor, $micro) = \OCP\Util::getVersion();
95
		$result['version'] = array(
96
			'major' => $major,
97
			'minor' => $minor,
98
			'micro' => $micro,
99
			'string' => \OC_Util::getVersionString(),
100
			'edition' => '',
101
		);
102
103
		$result['capabilities'] = $this->capabilitiesManager->getCapabilities();
104
105
		return new DataResponse($result);
106
	}
107
108
	/**
109
	 * @PublicPage
110
	 *
111
	 * @param string $login
112
	 * @param string $password
113
	 * @return DataResponse
114
	 */
115
	public function personCheck($login = '', $password = '') {
116
		if ($login !== '' && $password !== '') {
117
			$this->throttler->sleepDelay($this->request->getRemoteAddress(), 'login');
118
			if ($this->userManager->checkPassword($login, $password)) {
119
				return new DataResponse([
120
					'person' => [
121
						'personid' => $login
122
					]
123
				]);
124
			}
125
			$this->throttler->registerAttempt('login', $this->request->getRemoteAddress());
126
			return new DataResponse(null, 102);
0 ignored issues
show
Documentation introduced by
null is of type null, but the function expects a array|object.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
127
		}
128
		return new DataResponse(null, 101);
0 ignored issues
show
Documentation introduced by
null is of type null, but the function expects a array|object.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
129
	}
130
131
	/**
132
	 * @PublicPage
133
	 *
134
	 * @param string $cloudId
135
	 * @return DataResponse
136
	 */
137
	public function getIdentityProof($cloudId) {
138
		$userObject = $this->userManager->get($cloudId);
139
140
		if($userObject !== null) {
141
			$key = $this->keyManager->getKey($userObject);
142
			$data = [
143
				'public' => $key->getPublic(),
144
			];
145
			return new DataResponse($data);
146
		}
147
148
		return new DataResponse('User not found', 404);
0 ignored issues
show
Documentation introduced by
'User not found' is of type string, but the function expects a array|object.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
149
	}
150
}
151