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.1KB

123456789101112131415161718192021222324252627282930313233
  1. from django.shortcuts import render, render_to_response
  2. from django.views import generic
  3. from django.views.generic.edit import CreateView, FormView
  4. # Create your views here.
  5. from accounts.forms import LoginForm
  6. from accounts.models import Accounts, Players
  7. from accounts.utils import LoginHelper
  8. class RegisterAccountView(CreateView):
  9. model = Accounts
  10. fields = ['name', 'password', 'email']
  11. template_name = 'register_account.html'
  12. def form_valid(self, form):
  13. self.object = form.save(commit=False)
  14. hashed_password = LoginHelper.hash_password(self.object.password)
  15. self.object.password = hashed_password
  16. self.object.save()
  17. return render_to_response(self.template_name, self.get_context_data())
  18. class LoginView(FormView):
  19. template_name = 'login.html'
  20. form_class = LoginForm
  21. success_url = '/loginarea/'
  22. class IndexView(generic.ListView):
  23. template_name = 'index.html'
  24. context_object_name = 'best_players'
  25. def get_queryset(self):
  26. return Players.objects.filter(group_id=1).order_by('-level')[:10]