Bringing Account information to the API.
parent
8c4b7b3bf0
commit
83bda92684
File diff suppressed because one or more lines are too long
|
@ -55,8 +55,10 @@
|
|||
|
||||
var promise = $http({
|
||||
method: 'GET',
|
||||
url: '/api/account/',
|
||||
headers: {}
|
||||
url: '/api/private/profile/' + window.user_profile_id + '/',
|
||||
headers: {
|
||||
'Authorization': 'ApiKey ' + window.user + ':' + window.api_key
|
||||
}
|
||||
});
|
||||
|
||||
return promise;
|
||||
|
@ -71,7 +73,7 @@
|
|||
$scope.route = $route;
|
||||
|
||||
AccountStorage.getAccount().then(function(response) {
|
||||
console.log(response);
|
||||
$scope.user = response.data;
|
||||
});
|
||||
};
|
||||
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
|
||||
(function(){if(typeof angular!=='undefined'){var root=this;var $=root.jQuery;var app=angular.module('Account',[],function($routeProvider,$locationProvider){$locationProvider.html5Mode(true);$routeProvider.when('/account/',{templateUrl:'/media/js/src/modules/partials/profile.html',controller:controllers.ProfileController});$routeProvider.when('/account/billing/',{templateUrl:'/media/js/src/modules/partials/billing.html',controller:controllers.BillingController});$routeProvider.when('/account/blogging/',{templateUrl:'/media/js/src/modules/partials/blogging.html',controller:controllers.BloggingController});$routeProvider.when('/account/editor/',{templateUrl:'/media/js/src/modules/partials/editor.html',controller:controllers.EditorController});$routeProvider.otherwise({'redirectTo':function(routeParams,locationPath){window.location=locationPath;}});});app.config(function($interpolateProvider){$interpolateProvider.startSymbol('[[');$interpolateProvider.endSymbol(']]');});app.factory('AccountStorage',function($http){return{getAccount:function(){var promise=$http({method:'GET',url:'/api/account/',headers:{}});return promise;}};});var controllers={};controllers.MainController=function($scope,$route,AccountStorage){$scope.route=$route;AccountStorage.getAccount().then(function(response){console.log(response);});};controllers.BillingController=function($scope){$scope.section='Billing';};controllers.BloggingController=function($scope){$scope.section='Blogging';};controllers.EditorController=function($scope){$scope.section='Editor';};controllers.ProfileController=function($scope){$scope.section='Profile';};app.controller(controllers);}}).call(this);
|
||||
(function(){if(typeof angular!=='undefined'){var root=this;var $=root.jQuery;var app=angular.module('Account',[],function($routeProvider,$locationProvider){$locationProvider.html5Mode(true);$routeProvider.when('/account/',{templateUrl:'/media/js/src/modules/partials/profile.html',controller:controllers.ProfileController});$routeProvider.when('/account/billing/',{templateUrl:'/media/js/src/modules/partials/billing.html',controller:controllers.BillingController});$routeProvider.when('/account/blogging/',{templateUrl:'/media/js/src/modules/partials/blogging.html',controller:controllers.BloggingController});$routeProvider.when('/account/editor/',{templateUrl:'/media/js/src/modules/partials/editor.html',controller:controllers.EditorController});$routeProvider.otherwise({'redirectTo':function(routeParams,locationPath){window.location=locationPath;}});});app.config(function($interpolateProvider){$interpolateProvider.startSymbol('[[');$interpolateProvider.endSymbol(']]');});app.factory('AccountStorage',function($http){return{getAccount:function(){var promise=$http({method:'GET',url:'/api/private/profile/'+window.user_profile_id+'/',headers:{'Authorization':'ApiKey '+window.user+':'+window.api_key}});return promise;}};});var controllers={};controllers.MainController=function($scope,$route,AccountStorage){$scope.route=$route;AccountStorage.getAccount().then(function(response){$scope.user=response.data;});};controllers.BillingController=function($scope){$scope.section='Billing';};controllers.BloggingController=function($scope){$scope.section='Blogging';};controllers.EditorController=function($scope){$scope.section='Editor';};controllers.ProfileController=function($scope){$scope.section='Profile';};app.controller(controllers);}}).call(this);
|
|
@ -8,6 +8,7 @@ from tastypie.validation import Validation
|
|||
from tastypie.models import create_api_key
|
||||
from snipts.models import Favorite, Snipt
|
||||
from haystack.query import SearchQuerySet
|
||||
from accounts.models import UserProfile
|
||||
from tastypie.cache import SimpleCache
|
||||
from tastypie.fields import ListField
|
||||
from taggit.models import Tag
|
||||
|
@ -117,7 +118,32 @@ class PublicSniptResource(ModelResource):
|
|||
return orm_filters
|
||||
|
||||
|
||||
class PrivateUserProfileResource(ModelResource):
|
||||
class Meta:
|
||||
queryset = UserProfile.objects.all()
|
||||
resource_name = 'profile'
|
||||
excludes = ['is_pro', 'stripe_id']
|
||||
include_absolute_url = False
|
||||
allowed_methods = ['get', 'put']
|
||||
list_allowed_methods = []
|
||||
authentication = ApiKeyAuthentication()
|
||||
authorization = Authorization()
|
||||
always_return_data = True
|
||||
max_limit = 200
|
||||
cache = SimpleCache()
|
||||
|
||||
def apply_authorization_limits(self, request, object_list):
|
||||
return object_list.filter(user=request.user)
|
||||
|
||||
def dehydrate(self, bundle):
|
||||
bundle.data['email'] = bundle.obj.user.email
|
||||
bundle.data['username'] = bundle.obj.user.username
|
||||
bundle.data['api_key'] = bundle.obj.user.api_key.key
|
||||
return bundle
|
||||
|
||||
class PrivateUserResource(ModelResource):
|
||||
profile = fields.ForeignKey(PrivateUserProfileResource, 'profile', full=False)
|
||||
|
||||
class Meta:
|
||||
queryset = User.objects.all()
|
||||
resource_name = 'user'
|
||||
|
@ -136,9 +162,6 @@ class PrivateUserResource(ModelResource):
|
|||
|
||||
def dehydrate(self, bundle):
|
||||
bundle.data['email_md5'] = hashlib.md5(bundle.obj.email.lower()).hexdigest()
|
||||
bundle.data['profile'] = {
|
||||
'is_pro': bundle.obj.profile.is_pro
|
||||
}
|
||||
return bundle
|
||||
|
||||
class PrivateTagResource(ModelResource):
|
||||
|
|
|
@ -334,23 +334,35 @@
|
|||
{% block inline-js %}
|
||||
<script type="text/javascript">
|
||||
{% block js %}
|
||||
|
||||
window.user = '{{ request.user.username }}';
|
||||
window.user_id = {{ request.user.id }};
|
||||
window.user_profile_id = {{ request.user.profile.id }};
|
||||
|
||||
{% if public %}
|
||||
window.pub = {{ public|lower }};
|
||||
{% else %}
|
||||
window.pub = null;
|
||||
{% endif %}
|
||||
|
||||
window.api_key = '{{ request.user.api_key.key }}';
|
||||
|
||||
{% endblock %}
|
||||
{% if tag %}
|
||||
|
||||
window.tag = '{{ tag.name }}';
|
||||
|
||||
{% endif %}
|
||||
{% if request.user.profile.is_pro %}
|
||||
|
||||
window.user_is_pro = true;
|
||||
window.default_editor = '{{ request.user.profile.get_default_editor_display|lower }}';
|
||||
window.editor_theme = '{{ request.user.profile.editor_theme }}';
|
||||
|
||||
{% else %}
|
||||
|
||||
window.user_is_pro = false;
|
||||
|
||||
{% endif %}
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
|
Loading…
Reference in New Issue