|
|
|
|
@ -8,6 +8,8 @@ from registration.views import ActivationView as BaseActivationView |
|
|
|
|
from registration.views import RegistrationView as BaseRegistrationView |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import json |
|
|
|
|
|
|
|
|
|
class RegistrationView(BaseRegistrationView): |
|
|
|
|
""" |
|
|
|
|
A registration backend which follows a simple workflow: |
|
|
|
|
@ -81,6 +83,7 @@ class RegistrationView(BaseRegistrationView): |
|
|
|
|
signals.user_registered.send(sender=self.__class__, |
|
|
|
|
user=new_user, |
|
|
|
|
request=request) |
|
|
|
|
|
|
|
|
|
return new_user |
|
|
|
|
|
|
|
|
|
def registration_allowed(self, request): |
|
|
|
|
@ -98,15 +101,18 @@ class RegistrationView(BaseRegistrationView): |
|
|
|
|
""" |
|
|
|
|
return getattr(settings, 'REGISTRATION_OPEN', True) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_success_url(self, request, user): |
|
|
|
|
""" |
|
|
|
|
Return the name of the URL to redirect to after successful |
|
|
|
|
user registration. |
|
|
|
|
|
|
|
|
|
""" |
|
|
|
|
# return json.dumps({'bla': 'ok'}) |
|
|
|
|
return ('registration_complete', (), {}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ActivationView(BaseActivationView): |
|
|
|
|
def activate(self, request, activation_key): |
|
|
|
|
""" |
|
|
|
|
@ -128,3 +134,68 @@ class ActivationView(BaseActivationView): |
|
|
|
|
|
|
|
|
|
def get_success_url(self, request, user): |
|
|
|
|
return ('registration_activation_complete', (), {}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from django.http import HttpResponse, HttpResponseRedirect |
|
|
|
|
|
|
|
|
|
from accounts.models import User |
|
|
|
|
|
|
|
|
|
from registration.forms import RegistrationFormUniqueEmail, LoginForm |
|
|
|
|
from django.contrib.auth import login, logout |
|
|
|
|
|
|
|
|
|
from django.views.decorators.debug import sensitive_post_parameters |
|
|
|
|
from django.views.decorators.cache import never_cache |
|
|
|
|
|
|
|
|
|
@sensitive_post_parameters('password1', 'password2') |
|
|
|
|
@never_cache |
|
|
|
|
def RegisterAjaxView(request): |
|
|
|
|
if request.is_ajax(): |
|
|
|
|
data = {'success': False} |
|
|
|
|
if request.POST: |
|
|
|
|
form = RegistrationFormUniqueEmail(request.POST) |
|
|
|
|
if form.is_valid(): |
|
|
|
|
first_name, last_name, email, password = form.cleaned_data['first_name'],\ |
|
|
|
|
form.cleaned_data['last_name'], form.cleaned_data['email'],\ |
|
|
|
|
form.cleaned_data['password1'] |
|
|
|
|
if Site._meta.installed: |
|
|
|
|
site = Site.objects.get_current() |
|
|
|
|
else: |
|
|
|
|
site = RequestSite(request) |
|
|
|
|
new_user = RegistrationProfile.objects.create_inactive_user(first_name, last_name, email, |
|
|
|
|
password, site) |
|
|
|
|
signals.user_registered.send(sender=User, |
|
|
|
|
user=new_user, |
|
|
|
|
request=request) |
|
|
|
|
data['success'] = True |
|
|
|
|
|
|
|
|
|
else: |
|
|
|
|
data.update(form.errors) |
|
|
|
|
|
|
|
|
|
return HttpResponse(json.dumps(data), content_type='application/json') |
|
|
|
|
else: |
|
|
|
|
# 404 |
|
|
|
|
return HttpResponse('not post') |
|
|
|
|
else: |
|
|
|
|
# 404 |
|
|
|
|
return HttpResponse('not ajax') |
|
|
|
|
|
|
|
|
|
from django.contrib.auth.forms import AuthenticationForm |
|
|
|
|
|
|
|
|
|
@sensitive_post_parameters('password') |
|
|
|
|
def LoginAjaxView(request): |
|
|
|
|
|
|
|
|
|
if request.POST: |
|
|
|
|
form = AuthenticationForm(request.POST) |
|
|
|
|
if form.is_valid(): |
|
|
|
|
login(request, form.get_user()) |
|
|
|
|
return HttpResponseRedirect('/') |
|
|
|
|
|
|
|
|
|
else: |
|
|
|
|
return HttpResponse('bla') |
|
|
|
|
else: |
|
|
|
|
form = LoginForm() |
|
|
|
|
|
|
|
|
|
return HttpResponseRedirect('/') |
|
|
|
|
|