mirror of
https://gitlab.com/allianceauth/allianceauth.git
synced 2026-02-08 16:16:18 +01:00
Redone correctly , structure, its pretty
This commit is contained in:
0
registration/__init__.py
Normal file
0
registration/__init__.py
Normal file
3
registration/admin.py
Normal file
3
registration/admin.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
||||
20
registration/forms.py
Normal file
20
registration/forms.py
Normal file
@@ -0,0 +1,20 @@
|
||||
from django import forms
|
||||
|
||||
|
||||
class RegistrationForm(forms.Form):
|
||||
username = forms.CharField(max_length=32, required=True)
|
||||
password = forms.CharField(widget=forms.PasswordInput(), required=True)
|
||||
password_again = forms.CharField(widget=forms.PasswordInput(), required=True, label="Password Again")
|
||||
email = forms.CharField(max_length=254, required=True)
|
||||
email_again = forms.CharField(max_length=254, required=True, label="Email Again")
|
||||
|
||||
def clean(self):
|
||||
if 'password' in self.cleaned_data and 'password_again' in self.cleaned_data:
|
||||
if self.cleaned_data['password'] != self.cleaned_data['password_again']:
|
||||
raise forms.ValidationError(u'Passwords do not match')
|
||||
|
||||
if 'email' in self.cleaned_data and 'email_again' in self.cleaned_data:
|
||||
if self.cleaned_data['email'] != self.cleaned_data['email_again']:
|
||||
raise forms.ValidationError(u'Emails do not match')
|
||||
|
||||
return self.cleaned_data
|
||||
3
registration/models.py
Normal file
3
registration/models.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.db import models
|
||||
|
||||
# Create your models here.
|
||||
3
registration/tests.py
Normal file
3
registration/tests.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
||||
31
registration/views.py
Normal file
31
registration/views.py
Normal file
@@ -0,0 +1,31 @@
|
||||
from django.contrib.auth.models import User
|
||||
from django.http import HttpResponseRedirect
|
||||
from django.shortcuts import render_to_response
|
||||
from django.template import RequestContext
|
||||
|
||||
from forms import RegistrationForm
|
||||
|
||||
|
||||
def register_user_view(request):
|
||||
|
||||
if request.method == 'POST':
|
||||
form = RegistrationForm(request.POST)
|
||||
|
||||
if form.is_valid():
|
||||
|
||||
if not User.objects.filter(username=form.cleaned_data['username']).exists():
|
||||
user = User.objects.create_user(form.cleaned_data['username'],
|
||||
form.cleaned_data['email'], form.cleaned_data['password'])
|
||||
|
||||
user.save()
|
||||
|
||||
return HttpResponseRedirect("/dashboard")
|
||||
|
||||
else:
|
||||
return render_to_response('public/register.html', {'form': form, 'error': True}
|
||||
, context_instance=RequestContext(request))
|
||||
|
||||
else:
|
||||
form = RegistrationForm()
|
||||
|
||||
return render_to_response('public/register.html', {'form': form}, context_instance=RequestContext(request))
|
||||
Reference in New Issue
Block a user