1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<?php
class SabreAuthenticationJsonBackend extends \Sabre\DAV\Auth\Backend\AbstractBasic {
protected $userMgr;
function __construct(UserManager $userMgr) {
$this->userMgr = $userMgr;
}
protected function validateUserPass($username, $password) {
$userAccount = $this->userMgr->get($username);
if (!$userAccount) {
return false;
}
if (!password_verify($password, $userAccount['password'])) {
return false;
}
if (!$userAccount['active']) {
return false;
}
return true;
}
function challenge(\Sabre\HTTP\RequestInterface $request, \Sabre\HTTP\ResponseInterface $response) {
parent::challenge($request, $response);
if ('XMLHttpRequest' === $request->getHeader('X-Requested-With')) {
$response->removeHeader('WWW-Authenticate');
}
}
}