Website to manage tibia accounts and characters
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

views.py 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. from django.contrib.auth.models import User
  2. from django.shortcuts import render, render_to_response
  3. from django.views import generic
  4. from django.views.generic.edit import CreateView, FormView
  5. # Create your views here.
  6. from accounts.forms import LoginForm
  7. from accounts.models import Accounts, Players
  8. from accounts.utils import LoginHelper
  9. class RegisterAccountView(CreateView):
  10. model = Accounts
  11. fields = ['name', 'password', 'email']
  12. template_name = 'register_account.html'
  13. def form_valid(self, form):
  14. self.object = form.save(commit=False)
  15. # create django user
  16. u, created = User.objects.get_or_create(
  17. username=self.object.name,
  18. email=self.object.email,
  19. )
  20. if created:
  21. u.set_password(self.object.password)
  22. u.save()
  23. # create tibia account with sha1 hashed password
  24. hashed_password = LoginHelper.hash_password(self.object.password)
  25. self.object.password = hashed_password
  26. self.object.linked_django_user = u
  27. self.object.save()
  28. return render_to_response(self.template_name, self.get_context_data())
  29. class IndexView(generic.ListView):
  30. template_name = 'index.html'
  31. context_object_name = 'best_players'
  32. def get_queryset(self):
  33. return Players.objects.filter(group_id=1).order_by('-level').values('name', 'level')[:10]