From ede65b0147a54bb6226fb05a1d62f5e361d1aa1c Mon Sep 17 00:00:00 2001 From: Llloooggg Date: Mon, 12 Sep 2022 23:57:40 +0300 Subject: [PATCH] =?UTF-8?q?[backend=20+=20frontend]:=20=D0=94=D0=BE=D0=B1?= =?UTF-8?q?=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=B0=20=D0=B1=D0=B0=D0=B7=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0=D1=8F=20=D1=80=D0=B5=D0=B3=D0=B8=D1=81=D1=82=D1=80?= =?UTF-8?q?=D0=B0=D1=86=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/requirements.txt | 25 ++++ .../{authentication => accounts}/__init__.py | 0 .../{authentication => accounts}/admin.py | 0 .../{authentication => accounts}/apps.py | 4 +- .../migrations/__init__.py | 0 .../{authentication => accounts}/models.py | 0 .../{authentication => accounts}/tests.py | 0 backend/wheretogo/accounts/urls.py | 14 +++ backend/wheretogo/accounts/views.py | 13 ++ backend/wheretogo/authentication/urls.py | 9 -- backend/wheretogo/authentication/views.py | 3 - .../wheretogo/locale/ru/LC_MESSAGES/django.po | 6 +- backend/wheretogo/wheretogo/settings.py | 11 +- .../wheretogo/settings_var.py_template | 4 + backend/wheretogo/wheretogo/urls.py | 2 +- .../wheretogo/src/components/LoginPage.vue | 5 +- .../src/components/RegistrationPage.vue | 112 ++++++++++++++++++ frontend/wheretogo/src/router.js | 5 + .../wheretogo/src/services/auth-header.js | 4 +- .../wheretogo/src/services/auth.service.js | 8 +- .../wheretogo/src/services/user.service.js | 2 +- 21 files changed, 198 insertions(+), 29 deletions(-) rename backend/wheretogo/{authentication => accounts}/__init__.py (100%) rename backend/wheretogo/{authentication => accounts}/admin.py (100%) rename backend/wheretogo/{authentication => accounts}/apps.py (68%) rename backend/wheretogo/{authentication => accounts}/migrations/__init__.py (100%) rename backend/wheretogo/{authentication => accounts}/models.py (100%) rename backend/wheretogo/{authentication => accounts}/tests.py (100%) create mode 100644 backend/wheretogo/accounts/urls.py create mode 100644 backend/wheretogo/accounts/views.py delete mode 100644 backend/wheretogo/authentication/urls.py delete mode 100644 backend/wheretogo/authentication/views.py create mode 100644 frontend/wheretogo/src/components/RegistrationPage.vue diff --git a/backend/requirements.txt b/backend/requirements.txt index 4c37d05..2275bea 100644 --- a/backend/requirements.txt +++ b/backend/requirements.txt @@ -1,10 +1,35 @@ asgiref==3.5.2 backports.zoneinfo==0.2.1 +certifi==2022.6.15.1 +cffi==1.15.1 +charset-normalizer==2.1.1 +coreapi==2.3.3 +coreschema==0.0.4 +cryptography==38.0.1 +defusedxml==0.7.1 Django==4.1.1 django-cors-headers==3.13.0 django-filter==22.1 +django-templated-mail==1.1.1 djangorestframework==3.13.1 djangorestframework-gis==1.0 +djangorestframework-simplejwt==4.8.0 +djoser==2.1.0 +idna==3.3 +itypes==1.2.0 +Jinja2==3.1.2 +MarkupSafe==2.1.1 +oauthlib==3.2.1 psycopg2==2.9.3 +pycparser==2.21 +PyJWT==2.4.0 +python3-openid==3.2.0 pytz==2022.2.1 +requests==2.28.1 +requests-oauthlib==1.3.1 +six==1.16.0 +social-auth-app-django==4.0.0 +social-auth-core==4.3.0 sqlparse==0.4.2 +uritemplate==4.1.1 +urllib3==1.26.12 diff --git a/backend/wheretogo/authentication/__init__.py b/backend/wheretogo/accounts/__init__.py similarity index 100% rename from backend/wheretogo/authentication/__init__.py rename to backend/wheretogo/accounts/__init__.py diff --git a/backend/wheretogo/authentication/admin.py b/backend/wheretogo/accounts/admin.py similarity index 100% rename from backend/wheretogo/authentication/admin.py rename to backend/wheretogo/accounts/admin.py diff --git a/backend/wheretogo/authentication/apps.py b/backend/wheretogo/accounts/apps.py similarity index 68% rename from backend/wheretogo/authentication/apps.py rename to backend/wheretogo/accounts/apps.py index 27f63ad..079c961 100644 --- a/backend/wheretogo/authentication/apps.py +++ b/backend/wheretogo/accounts/apps.py @@ -4,5 +4,5 @@ from django.utils.translation import gettext_lazy class AuthConfig(AppConfig): default_auto_field = "django.db.models.BigAutoField" - name = "authentication" - verbose_name = gettext_lazy("authentication") + name = "accounts" + verbose_name = gettext_lazy("accounts") diff --git a/backend/wheretogo/authentication/migrations/__init__.py b/backend/wheretogo/accounts/migrations/__init__.py similarity index 100% rename from backend/wheretogo/authentication/migrations/__init__.py rename to backend/wheretogo/accounts/migrations/__init__.py diff --git a/backend/wheretogo/authentication/models.py b/backend/wheretogo/accounts/models.py similarity index 100% rename from backend/wheretogo/authentication/models.py rename to backend/wheretogo/accounts/models.py diff --git a/backend/wheretogo/authentication/tests.py b/backend/wheretogo/accounts/tests.py similarity index 100% rename from backend/wheretogo/authentication/tests.py rename to backend/wheretogo/accounts/tests.py diff --git a/backend/wheretogo/accounts/urls.py b/backend/wheretogo/accounts/urls.py new file mode 100644 index 0000000..9aa6955 --- /dev/null +++ b/backend/wheretogo/accounts/urls.py @@ -0,0 +1,14 @@ +from django.urls import path +from django.urls import include + +from accounts.views import CustomTokenObtainPairView + +urlpatterns = [ + path("", include("djoser.urls")), + path( + "auth/jwt/create", + CustomTokenObtainPairView.as_view(), + name="custom_token_obtain_pair", + ), + path("auth/", include("djoser.urls.jwt")), +] diff --git a/backend/wheretogo/accounts/views.py b/backend/wheretogo/accounts/views.py new file mode 100644 index 0000000..63e3fc8 --- /dev/null +++ b/backend/wheretogo/accounts/views.py @@ -0,0 +1,13 @@ +from rest_framework_simplejwt.serializers import TokenObtainPairSerializer +from rest_framework_simplejwt.views import TokenObtainPairView + + +class CustomTokenObtainPairSerializer(TokenObtainPairSerializer): + def validate(self, attrs): + data = super().validate(attrs) + data["username"] = self.user.username + return data + + +class CustomTokenObtainPairView(TokenObtainPairView): + serializer_class = CustomTokenObtainPairSerializer diff --git a/backend/wheretogo/authentication/urls.py b/backend/wheretogo/authentication/urls.py deleted file mode 100644 index b66ac60..0000000 --- a/backend/wheretogo/authentication/urls.py +++ /dev/null @@ -1,9 +0,0 @@ -from django.urls import path - -from rest_framework_simplejwt.views import TokenObtainPairView -from rest_framework_simplejwt.views import TokenRefreshView - -urlpatterns = [ - path("token", TokenObtainPairView.as_view(), name="token_obtain_pair"), - path("token/refresh", TokenRefreshView.as_view(), name="token_refresh"), -] diff --git a/backend/wheretogo/authentication/views.py b/backend/wheretogo/authentication/views.py deleted file mode 100644 index 91ea44a..0000000 --- a/backend/wheretogo/authentication/views.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.shortcuts import render - -# Create your views here. diff --git a/backend/wheretogo/locale/ru/LC_MESSAGES/django.po b/backend/wheretogo/locale/ru/LC_MESSAGES/django.po index 0284f65..ad388df 100644 --- a/backend/wheretogo/locale/ru/LC_MESSAGES/django.po +++ b/backend/wheretogo/locale/ru/LC_MESSAGES/django.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2022-09-10 14:48+0300\n" +"POT-Creation-Date: 2022-09-12 23:55+0300\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -20,6 +20,10 @@ msgstr "" "%10<=4 && (n%100<12 || n%100>14) ? 1 : n%10==0 || (n%10>=5 && n%10<=9) || (n" "%100>=11 && n%100<=14)? 2 : 3);\n" +#: accounts/apps.py:8 +msgid "accounts" +msgstr "аккаунты" + #: facilities/apps.py:8 facilities/models.py:18 msgid "facilities" msgstr "заведения" diff --git a/backend/wheretogo/wheretogo/settings.py b/backend/wheretogo/wheretogo/settings.py index 5ed536f..92c774f 100644 --- a/backend/wheretogo/wheretogo/settings.py +++ b/backend/wheretogo/wheretogo/settings.py @@ -43,11 +43,11 @@ INSTALLED_APPS = [ "django.contrib.messages", "django.contrib.staticfiles", "django.contrib.gis", + "djoser", "rest_framework", - "rest_framework_simplejwt", "rest_framework_gis", "corsheaders", - "authentication", + "accounts", "facilities", ] @@ -128,9 +128,12 @@ STATIC_URL = "static/" DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField" - REST_FRAMEWORK = { "DEFAULT_AUTHENTICATION_CLASSES": ( "rest_framework_simplejwt.authentication.JWTAuthentication", - ) + ), +} + +SIMPLE_JWT = { + "AUTH_HEADER_TYPES": ("JWT",), } diff --git a/backend/wheretogo/wheretogo/settings_var.py_template b/backend/wheretogo/wheretogo/settings_var.py_template index efc62a0..b7bfd21 100644 --- a/backend/wheretogo/wheretogo/settings_var.py_template +++ b/backend/wheretogo/wheretogo/settings_var.py_template @@ -11,3 +11,7 @@ DATABASES = { "PORT": "5432", } } + +CORS_ALLOWED_ORIGINS = [ + "http://localhost:8080", +] diff --git a/backend/wheretogo/wheretogo/urls.py b/backend/wheretogo/wheretogo/urls.py index 02ceb3c..3e6b8a8 100644 --- a/backend/wheretogo/wheretogo/urls.py +++ b/backend/wheretogo/wheretogo/urls.py @@ -19,6 +19,6 @@ from django.urls import include urlpatterns = [ path("admin/", admin.site.urls), - path("api/auth/", include("authentication.urls")), + path("api/accounts/", include("accounts.urls")), path("api/facilities/", include("facilities.urls")), ] diff --git a/frontend/wheretogo/src/components/LoginPage.vue b/frontend/wheretogo/src/components/LoginPage.vue index a131aef..358b7fc 100644 --- a/frontend/wheretogo/src/components/LoginPage.vue +++ b/frontend/wheretogo/src/components/LoginPage.vue @@ -5,6 +5,7 @@
+
Login
@@ -61,7 +62,7 @@ export default { }, created() { if (this.loggedIn) { - this.$router.push("/profile"); + this.$router.push("/"); } }, methods: { @@ -69,7 +70,7 @@ export default { this.loading = true; this.$store.dispatch("auth/login", user).then( () => { - this.$router.push("/profile"); + this.$router.push("/"); }, (error) => { this.loading = false; diff --git a/frontend/wheretogo/src/components/RegistrationPage.vue b/frontend/wheretogo/src/components/RegistrationPage.vue new file mode 100644 index 0000000..dd7cfdd --- /dev/null +++ b/frontend/wheretogo/src/components/RegistrationPage.vue @@ -0,0 +1,112 @@ + + \ No newline at end of file diff --git a/frontend/wheretogo/src/router.js b/frontend/wheretogo/src/router.js index b7373ab..0166682 100644 --- a/frontend/wheretogo/src/router.js +++ b/frontend/wheretogo/src/router.js @@ -1,6 +1,7 @@ import { createWebHistory, createRouter } from "vue-router"; import MapPage from "./components/MapPage.vue"; import LoginPage from "./components/LoginPage.vue"; +import RegistrationPage from "./components/RegistrationPage.vue"; const routes = [ { path: "/", @@ -11,6 +12,10 @@ const routes = [ path: "/login", component: LoginPage, }, + { + path: "/register", + component: RegistrationPage, + }, ]; const router = createRouter({ history: createWebHistory(), diff --git a/frontend/wheretogo/src/services/auth-header.js b/frontend/wheretogo/src/services/auth-header.js index 2aa49ae..3f040d6 100644 --- a/frontend/wheretogo/src/services/auth-header.js +++ b/frontend/wheretogo/src/services/auth-header.js @@ -1,7 +1,7 @@ export default function authHeader() { let user = JSON.parse(localStorage.getItem('user')); - if (user && user.accessToken) { - return { Authorization: 'Bearer ' + user.accessToken }; + if (user && user.access) { + return { Authorization: 'Bearer ' + user.access }; } else { return {}; } diff --git a/frontend/wheretogo/src/services/auth.service.js b/frontend/wheretogo/src/services/auth.service.js index 5dbbe12..8ec2a25 100644 --- a/frontend/wheretogo/src/services/auth.service.js +++ b/frontend/wheretogo/src/services/auth.service.js @@ -1,14 +1,14 @@ import axios from "axios"; -const API_URL = "http://localhost:8000/api/auth/"; +const API_URL = "http://127.0.0.1:8000/api/accounts/"; class AuthService { login(user) { return axios - .post(API_URL + "token", { + .post(API_URL + "auth/jwt/create", { username: user.username, password: user.password, }) .then((response) => { - if (response.data.accessToken) { + if (response.data.access) { localStorage.setItem("user", JSON.stringify(response.data)); } return response.data; @@ -18,7 +18,7 @@ class AuthService { localStorage.removeItem("user"); } register(user) { - return axios.post(API_URL + "signup", { + return axios.post(API_URL + "users/", { username: user.username, email: user.email, password: user.password, diff --git a/frontend/wheretogo/src/services/user.service.js b/frontend/wheretogo/src/services/user.service.js index 38ddf45..6748720 100644 --- a/frontend/wheretogo/src/services/user.service.js +++ b/frontend/wheretogo/src/services/user.service.js @@ -1,6 +1,6 @@ import axios from 'axios'; import authHeader from './auth-header'; -const API_URL = 'http://localhost:8000/api/auth/user/'; +const API_URL = 'http://127.0.0.1:8000/api/accounts/users/me/'; class UserService { getPublicContent() { return axios.get(API_URL + 'all');