diff --git a/api/masteriqapp/views/AuthenticationView.py b/api/masteriqapp/views/AuthenticationView.py index 536b4aa..4ff88e4 100644 --- a/api/masteriqapp/views/AuthenticationView.py +++ b/api/masteriqapp/views/AuthenticationView.py @@ -9,9 +9,11 @@ masteriq = apps.get_app_config("masteriqapp") + class AuthenticationView(viewsets.ViewSet): category_model = masteriq.get_model("Category") iq_model = masteriq.get_model("IQ") + @action(detail=False, methods=['POST'], permission_classes=[AllowAny]) def login(self, request): username = request.data.get('username') @@ -47,4 +49,3 @@ def create_iq_objects_for_new_user(self, user): already_existing_entry = self.iq_model.objects.get_iq_of_user_in_category(user=user, category=category) except masteriqapp.models.IQ.DoesNotExist: self.iq_model.objects.create(user=user, category=category, iq=100) - diff --git a/api/masteriqapp/views/QuestionView.py b/api/masteriqapp/views/QuestionView.py index d425e93..80321af 100644 --- a/api/masteriqapp/views/QuestionView.py +++ b/api/masteriqapp/views/QuestionView.py @@ -50,7 +50,7 @@ class QuestionView(viewsets.ViewSet): queryset = category_model.objects.all() permission_classes = (IsAuthenticated,) - @action(detail=True, methods=["GET"]) + @action(detail=True, methods=["GET"], permission_classes=[IsAuthenticated]) def new(self, request, pk): category = get_object_or_404(self.queryset, pk=pk) if 'question' in request.session: @@ -66,7 +66,7 @@ def new(self, request, pk): serializer = QuestionSerializer(new_question) return Response(serializer.data, status=status.HTTP_200_OK) - @action(detail=False, methods=["POST"]) + @action(detail=False, methods=["POST"], permission_classes=[IsAuthenticated]) def new_community(self, request): datas = request.data if not ('question' in datas and 'answer' in datas and 'options' in datas): @@ -102,7 +102,7 @@ def new_community(self, request): return Response(question_serializer.data, status=status.HTTP_201_CREATED) - @action(detail=False, methods=["GET"]) + @action(detail=False, methods=["GET"], permission_classes=[IsAuthenticated]) def options(self, request): if not 'question' in request.session: return Response(status=449, data={"error": "No question being answered at the moment"}) @@ -114,7 +114,7 @@ def options(self, request): data_to_send['options'][option.id] = option.text return Response(status=status.HTTP_200_OK, data=data_to_send) - @action(detail=False, methods=["POST"], url_path="answer_text") + @action(detail=False, methods=["POST"], url_path="answer_text", permission_classes=[IsAuthenticated]) def answer_text(self, request): if not 'answer' in request.data: return Response(status=status.HTTP_400_BAD_REQUEST, data={"error": "No answer given"}) @@ -139,7 +139,7 @@ def answer_text(self, request): del request.session['options_asked'] return Response(status=status.HTTP_200_OK, data=data_to_send) - @action(detail=False, methods=["POST"], url_path="answer_option") + @action(detail=False, methods=["POST"], url_path="answer_option", permission_classes=[IsAuthenticated]) def answer_options(self, request): if not 'answer' in request.data: return Response(status=status.HTTP_400_BAD_REQUEST, data={"error": "No answer given"}) @@ -167,7 +167,7 @@ def answer_options(self, request): del request.session['options_asked'] return Response(status=status.HTTP_200_OK, data=data_to_send) - @action(detail=False, methods=["GET"]) + @action(detail=False, methods=["GET"], permission_classes=[IsAuthenticated]) def options_asked(self, request): if not 'question' in request.session or not 'options_asked' in request.session: data_to_send = {"options_asked": False} diff --git a/frontend/src/api_client.js b/frontend/src/api_client.js index 4868530..e0a5fff 100644 --- a/frontend/src/api_client.js +++ b/frontend/src/api_client.js @@ -174,15 +174,11 @@ export default */ static async registerUser(username, password) { csrftoken = getCookie('csrftoken'); - try { - const response = await axios.post('/api/user/register/', { - username, - password - }); - return response.data; - } catch (error) { - throw new Error('Error registering user: ' + error.message); - } + const response = await axios.post('/api/user/register/', { + username, + password + }); + return response.data; } /** @@ -193,15 +189,11 @@ export default */ static async loginUser(username, password) { csrftoken = getCookie('csrftoken'); - try { - const response = await axios.post('/api/user/login/', { - username, - password - }); - return response.data; - } catch (error) { - throw new Error('Error logging in: ' + error.message); - } + const response = await axios.post('/api/user/login/', { + username, + password + }); + return response.data; } /** @@ -227,12 +219,8 @@ export default */ static async logOutUser() { csrftoken = getCookie('csrftoken'); - try { - const response = await axios.post('/api/user/logout/',); - return response.data; - } catch (error) { - throw new Error('Error logging out: ' + error.message); - } + const response = await axios.post('/api/user/logout/',); + return response.data; } } diff --git a/frontend/src/views/Authentication/LoginView.vue b/frontend/src/views/Authentication/LoginView.vue index 4768daa..0330c43 100644 --- a/frontend/src/views/Authentication/LoginView.vue +++ b/frontend/src/views/Authentication/LoginView.vue @@ -62,6 +62,7 @@ const login = async () => { display: flex; flex-direction: column; align-items: center; + min-height: 80vh; } .title, .info { diff --git a/frontend/src/views/Authentication/RegisterView.vue b/frontend/src/views/Authentication/RegisterView.vue index 27706a4..528cb46 100644 --- a/frontend/src/views/Authentication/RegisterView.vue +++ b/frontend/src/views/Authentication/RegisterView.vue @@ -65,6 +65,7 @@ const register = async () => { display: flex; flex-direction: column; align-items: center; + min-height: 80vh; } .title, .info {