1379: Этап №4 - Ошибка 404 на странице профиля

1394: Этап №4 - Ошибка при авторизации
remotes/origin/mobile_from_stage4
Alexander Burdeiny 10 years ago
parent 0742be4893
commit 897a30f885
  1. 9
      accounts/forms.py
  2. 8
      accounts/views.py
  3. 8
      fabfile.py
  4. 36
      functions/pipeline.py
  5. 23
      registration/backends/default/views.py
  6. 3
      templates/registration/acquire_email.html

@ -1,4 +1,5 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import re
import json import json
import ast import ast
from django import forms from django import forms
@ -200,6 +201,8 @@ class EmailAnnouncementForm(forms.Form):
announcement = forms.MultipleChoiceField(choices=data, widget=forms.CheckboxSelectMultiple()) announcement = forms.MultipleChoiceField(choices=data, widget=forms.CheckboxSelectMultiple())
url_regex = re.compile('^\w*$')
class RegistrationCompleteForm(forms.ModelForm): class RegistrationCompleteForm(forms.ModelForm):
country = forms.ModelChoiceField(label=_(u'Страна'), queryset=Country.objects.all(), country = forms.ModelChoiceField(label=_(u'Страна'), queryset=Country.objects.all(),
widget=forms.Select(attrs={'class': 'select2'})) widget=forms.Select(attrs={'class': 'select2'}))
@ -239,8 +242,9 @@ class RegistrationCompleteForm(forms.ModelForm):
def clean_url(self): def clean_url(self):
url = self.cleaned_data['url'] url = self.cleaned_data['url']
if not is_latin(url): valid = url_regex.match(url)
raise forms.ValidationError(_(u'url должен состоять только из латинских букв')) if valid is None:
raise forms.ValidationError(_(u'url должен состоять только из латинских букв и цифр'))
try: try:
User.objects.get(url=url) User.objects.get(url=url)
@ -259,6 +263,7 @@ class SocialRegistrationCompleteForm(RegistrationCompleteForm):
def save(self, force_insert=False, force_update=False, commit=True): def save(self, force_insert=False, force_update=False, commit=True):
email = self.cleaned_data['email'] email = self.cleaned_data['email']
print(email, 'blablabla')
if User.objects.filter(email=email).exists(): if User.objects.filter(email=email).exists():
# pass to the view user, that had account before # pass to the view user, that had account before
user = User.objects.get(email=email) user = User.objects.get(email=email)

@ -231,10 +231,10 @@ class UserView(MetadataMixin, TemplateView):
url = self.kwargs.get('url') url = self.kwargs.get('url')
try: try:
url = int(url) user = User.objects.get(id=int(url))
user = get_object_or_404(User, id=url) except (ValueError, User.DoesNotExist, ):
except ValueError:
user = get_object_or_404(User, url=url) user = get_object_or_404(User, url=url)
self.kwargs['user_full_name'] = user.get_full_name() self.kwargs['user_full_name'] = user.get_full_name()
return user return user
@ -496,4 +496,4 @@ def remove_from_calendar(request):
return HttpResponse(json.dumps({'success': True}), content_type='application/json') return HttpResponse(json.dumps({'success': True}), content_type='application/json')
else: else:
return Http404 return Http404

8
fabfile.py vendored

@ -116,3 +116,11 @@ def stage3_release():
run('python manage.py migrate article 0003') run('python manage.py migrate article 0003')
chown() chown()
call_state('start') call_state('start')
def c_fix():
with cd(REMOTE_HOME_DIR):
call_state('stop', only='apache2')
run('git pull')
run('python manage.py migrate expobanner')
call_state('start', only='apache2')

@ -1,8 +1,20 @@
# -*- coding: utf-8 -*-
from accounts.models import User
import random import random
import string import string
from accounts.models import User
from django.conf import settings
from django.contrib.sites.models import RequestSite, Site
from django.core import signing
from django.core.mail import EmailMultiAlternatives
from django.core.urlresolvers import reverse
from django.shortcuts import redirect
from registration import signals
from registration.models import RegistrationProfile
from social.pipeline.partial import partial
def random_pass(): def random_pass():
digits = random.sample(('0', '1', '2', '3', '4', '5', '6', '7', '8', '9'), 4) digits = random.sample(('0', '1', '2', '3', '4', '5', '6', '7', '8', '9'), 4)
chars = random.sample(string.lowercase[:], 4) chars = random.sample(string.lowercase[:], 4)
@ -19,9 +31,6 @@ def load_user(strategy, details, response, uid, *args, **kwargs):
return {'user': user, 'is_new': False} return {'user': user, 'is_new': False}
from django.contrib.sites.models import Site, RequestSite
from registration.models import RegistrationProfile
def create_user(strategy, details, response, uid, user=None, *args, **kwargs): def create_user(strategy, details, response, uid, user=None, *args, **kwargs):
if user: if user:
@ -39,33 +48,20 @@ def create_user(strategy, details, response, uid, user=None, *args, **kwargs):
return {'user': new_user, 'is_new': True} return {'user': new_user, 'is_new': True}
from django.shortcuts import redirect
from social.pipeline.partial import partial
from registration import signals
@partial @partial
def require_email(strategy, details, user=None, is_new=False, *args, **kwargs): def require_email(strategy, details, user=None, is_new=False, *args, **kwargs):
if user and user.email: if user and user.email:
return return
elif is_new and not details.get('email'): elif is_new and not details.get('email'):
email = strategy.request_data().get('email') email = strategy.request_data().get('email')
if email: if email and not User.objects.filter(email=email).exists():
details['email'] = email details['email'] = email
else: else:
strategy.request.session['new_email'] = True strategy.request.session['new_email'] = True
strategy.request.session['new_email_invalid'] = True
return redirect('acquire_email') return redirect('acquire_email')
from django.core import signing
from django.core.mail import EmailMultiAlternatives
from django.conf import settings
from django.core.urlresolvers import reverse
def SendVerificationEmail(strategy, backend, code): def SendVerificationEmail(strategy, backend, code):
""" """
Send an email with an embedded verification code and the necessary details to restore the required session Send an email with an embedded verification code and the necessary details to restore the required session
@ -94,4 +90,4 @@ Please click on <a href='{verifyURL}'>this link</a> to continue registration.
email = EmailMultiAlternatives(**kwargs) email = EmailMultiAlternatives(**kwargs)
email.attach_alternative(emailHTML, "text/html") email.attach_alternative(emailHTML, "text/html")
email.send() email.send()

