add request to vvsu

This commit is contained in:
b1ek 2023-05-16 17:42:44 +10:00
parent 61f8fd7d68
commit a4987aff81
Signed by: blek
GPG Key ID: 14546221E3595D0C
4 changed files with 37 additions and 7 deletions

View File

@ -15,5 +15,5 @@ urlpatterns = format_suffix_patterns([
# auth
re_path(r'^auth/vvsu/', views.VVSUAuthProxy),
path('auth/user/login', views.UserLogin)
path('auth/user/login', views.UserLogin.as_view())
])

View File

@ -4,7 +4,7 @@ from rest_framework.views import APIView, View
from rest_framework.request import Request
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.core.validators import validate_email
@ -172,6 +172,36 @@ def VVSUAuthProxy(req: Request):
return resp;
def UserLogin(req: Request):
data = req.data
return HttpResponse(data);
class UserLogin(APIView):
# TODO: Remove csrf exempt when index.html is loaded through django
@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;

View File

@ -41,7 +41,7 @@ class User {
}
const data = await axios.post(api_path('/api/auth/user/login'), response);
return data.data;
return new User(data.data);
}
}

View File

@ -37,7 +37,7 @@ export default class LoggedIn extends React.Component {
async componentDidMount() {
if (this.response.error) return;
User.login(this.response);
console.log(await User.login(this.response));
}
render() {