diff --git a/src/api.ts b/src/api.ts index e23d953..9d349fd 100644 --- a/src/api.ts +++ b/src/api.ts @@ -62,6 +62,13 @@ export class User extends Model implements UserData { super(); } + async login(): Promise { + await super.create("token/login", { + email: this.email, + password: this.password, + }); + } + async signup(): Promise { await super.create("users", { email: this.email, password: this.password }); } diff --git a/src/components/LoginForm.vue b/src/components/LoginForm.vue index d1d2d3d..85e8a33 100644 --- a/src/components/LoginForm.vue +++ b/src/components/LoginForm.vue @@ -33,6 +33,7 @@ export default class LoginForm extends Vue { private async doSignup() { await this.user.signup(); + // TODO: error handling, show confirmation page } } diff --git a/userausfall/admin.py b/userausfall/admin.py new file mode 100644 index 0000000..00b5d97 --- /dev/null +++ b/userausfall/admin.py @@ -0,0 +1,6 @@ +from django.contrib import admin +from django.contrib.auth.admin import UserAdmin + +from userausfall.models import User + +admin.site.register(User, UserAdmin) diff --git a/userausfall/models.py b/userausfall/models.py index 49cc3e9..62c38bf 100644 --- a/userausfall/models.py +++ b/userausfall/models.py @@ -26,7 +26,7 @@ class UserManager(BaseUserManager): extra_fields.setdefault('is_superuser', False) return self._create_user(email, password, **extra_fields) - def create_superuser(self, username, email, password, **extra_fields): + def create_superuser(self, email, password, **extra_fields): extra_fields.setdefault('is_staff', True) extra_fields.setdefault('is_superuser', True) diff --git a/userausfall/settings.py b/userausfall/settings.py index d1ab09b..2459e41 100644 --- a/userausfall/settings.py +++ b/userausfall/settings.py @@ -38,6 +38,7 @@ INSTALLED_APPS = [ 'django.contrib.staticfiles', 'userausfall', 'rest_framework', + 'rest_framework.authtoken', 'djoser', ] @@ -149,3 +150,13 @@ DJOSER = { # https://docs.djangoproject.com/en/3.2/topics/email/ EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' + + +# Django Rest Framework +# https://www.django-rest-framework.org/api-guide/settings/ + +REST_FRAMEWORK = { + 'DEFAULT_AUTHENTICATION_CLASSES': ( + 'rest_framework.authentication.TokenAuthentication', + ), +} diff --git a/userausfall/urls.py b/userausfall/urls.py index d2525fe..b353d4b 100644 --- a/userausfall/urls.py +++ b/userausfall/urls.py @@ -7,4 +7,5 @@ urlpatterns = [ path('admin/', admin.site.urls), path('api/', include(rest_api_urls.router.urls)), path('api/', include('djoser.urls')), + path('api/', include('djoser.urls.authtoken')), ]