예제 #1
0
    def post(self, *args, **kwargs):
        register_form = CustomRegisterForm(data=self.request.POST)
        if register_form.is_valid():
            user = register_form.save()
            kw = {
                'token': user.auth_token.key,
                '_': timezone.now().date().strftime("%H%M%S"),
            }

            url_redirect = url_with_querystring(reverse('tokenize'), **kw)
            # url = "http://{host}{url}".format(host=self.request.get_host(), url=url_redirect)
            # context = {'user': user, 'redirect_url': url}
            #
            # kw = dict(subject=APP_SUBJECT_TO_CONFIRM_REGISTER,
            #           tpl_name='confirmation_register.html',
            #           context=context,
            #           to=[user.email])
            # send_template_mail.apply_async(kwargs=kw)

            transaction.commit()
            return redirect(url_redirect)

        else:
            transaction.rollback()
            resp_dict = {'error': dict(((i[0], i[1][0]) for i in register_form.errors.items()))}
            return HttpResponse(render_page('register', resp_dict))
예제 #2
0
파일: forms.py 프로젝트: tumani1/vsevi
    def save(self, commit=True, send_email=False):
        instance = super(CustomRegisterForm, self).save(commit)
        instance.first_name = self.cleaned_data['email'].split('@')[0]
        instance.set_password(self.cleaned_data['password1'])
        instance.save()

        # save hash
        o_hash = UsersHash(user=instance, hash_type=APP_USER_HASH_REGISTR)
        o_hash.save()

        if send_email:
            param_email = {
                'to': [instance.email],
                'context': {
                    'user': model_to_dict(instance, fields=[field.name for field in instance._meta.fields]),
                    'redirect_url': 'http://{host}{url}'.format(
                        host=HOST,
                        url=url_with_querystring(reverse('confirm_email'), **{APP_USER_ACTIVE_KEY: o_hash.hash_key})
                    )
                },
                'subject': APP_SUBJECT_TO_CONFIRM_REGISTER,
                'tpl_name': 'mail/confirmation_register.html',
            }

            send_template_mail.apply_async(kwargs=param_email)

        return instance
예제 #3
0
파일: loader.py 프로젝트: tumani1/vsevi
 def get_url(self, load_function):
     url = "http://%s/%s" % (self.host, self.search_url, )
     url = url_with_querystring(url, **self.params)
     response = load_function(url)
     film_url = parsers.parse_search(response, self.film.name, self.film.release_date)
     if film_url is None:
         raise NoSuchFilm(self.film)
     self.url_load = film_url
     return self.url_load
예제 #4
0
 def get_url(self, load_function):
     url = "http://%s/%s" % (self.host, self.search_url, )
     url = url_with_querystring(url, **self.params)
     response = load_function(url)
     film_url = parsers.parse_search(response, self.film.name, self.film.release_date.year)
     if film_url is None:
         raise NoSuchFilm(self.film)
     self.url_load = film_url
     return self.url_load
예제 #5
0
 def get_url(self, load_function):
     url = "http://%s/%s" % (self.host, self.search_url, )
     url = url_with_querystring(url, **self.params)
     response = load_function(url)
     film = parsers.parse_search(response, self.film)
     if film is None:
         raise NoSuchFilm(self.film)
     self.url_load = film['link']
     return "http://%s%s" % (self.host, self.url_load)
예제 #6
0
파일: loader.py 프로젝트: tumani1/vsevi
    def get_url(self, load_function):
        url = "http://%s/%s" % (self.host, self.search_url)
        url = url_with_querystring(url, **self.params)

        response = load_function(url)

        link = parsers.parse_search(response, self.film.name, self.film.type, self.film.release_date.year)
        if link is None:
            raise NoSuchFilm(self.film)

        self.url_load = link
        return link
예제 #7
0
파일: views.py 프로젝트: tumani1/vsevi
def delete_social_provider(request, provider):
    if isinstance(request.user, AnonymousUser):
        return redirect("login_view")

    try:
        users_social = UserSocialAuth.objects.filter(user=request.user)
        if request.user.has_usable_password() or users_social.count() > 1:
            users_social.get(provider=provider).delete()
        else:
            kw = {'e': u'Невозможно удалить аккаунт социальной сети'.encode('utf-8')}
            url = url_with_querystring(reverse('profile_view'), **kw)
            return redirect(url)
    except Exception, e:
        pass
