diff --git a/account/urls/oj.py b/account/urls/oj.py index 36b28ce5..34b267c5 100644 --- a/account/urls/oj.py +++ b/account/urls/oj.py @@ -1,10 +1,12 @@ from django.conf.urls import url from ..views.oj import (ApplyResetPasswordAPI, ResetPasswordAPI, - UserChangePasswordAPI, UserLoginAPI, UserRegisterAPI) + UserChangePasswordAPI, UserRegisterAPI, + UserLoginAPI, UserLogoutAPI) urlpatterns = [ url(r"^login/?$", UserLoginAPI.as_view(), name="user_login_api"), + url(r"^logout/?$", UserLogoutAPI.as_view(), name="user_logout_api"), url(r"^register/?$", UserRegisterAPI.as_view(), name="user_register_api"), url(r"^change_password/?$", UserChangePasswordAPI.as_view(), name="user_change_password_api"), url(r"^apply_reset_password/?$", ApplyResetPasswordAPI.as_view(), name="apply_reset_password_api"), diff --git a/account/views/oj.py b/account/views/oj.py index 39219eee..fdf2c316 100644 --- a/account/views/oj.py +++ b/account/views/oj.py @@ -52,6 +52,12 @@ class UserLoginAPI(APIView): return self.success({}) +class UserLogoutAPI(APIView): + def get(self, request): + auth.logout(request) + return self.success({}) + + class UserRegisterAPI(APIView): @validate_serializer(UserRegisterSerializer) def post(self, request): diff --git a/account/views/user.py b/account/views/user.py index 727bd780..1f9ee24d 100644 --- a/account/views/user.py +++ b/account/views/user.py @@ -1,5 +1,5 @@ import os -from io import StringIO +from io import BytesIO import qrcode from django.conf import settings @@ -140,7 +140,7 @@ class TwoFactorAuthAPI(APIView): config = WebsiteConfig.objects.first() image = qrcode.make(OtpAuth(token).to_uri("totp", config.base_url, config.name)) - buf = StringIO() + buf = BytesIO() image.save(buf, "gif") return HttpResponse(buf.getvalue(), "image/gif")