Commits

aminiy committed cab3673

Потверждение почты по ссылке

Comments (0)

Files changed (3)

 admin.autodiscover()
 
 urlpatterns = staticfiles_urlpatterns() + patterns('',
-    url(r'^accounts/confirm/', 'catalog.userprofs.views.confirm'),
+    url(r'^accounts/confirm/$', 'catalog.userprofs.views.confirm'),
     url(r'^accounts/register/', 'catalog.userprofs.views.register'),
-    url(r'^accounts/password_reset/$', 'django.contrib.auth.views.password_reset', name='admin_password_reset'),
-    url(r'^accounts/password_reset/done/$', 'django.contrib.auth.views.password_reset_done'),
-    url(r'^reset/(?P<uidb36>[0-9A-Za-z]+)-(?P<token>.+)/$', 'django.contrib.auth.views.password_reset_confirm'),
+    url(r'^accounts/password_reset/$',
+        'django.contrib.auth.views.password_reset',
+        name='admin_password_reset'),
+    url(r'^accounts/password_reset/done/$',
+        'django.contrib.auth.views.password_reset_done'),
+    url(r'^reset/(?P<uidb36>[0-9A-Za-z]+)-(?P<token>.+)/$',
+        'django.contrib.auth.views.password_reset_confirm'),
     url(r'^reset/done/$', 'django.contrib.auth.views.password_reset_complete'),
     url(r'^accounts/login/', login, {'template_name': 'form.html'}),
     url(r'^accounts/logout/', logout, {'next_page': '/'}),

catalog/userprofs/views.py

 from django.core.mail.message import EmailMessage
 from django.contrib.auth.decorators import login_required
 from django.forms.models import inlineformset_factory
+from django.template.loader import get_template
+from django.template.context import Context
 
 
 @csrf_protect
         form = UserForm(request.POST, instance=tuser)
 
         if form.is_valid():
+            tuser.save()
 
-            tuser.save()
+            email_template = get_template('emailconfirm.html')
+            email_context = Context({'code': tuser.key})
+            email_text = email_template.render(email_context)
+
             email = EmailMessage(u'Потверждение регистрации',
-                               'Код потверждения регистрации %s '
-                               % (tuser.key), to=[tuser.email])
+                               email_text, to=[tuser.email])
             email.send()
             return HttpResponseRedirect('/accounts/confirm/')
     else:
             tuser.delete()
             return HttpResponseRedirect('/accounts/login/')
     else:
-        form = EmailConfirmation()
-    return render_to_response('form.html', {'form': form},
+        if 'code' in request.GET:
+            tuser = TempUser.objects.get(key=request.GET['code'])
+            #Создаем нового пользователя
+            new_user = User.objects.create_user(tuser.username,
+                                                tuser.email, tuser.password)
+            new_user.save()
+
+            #Создаем новый профиль для активированного пользователя
+            profile = Profile(type=tuser.type, user=new_user)
+
+            profile.save()
+
+            tuser.delete()
+            return HttpResponseRedirect('/accounts/login/')
+        else:
+            form = EmailConfirmation()
+            return render_to_response('form.html', {'form': form},
                               context_instance=RequestContext(request))
 
 

templs/emailconfirm.html

+Благодарим за регистрацию на сайте *****
+Для подтверждения регистрации прейдите по ссылке
+http://aminiy.pythonanywhere.com/accounts/confirm/?code={{code}}
+или введите этот код 
+{{code}}
+в форму подтверждения регистрации
+http://aminiy.pythonanywhere.com/accounts/confirm/