예제 #8
0
def delete_social_provider(request, provider):
    if isinstance(request.user, AnonymousUser):
        return redirect("login_view")
    try:
        users_social = UserSocialAuth.objects.filter(user=request.user)
        if request.user.has_usable_password() or users_social.count() > 1:
            users_social.get(provider=provider).delete()
        else:
            kw = {'e': u'Невозможно удалить аккаунт социальной сети'.encode('utf-8')}
            url = url_with_querystring(reverse('profile_view'), **kw)
            return redirect(url)
    except:
        pass
    return redirect('profile_view')
예제 #9
0
    def post(self, *args, **kwargs):
        login_form = AuthenticationForm(data=self.request.POST)
        if login_form.is_valid():
            user = login_form.get_user()
            kw = {
                'token': user.auth_token.key,
                '_': timezone.now().date().strftime("%H%M%S")
            }
            if self.request.META['HTTP_HOST'] == HOST and not HOST+'/login' in self.request.META['HTTP_REFERER']:
                kw.update(back_url=self.request.META['HTTP_REFERER'])
            url = url_with_querystring(reverse('tokenize'), **kw)
            return HttpResponseRedirect(url)

        else:
            return HttpResponse(render_page('login', {'error': u'Введите корректный логин или пароль'}))
예제 #10
0
파일: views.py 프로젝트: tumani1/vsevi
    def post(self, *args, **kwargs):
        data = self.request.POST
        login_form = AuthenticationForm(data=data)
        if login_form.is_valid():
            user = login_form.get_user()
            kw = {
                'token': user.auth_token.key,
                '_': timezone.now().date().strftime("%H%M%S")
            }

            if self.request.META['HTTP_HOST'] == HOST and not HOST+'/login' in self.request.META['HTTP_REFERER']:
                kw.update(back_url=self.request.META['HTTP_REFERER'])

            url = url_with_querystring(reverse('tokenize'), **kw)
            return HttpResponseRedirect(url)

        else:
            return HttpResponse(render_page('login', {'error': u'Введите корректный логин или пароль'}))
예제 #11
0
파일: views.py 프로젝트: tumani1/vsevi
    def post(self, *args, **kwargs):
        register_form = CustomRegisterForm(data=self.request.POST)
        if register_form.is_valid():
            committed = False
            try:
                user = register_form.save(send_email=True)
                url_redirect = url_with_querystring(
                    reverse('tokenize'),
                    **{
                        'token': user.auth_token.key,
                        '_': timezone.now().date().strftime("%H%M%S"),
                    }
                )
                transaction.commit()
                committed = True

                return redirect(url_redirect)

            except Exception, e:
                resp_dict = {'error': 'Ошибка в сохранении данных.'}
                return HttpResponse(render_page('register', resp_dict))

            finally:
예제 #12
0
파일: forms.py 프로젝트: tumani1/vsevi
        try:
            transaction.commit()
        except IntegrityError, e:
            transaction.rollback()
            return {'error': "Ошибка в сохранении имени"}

        if send_email and email_flag:
            # Формируем параметры email
            param_email = {
                'to': [email],
                'context': {
                    'user': model_to_dict(self.user, fields=[field.name for field in self.user._meta.fields]),
                    'profile': model_to_dict(instance, fields=[field.name for field in instance._meta.fields]),
                    'url': 'http://{host}{url}'.format(
                        host=HOST,
                        url=url_with_querystring(reverse('confirm_email'), **{APP_USER_ACTIVE_KEY: o_hash.hash_key})
                    ),
                },
                'subject': APP_SUBJECT_TO_RESTORE_EMAIL,
                'tpl_name': 'mail/confirm_change_email.html',
            }

            # Отправляем email
            send_template_mail.apply_async(kwargs=param_email)

        return instance

    class Meta:
        model = UsersProfile
        exclude = ('userpic_id', 'last_visited', 'user')