@ -3,6 +3,7 @@ from django.conf import settings
from django.contrib.sites.models import RequestSite from django.contrib.sites.models import RequestSite
from django.contrib.sites.models import Site from django.contrib.sites.models import Site
from django.utils.translation import ugettext as _ from django.utils.translation import ugettext as _
from django.http import Http404
from registration import signals from registration import signals
from registration.models import RegistrationProfile from registration.models import RegistrationProfile
@ -50,7 +51,7 @@ class RegistrationView(BaseRegistrationView):
an instance of ``registration.models.RegistrationProfile``. See an instance of ``registration.models.RegistrationProfile``. See
that model and its custom manager for full documentation of its that model and its custom manager for full documentation of its
fields and supported operations. fields and supported operations.
""" """
def register(self, request, **cleaned_data): def register(self, request, **cleaned_data):
""" """
@ -100,7 +101,7 @@ class RegistrationView(BaseRegistrationView):
* If ``REGISTRATION_OPEN`` is both specified and set to * If ``REGISTRATION_OPEN`` is both specified and set to
``False``, registration is not permitted. ``False``, registration is not permitted.
""" """
return getattr(settings, 'REGISTRATION_OPEN', True) return getattr(settings, 'REGISTRATION_OPEN', True)
@ -109,7 +110,7 @@ class RegistrationView(BaseRegistrationView):
""" """
Return the name of the URL to redirect to after successful Return the name of the URL to redirect to after successful
user registration. user registration.
""" """
# return json.dumps({'bla': 'ok'}) # return json.dumps({'bla': 'ok'})
return ('registration_complete', (), {}) return ('registration_complete', (), {})
@ -126,7 +127,7 @@ class ActivationView(BaseActivationView):
``registration.signals.user_activated`` will be sent, with the ``registration.signals.user_activated`` will be sent, with the
newly activated ``User`` as the keyword argument ``user`` and newly activated ``User`` as the keyword argument ``user`` and
the class of this backend as the sender. the class of this backend as the sender.
""" """
activated_user = RegistrationProfile.objects.activate_user(activation_key) activated_user = RegistrationProfile.objects.activate_user(activation_key)
if activated_user: if activated_user:
@ -250,8 +251,6 @@ def LoginView(request):
HttpResponseRedirect('/') HttpResponseRedirect('/')
def complete_registration(request): def complete_registration(request):
if request.is_ajax(): if request.is_ajax():
response = {'success': False} response = {'success': False}
@ -285,9 +284,15 @@ def acquire_email(request, template_name="registration/acquire_email.html"):
""" """
Request email for the create user flow for logins that don't specify their email address. Request email for the create user flow for logins that don't specify their email address.
""" """
backend = request.session['partial_pipeline']['backend'] if 'partial_pipeline' not in request.session:
return render(request, template_name, {"backend": backend}) raise Http404
ctx = {
"backend": request.session['partial_pipeline']['backend'],
"invalid": request.session.get('new_email_invalid', False),
}
request.session['new_email_invalid'] = False
return render(request, template_name, ctx)
def inactive_user_message(request): def inactive_user_message(request):
return render(request, 'registration/social_registration_complete.html') return render(request, 'registration/social_registration_complete.html')

@ -16,6 +16,9 @@
<label class="control-label" for="id_email">{% trans "Email address:" %}</label> <label class="control-label" for="id_email">{% trans "Email address:" %}</label>
<input class="form-control" id="id_email" type="email" name="email" placeholder="E-mail"/> <input class="form-control" id="id_email" type="email" name="email" placeholder="E-mail"/>
{# <input type="hidden" name="valid" value="no">#} {# <input type="hidden" name="valid" value="no">#}
{% if invalid %}
{% trans "Такой Email уже существует." %}
{% endif %}
</div> </div>
</div> </div>
<button class="btn btn-default" type="submit">{% trans "Submit" %}</button> <button class="btn btn-default" type="submit">{% trans "Submit" %}</button>

Loading…
Cancel
Save