added authentication via api key for some limited api methods (fix #64)

This commit is contained in:
Athou
2013-05-01 21:56:59 +02:00
parent 52a8ea1920
commit 5dcc923cf1
14 changed files with 148 additions and 40 deletions

View File

@@ -184,10 +184,11 @@ function($scope, $timeout, $stateParams, $window, $location, $state, $route, Cat
});
}]);
module.controller('FeedDetailsCtrl', ['$scope', '$state', '$stateParams', 'FeedService', 'CategoryService', '$dialog',
function($scope, $state, $stateParams, FeedService, CategoryService, $dialog) {
module.controller('FeedDetailsCtrl', ['$scope', '$state', '$stateParams', 'FeedService', 'CategoryService', 'ProfileService', '$dialog',
function($scope, $state, $stateParams, FeedService, CategoryService, ProfileService, $dialog) {
$scope.CategoryService = CategoryService;
$scope.user = ProfileService.get();
$scope.sub = FeedService.get({
id : $stateParams._id
@@ -250,9 +251,10 @@ module.controller('FeedDetailsCtrl', ['$scope', '$state', '$stateParams', 'FeedS
};
}]);
module.controller('CategoryDetailsCtrl', ['$scope', '$state', '$stateParams', 'FeedService', 'CategoryService', '$dialog',
function($scope, $state, $stateParams, FeedService, CategoryService, $dialog) {
module.controller('CategoryDetailsCtrl', ['$scope', '$state', '$stateParams', 'FeedService', 'CategoryService', 'ProfileService', '$dialog',
function($scope, $state, $stateParams, FeedService, CategoryService, ProfileService, $dialog) {
$scope.CategoryService = CategoryService;
$scope.user = ProfileService.get();
$scope.isMeta = function() {
return parseInt($stateParams._id, 10) != $stateParams._id;
@@ -264,7 +266,7 @@ module.controller('CategoryDetailsCtrl', ['$scope', '$state', '$stateParams', 'F
return elem.id != $scope.category.id;
};
CategoryService.get(function() {
CategoryService.init(function() {
if ($scope.isMeta()) {
$scope.category = {
id : $stateParams._id,
@@ -785,7 +787,8 @@ function($scope, $location, ProfileService, AnalyticsService) {
}
var o = {
email : $scope.user.email,
password : $scope.user.password
password : $scope.user.password,
newApiKey : $scope.newApiKey
};
ProfileService.save(o, function() {

View File

@@ -24,7 +24,8 @@
<div class="control-group">
<label class="control-label">Feed URL</label>
<div class="controls horizontal-align">
<a href="{{'rest/category/entriesAsFeed?id=' + category.id}}" target="_blank">{{'rest/category/entriesAsFeed?id=' + category.id}}</a>
<a ng-show="user.apiKey" href="{{'rest/category/entriesAsFeed?id=' + category.id + '&apiKey=' + user.apiKey}}" target="_blank">link</a>
<span ng-show="!user.apiKey">Generate an API key in your profile first.</span>
</div>
</div>

View File

@@ -37,7 +37,8 @@
<div class="control-group">
<label class="control-label">Feed URL</label>
<div class="controls horizontal-align">
<a href="{{'rest/feed/entriesAsFeed?id=' + sub.id}}" target="_blank">{{'rest/feed/entriesAsFeed?id=' + sub.id}}</a>
<a ng-show="user.apiKey" href="{{'rest/feed/entriesAsFeed?id=' + sub.id + '&apiKey=' + user.apiKey}}" target="_blank">link</a>
<span ng-show="!user.apiKey">Generate an API key in your profile first.</span>
</div>
</div>

View File

@@ -31,6 +31,21 @@
<span class="help-inline" ng-show="profileForm.password_c.$error.validator">Passwords do not match</span>
</div>
</div>
<div class="control-group">
<label class="control-label" for="password">API key</label>
<div class="controls horizontal-align">
<span ng-show="user.apiKey">{{user.apiKey}}</span>
<span ng-show="!user.apiKey">Not generated yet</span>
</div>
</div>
<div class="control-group">
<label class="control-label" for="password">Generate new API key</label>
<div class="controls">
<input type="checkbox" name="newApiKey" id="newApiKey" ng-model="newApiKey">
<span class="help-block">Changing password will generate a new API key</span>
</div>
</div>
<div class="form-actions">
<button type="submit" class="btn btn-primary">Save</button>