parent
357d342467
commit
12431aa399
@ -0,0 +1,71 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* @author Christoph Wurst <christoph@owncloud.com> |
||||
* |
||||
* @copyright Copyright (c) 2016, ownCloud, Inc. |
||||
* @license AGPL-3.0 |
||||
* |
||||
* This code is free software: you can redistribute it and/or modify |
||||
* it under the terms of the GNU Affero General Public License, version 3, |
||||
* as published by the Free Software Foundation. |
||||
* |
||||
* 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, version 3, |
||||
* along with this program. If not, see <http://www.gnu.org/licenses/> |
||||
* |
||||
*/ |
||||
|
||||
namespace OC\Settings\Controller; |
||||
|
||||
use OC\Authentication\Token\IProvider; |
||||
use OCP\AppFramework\Controller; |
||||
use OCP\AppFramework\Http\JSONResponse; |
||||
use OCP\IRequest; |
||||
use OCP\IUserManager; |
||||
|
||||
class AuthSettingsController extends Controller { |
||||
|
||||
/** @var IProvider */ |
||||
private $tokenProvider; |
||||
|
||||
/** |
||||
* @var IUserManager |
||||
*/ |
||||
private $userManager; |
||||
|
||||
/** @var string */ |
||||
private $uid; |
||||
|
||||
/** |
||||
* @param string $appName |
||||
* @param IRequest $request |
||||
* @param IProvider $tokenProvider |
||||
* @param IUserManager $userManager |
||||
* @param string $uid |
||||
*/ |
||||
public function __construct($appName, IRequest $request, IProvider $tokenProvider, IUserManager $userManager, $uid) { |
||||
parent::__construct($appName, $request); |
||||
$this->tokenProvider = $tokenProvider; |
||||
$this->userManager = $userManager; |
||||
$this->uid = $uid; |
||||
} |
||||
|
||||
/** |
||||
* @NoAdminRequired |
||||
* |
||||
* @return JSONResponse |
||||
*/ |
||||
public function index() { |
||||
$user = $this->userManager->get($this->uid); |
||||
if (is_null($user)) { |
||||
return []; |
||||
} |
||||
return $this->tokenProvider->getTokenByUser($user); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,33 @@ |
||||
/* global Backbone */ |
||||
|
||||
/** |
||||
* @author Christoph Wurst <christoph@owncloud.com> |
||||
* |
||||
* @copyright Copyright (c) 2016, ownCloud, Inc. |
||||
* @license AGPL-3.0 |
||||
* |
||||
* This code is free software: you can redistribute it and/or modify |
||||
* it under the terms of the GNU Affero General Public License, version 3, |
||||
* as published by the Free Software Foundation. |
||||
* |
||||
* 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, version 3, |
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
* |
||||
*/ |
||||
|
||||
(function(OC, Backbone) { |
||||
'use strict'; |
||||
|
||||
OC.Settings = OC.Settings || {}; |
||||
|
||||
var AuthToken = Backbone.Model.extend({ |
||||
}); |
||||
|
||||
OC.Settings.AuthToken = AuthToken; |
||||
|
||||
})(OC, Backbone); |
@ -0,0 +1,36 @@ |
||||
/* global Backbone */ |
||||
|
||||
/** |
||||
* @author Christoph Wurst <christoph@owncloud.com> |
||||
* |
||||
* @copyright Copyright (c) 2016, ownCloud, Inc. |
||||
* @license AGPL-3.0 |
||||
* |
||||
* This code is free software: you can redistribute it and/or modify |
||||
* it under the terms of the GNU Affero General Public License, version 3, |
||||
* as published by the Free Software Foundation. |
||||
* |
||||
* 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, version 3, |
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
* |
||||
*/ |
||||
|
||||
(function(OC, Backbone) { |
||||
'use strict'; |
||||
|
||||
OC.Settings = OC.Settings || {}; |
||||
|
||||
var AuthTokenCollection = Backbone.Collection.extend({ |
||||
model: OC.Settings.AuthToken, |
||||
tokenType: null, |
||||
url: OC.generateUrl('/settings/personal/authtokens'), |
||||
}); |
||||
|
||||
OC.Settings.AuthTokenCollection = AuthTokenCollection; |
||||
|
||||
})(OC, Backbone); |
@ -0,0 +1,93 @@ |
||||
/* global Backbone, Handlebars */ |
||||
|
||||
/** |
||||
* @author Christoph Wurst <christoph@owncloud.com> |
||||
* |
||||
* @copyright Copyright (c) 2016, ownCloud, Inc. |
||||
* @license AGPL-3.0 |
||||
* |
||||
* This code is free software: you can redistribute it and/or modify |
||||
* it under the terms of the GNU Affero General Public License, version 3, |
||||
* as published by the Free Software Foundation. |
||||
* |
||||
* 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, version 3, |
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
* |
||||
*/ |
||||
|
||||
(function(OC, _, Backbone, $, Handlebars) { |
||||
'use strict'; |
||||
|
||||
OC.Settings = OC.Settings || {}; |
||||
|
||||
var TEMPLATE_TOKEN = |
||||
'<tr>' |
||||
+ '<td>{{name}}</td>' |
||||
+ '<td>{{lastActivity}}</td>' |
||||
+ '<tr>'; |
||||
|
||||
var SubView = Backbone.View.extend({ |
||||
collection: null, |
||||
type: 0, |
||||
template: Handlebars.compile(TEMPLATE_TOKEN), |
||||
initialize: function(options) { |
||||
this.type = options.type; |
||||
this.collection = options.collection; |
||||
}, |
||||
render: function() { |
||||
var _this = this; |
||||
|
||||
var list = this.$el.find('.token-list'); |
||||
var tokens = this.collection.filter(function(token) { |
||||
return parseInt(token.get('type')) === _this.type; |
||||
}); |
||||
list.removeClass('icon-loading'); |
||||
list.html(''); |
||||
|
||||
tokens.forEach(function(token) { |
||||
var html = _this.template(token.toJSON()); |
||||
list.append(html); |
||||
}); |
||||
}, |
||||
}); |
||||
|
||||
var AuthTokenView = Backbone.View.extend({ |
||||
collection: null, |
||||
views |
||||
: [], |
||||
initialize: function(options) { |
||||
this.collection = options.collection; |
||||
|
||||
var tokenTypes = [0, 1]; |
||||
var _this = this; |
||||
_.each(tokenTypes, function(type) { |
||||
_this.views.push(new SubView({ |
||||
el: type === 0 ? '#sessions' : '#devices', |
||||
type: type, |
||||
collection: _this.collection |
||||
})); |
||||
}); |
||||
}, |
||||
render: function() { |
||||
_.each(this.views, function(view) { |
||||
view.render(); |
||||
}); |
||||
}, |
||||
reload: function() { |
||||
var loadingTokens = this.collection.fetch(); |
||||
|
||||
var _this = this; |
||||
$.when(loadingTokens).done(function() { |
||||
_this.render(); |
||||
}); |
||||
} |
||||
}); |
||||
|
||||
OC.Settings.AuthTokenView = AuthTokenView; |
||||
|
||||
})(OC, _, Backbone, $, Handlebars); |
@ -0,0 +1,66 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* @author Christoph Wurst <christoph@owncloud.com> |
||||
* |
||||
* @copyright Copyright (c) 2016, ownCloud, Inc. |
||||
* @license AGPL-3.0 |
||||
* |
||||
* This code is free software: you can redistribute it and/or modify |
||||
* it under the terms of the GNU Affero General Public License, version 3, |
||||
* as published by the Free Software Foundation. |
||||
* |
||||
* 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, version 3, |
||||
* along with this program. If not, see <http://www.gnu.org/licenses/> |
||||
* |
||||
*/ |
||||
|
||||
namespace Test\Settings\Controller; |
||||
|
||||
use OC\Settings\Controller\AuthSettingsController; |
||||
use Test\TestCase; |
||||
|
||||
class AuthSettingsControllerTest extends TestCase { |
||||
|
||||
/** @var AuthSettingsController */ |
||||
private $controller; |
||||
private $request; |
||||
private $tokenProvider; |
||||
private $userManager; |
||||
private $uid; |
||||
|
||||
protected function setUp() { |
||||
parent::setUp(); |
||||
|
||||
$this->request = $this->getMock('\OCP\IRequest'); |
||||
$this->tokenProvider = $this->getMock('\OC\Authentication\Token\IProvider'); |
||||
$this->userManager = $this->getMock('\OCP\IUserManager'); |
||||
$this->uid = 'jane'; |
||||
$this->user = $this->getMock('\OCP\IUser'); |
||||
|
||||
$this->controller = new AuthSettingsController('core', $this->request, $this->tokenProvider, $this->userManager, $this->uid); |
||||
} |
||||
|
||||
public function testIndex() { |
||||
$result = [ |
||||
'token1', |
||||
'token2', |
||||
]; |
||||
$this->userManager->expects($this->once()) |
||||
->method('get') |
||||
->with($this->uid) |
||||
->will($this->returnValue($this->user)); |
||||
$this->tokenProvider->expects($this->once()) |
||||
->method('getTokenByUser') |
||||
->with($this->user) |
||||
->will($this->returnValue($result)); |
||||
|
||||
$this->assertEquals($result, $this->controller->index()); |
||||
} |
||||
|
||||
} |
Loading…
Reference in new issue