Enable login (without view yet)

This commit is contained in:
aldrin 2021-04-14 11:21:39 +02:00
parent a6300d0388
commit b54c523491
6 changed files with 27 additions and 1 deletions

View File

@ -62,6 +62,13 @@ export class User extends Model implements UserData {
super();
}
async login(): Promise<void> {
await super.create("token/login", {
email: this.email,
password: this.password,
});
}
async signup(): Promise<void> {
await super.create("users", { email: this.email, password: this.password });
}

View File

@ -33,6 +33,7 @@ export default class LoginForm extends Vue {
private async doSignup() {
await this.user.signup();
// TODO: error handling, show confirmation page
}
}
</script>

6
userausfall/admin.py Normal file
View File

@ -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)

View File

@ -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)

View File

@ -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',
),
}

View File

@ -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')),
]