fixed authentication permissions

master
ahmetkotan 2019-01-31 02:18:37 +03:00
rodzic 602f34a340
commit aab4da3a7e
5 zmienionych plików z 17 dodań i 13 usunięć

Wyświetl plik

@ -46,7 +46,6 @@ class PinView(PaginationAPIView):
if not pin: if not pin:
return Response({"physical": "No pin number."}) return Response({"physical": "No pin number."})
serializer = self.serializer_class(data=request.data) serializer = self.serializer_class(data=request.data)
serializer.is_valid(raise_exception=True) serializer.is_valid(raise_exception=True)

Wyświetl plik

@ -2,3 +2,9 @@
DEBUG = True DEBUG = True
ALLOWED_HOSTS = ['*'] ALLOWED_HOSTS = ['*']
CORS_ALLOW_CREDENTIALS = True
CORS_ORIGIN_ALLOW_ALL = True
CORS_ORIGIN_WHITELIST = (
'localhost',
'http//:localhost:63342'
)

Wyświetl plik

@ -131,7 +131,7 @@ REST_FRAMEWORK = {
'rest_framework.permissions.IsAuthenticated', 'rest_framework.permissions.IsAuthenticated',
), ),
'DEFAULT_AUTHENTICATION_CLASSES': ( 'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework.authentication.BasicAuthentication', 'rest_framework.authentication.SessionAuthentication',
'tokenauth.auth.TokenAuthentication', 'tokenauth.auth.TokenAuthentication',
), ),
'DEFAULT_PARSER_CLASSES': ( 'DEFAULT_PARSER_CLASSES': (
@ -147,10 +147,3 @@ REST_FRAMEWORK = {
'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination', 'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination',
'PAGE_SIZE': 40, 'PAGE_SIZE': 40,
} }
CORS_ALLOW_CREDENTIALS = True
CORS_ORIGIN_ALLOW_ALL = True
CORS_ORIGIN_WHITELIST = (
'localhost',
'http//:localhost:63342'
)

Wyświetl plik

@ -15,6 +15,7 @@ app.controller('pinTableController', function($scope, $http) {
return new_pinlist; return new_pinlist;
}; };
var token = document.getElementsByName("csrfmiddlewaretoken")[0].value;
$http.get("/pins/api/") $http.get("/pins/api/")
.then(function(response) { .then(function(response) {
$scope.pinlist = response.data.results; $scope.pinlist = response.data.results;
@ -23,7 +24,9 @@ app.controller('pinTableController', function($scope, $http) {
$scope.change_mode = function (physical, mode_code) { $scope.change_mode = function (physical, mode_code) {
var url = "/pins/api/" + physical; var url = "/pins/api/" + physical;
$http.post(url, {mode: mode_code}, {headers: {'Content-Type': 'application/json'}}) $http.post(url,
{mode: mode_code},
{headers: {'Content-Type': 'application/json', 'X-CSRFToken': token}})
.then(function (response) { .then(function (response) {
if(response.status == 200 && response.data.operation){ if(response.status == 200 && response.data.operation){
console.log(response.data.pin); console.log(response.data.pin);
@ -39,7 +42,9 @@ app.controller('pinTableController', function($scope, $http) {
$scope.change_value = function (physical) { $scope.change_value = function (physical) {
var url = "/pins/api/" + physical; var url = "/pins/api/" + physical;
var new_value = ($scope.pinlist[physical-1].value) ? 0 : 1 var new_value = ($scope.pinlist[physical-1].value) ? 0 : 1
$http.post(url, {value: new_value}, {headers: {'Content-Type': 'application/json'}}) $http.post(url,
{value: new_value},
{headers: {'Content-Type': 'application/json', 'X-CSRFToken': token}})
.then(function (response) { .then(function (response) {
if(response.status == 200 && response.data.operation){ if(response.status == 200 && response.data.operation){
$scope.pinlist[physical-1] = response.data.pin; $scope.pinlist[physical-1] = response.data.pin;

Wyświetl plik

@ -3,6 +3,7 @@
{% block title %}Pins{% endblock %} {% block title %}Pins{% endblock %}
{% block mainarea %} {% block mainarea %}
{% csrf_token %}
<main class="main-bar"> <main class="main-bar">
<div class="container"> <div class="container">
<div class="row justify-content-center"> <div class="row justify-content-center">