diff --git a/accounts/models.py b/accounts/models.py
index a4dd93f..42cedd5 100644
--- a/accounts/models.py
+++ b/accounts/models.py
@@ -5,6 +5,7 @@
# * Make sure each ForeignKey has `on_delete` set to the desired behavior.
# * Remove `managed = False` lines if you wish to allow Django to create, modify, and delete the table
# Feel free to rename the models, but don't rename db_table values or field names.
+from django.contrib.auth.models import User
from django.db import models
@@ -54,9 +55,10 @@ class Accounts(models.Model):
lastday = models.PositiveIntegerField(default=0)
email = models.CharField(max_length=255)
creation = models.IntegerField(default=0)
+ linked_django_user = models.OneToOneField(User, on_delete=models.CASCADE, blank=True, null=True)
class Meta:
- managed = False
+ managed = True
db_table = 'accounts'
diff --git a/accounts/templates/base_generic.html b/accounts/templates/base_generic.html
index d400ea4..68c7167 100644
--- a/accounts/templates/base_generic.html
+++ b/accounts/templates/base_generic.html
@@ -3,7 +3,7 @@
{% block title %}Ambitious Server{% endblock %}
-
+
{% load static %}
diff --git a/accounts/templates/register_account.html b/accounts/templates/register_account.html
index 48126a0..5e3d562 100644
--- a/accounts/templates/register_account.html
+++ b/accounts/templates/register_account.html
@@ -1,17 +1,10 @@
-
-
-
-
- Register Account
-
-
-
-
+{% extends "base_generic.html" %}
+{% block content %}
+Register
-
-
\ No newline at end of file
+{% endblock %}
\ No newline at end of file
diff --git a/accounts/urls.py b/accounts/urls.py
index 79c5883..8fc5803 100644
--- a/accounts/urls.py
+++ b/accounts/urls.py
@@ -8,5 +8,4 @@ app_name = 'accounts'
urlpatterns = [
path('', views.IndexView.as_view(), name='index'),
path('register/', views.RegisterAccountView.as_view(), name='register'),
- path('login/', views.LoginView.as_view(), name='login'),
]
\ No newline at end of file
diff --git a/accounts/views.py b/accounts/views.py
index 44e221b..aef69e0 100644
--- a/accounts/views.py
+++ b/accounts/views.py
@@ -1,3 +1,4 @@
+from django.contrib.auth.models import User
from django.shortcuts import render, render_to_response
from django.views import generic
from django.views.generic.edit import CreateView, FormView
@@ -14,17 +15,22 @@ class RegisterAccountView(CreateView):
def form_valid(self, form):
self.object = form.save(commit=False)
- hashed_password = LoginHelper.hash_password(self.object.password)
- self.object.password = hashed_password
- self.object.save()
+ # create django user
+ u, created = User.objects.get_or_create(
+ username=self.object.name,
+ email=self.object.email,
+ )
+ if created:
+ u.set_password(self.object.password)
+ u.save()
+ # create tibia account with sha1 hashed password
+ hashed_password = LoginHelper.hash_password(self.object.password)
+ self.object.password = hashed_password
+ self.object.linked_django_user = u
+ self.object.save()
return render_to_response(self.template_name, self.get_context_data())
-class LoginView(FormView):
- template_name = 'login.html'
- form_class = LoginForm
- success_url = '/loginarea/'
-
class IndexView(generic.ListView):
template_name = 'index.html'
context_object_name = 'best_players'
diff --git a/tibia_website/settings.py b/tibia_website/settings.py
index d6354ad..645be71 100644
--- a/tibia_website/settings.py
+++ b/tibia_website/settings.py
@@ -125,5 +125,5 @@ USE_TZ = True
STATIC_URL = '/static/'
# Redirect to home URL after login (Default redirects to /accounts/profile/)
-LOGIN_REDIRECT_URL = '/'
+LOGIN_REDIRECT_URL = '/accounts/'