add request to vvsu
This commit is contained in:
parent
61f8fd7d68
commit
a4987aff81
|
@ -15,5 +15,5 @@ urlpatterns = format_suffix_patterns([
|
||||||
|
|
||||||
# auth
|
# auth
|
||||||
re_path(r'^auth/vvsu/', views.VVSUAuthProxy),
|
re_path(r'^auth/vvsu/', views.VVSUAuthProxy),
|
||||||
path('auth/user/login', views.UserLogin)
|
path('auth/user/login', views.UserLogin.as_view())
|
||||||
])
|
])
|
||||||
|
|
|
@ -4,7 +4,7 @@ from rest_framework.views import APIView, View
|
||||||
from rest_framework.request import Request
|
from rest_framework.request import Request
|
||||||
from django.views.decorators.csrf import csrf_exempt
|
from django.views.decorators.csrf import csrf_exempt
|
||||||
|
|
||||||
from django.http import HttpResponseBadRequest, HttpResponse
|
from django.http import HttpResponseBadRequest, HttpResponse, JsonResponse, HttpRequest
|
||||||
from django.db.models.query import QuerySet
|
from django.db.models.query import QuerySet
|
||||||
|
|
||||||
from django.core.validators import validate_email
|
from django.core.validators import validate_email
|
||||||
|
@ -172,6 +172,36 @@ def VVSUAuthProxy(req: Request):
|
||||||
|
|
||||||
return resp;
|
return resp;
|
||||||
|
|
||||||
def UserLogin(req: Request):
|
class UserLogin(APIView):
|
||||||
data = req.data
|
# TODO: Remove csrf exempt when index.html is loaded through django
|
||||||
return HttpResponse(data);
|
@csrf_exempt
|
||||||
|
def post(self, req: HttpRequest):
|
||||||
|
if (req.content_type != 'application/json'):
|
||||||
|
res = HttpResponse({'error': 'bad content type'});
|
||||||
|
res.status_code = 400;
|
||||||
|
return res;
|
||||||
|
|
||||||
|
data = json.loads(req.body.decode('utf8'));
|
||||||
|
|
||||||
|
# if (not hasattr(data, 'code')):
|
||||||
|
# res = JsonResponse({'error': 'no code'});
|
||||||
|
# res.status_code = 400;
|
||||||
|
# return res
|
||||||
|
|
||||||
|
cb = requests.post('https://vvsu.ru/connect/oauth2/token', {
|
||||||
|
'grant_type': 'authorization_code',
|
||||||
|
'redirect_uri': 'https://pairent.vvsu.ru/sign-in/',
|
||||||
|
'code': data['code'],
|
||||||
|
# 'code_verifier': data['code_verifier'],
|
||||||
|
'client_id': 'it-hub-client',
|
||||||
|
'client_secret': 'U8y@uPVee6Q^*729esHTo4Vd'
|
||||||
|
}, headers={
|
||||||
|
'Origin': 'https://pairent.vvsu.ru',
|
||||||
|
'Referer': 'https://pairent.vvsu.ru'
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
resp = HttpResponse(cb.content);
|
||||||
|
resp.headers['Content-Type'] = cb.headers['Content-Type'];
|
||||||
|
|
||||||
|
return resp;
|
|
@ -41,7 +41,7 @@ class User {
|
||||||
}
|
}
|
||||||
|
|
||||||
const data = await axios.post(api_path('/api/auth/user/login'), response);
|
const data = await axios.post(api_path('/api/auth/user/login'), response);
|
||||||
return data.data;
|
return new User(data.data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -37,7 +37,7 @@ export default class LoggedIn extends React.Component {
|
||||||
|
|
||||||
async componentDidMount() {
|
async componentDidMount() {
|
||||||
if (this.response.error) return;
|
if (this.response.error) return;
|
||||||
User.login(this.response);
|
console.log(await User.login(this.response));
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
|
Loading…
Reference in New Issue