@Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException,
            IOException {
        if ("logout".equals(request.getParameter("action"))) {
            logout(request, response);
            return;
        }
        Profile existingProfile = (Profile) request.getSession().getAttribute("profile");

        if("changeLanguage".equals(request.getParameter("action"))) {
            Profile updatedProfile = profileService.changeLanguage(existingProfile, request.getParameter("language"));
            request.getSession().setAttribute("profile", updatedProfile);
            request.getRequestDispatcher("/exam?action=view").forward(request, response);
            return;
        }

        if (existingProfile != null && existingProfile instanceof ProfileImpl) {
            request.getRequestDispatcher("/exam?action=view").forward(request, response);
            return;
        }

        String login = request.getParameter("login");
        String password = request.getParameter("password");

        Profile profileFromService = profileService.getProfile(login, password);
        if(profileFromService instanceof NullProfile){
            request.setAttribute("authenticationFailed", "true");
            goToLogin(request, response);
            return;
        }

        request.getSession().setAttribute("profile", profileFromService);
        request.getRequestDispatcher("/exam?action=view").forward(request, response);
    }