Exemplo n.º 1
0
def post_detail(request, year, month, day, slug):
    reply_to = _get_reply_to(request)
    date = _get_date(year+month+day)
    today = (dt.combine(date, t.min), dt.combine(date, t.max))
    post = get_object_or_404(Post.all_objects.filter(date__range=today), slug=slug)
    if post.comments_open():
        Form = request.user.is_authenticated() and CommentForm or AnonymousCommentForm
        form = build_form(Form, request, remote_ip=request.META['REMOTE_ADDR'], post=post, user=request.user,
                          initial={'reply_to': reply_to})
        if form.is_valid():
            c, user_is_new = form.save()
            if not request.user.is_authenticated():
                if user_is_new:
                    c.user.backend = 'django.contrib.auth.backends.ModelBackend'
                    _login(request, c.user)
                    message = _('Please look in your mailbox for info about your account.')
                else:
                    ActionRecord.approvals.send_approval(c)
                    message = _('Please look in your mailbox for comment approval link.')
            else:
                message = None
            raise RedirectException(c.get_absolute_url(), notice_message=message)
    else:
        form = None
    return {
            'object': post,
            'form': form,
            'reply_to': reply_to,
            'feedurl': 'comments/%s' % post.id,
            'site': Site.objects.get_current(),
            'post_detail': True}
Exemplo n.º 2
0
def android_login(request):
    email = request.GET.get('email', None)
    password = request.GET.get('password', None)
    if _login(request, email, password) == True:
        return_data = '1'
    else:
        return_data = '0'

    return HttpResponse(return_data, mimetype="text/plain")
Exemplo n.º 3
0
def android_login(request):
    email = request.GET.get('email', None)
    password = request.GET.get('password', None)
    if _login(request, email, password) == True:
        return_data = '1'
    else:
        return_data = '0'
    
    return HttpResponse(return_data, mimetype="text/plain")
Exemplo n.º 4
0
def post_detail(request, year, month, day, slug):
    reply_to = _get_reply_to(request)
    date = _get_date(year + month + day)
    today = (dt.combine(date, t.min), dt.combine(date, t.max))
    post = get_object_or_404(Post.all_objects.filter(date__range=today),
                             slug=slug)
    if post.comments_open():
        Form = request.user.is_authenticated(
        ) and CommentForm or AnonymousCommentForm
        form = build_form(Form,
                          request,
                          remote_ip=request.META['REMOTE_ADDR'],
                          post=post,
                          user=request.user,
                          initial={'reply_to': reply_to})
        if form.is_valid():
            c, user_is_new = form.save()
            if not request.user.is_authenticated():
                if user_is_new:
                    c.user.backend = 'django.contrib.auth.backends.ModelBackend'
                    _login(request, c.user)
                    message = _(
                        'Please look in your mailbox for info about your account.'
                    )
                else:
                    ActionRecord.approvals.send_approval(c)
                    message = _(
                        'Please look in your mailbox for comment approval link.'
                    )
            else:
                message = None
            raise RedirectException(c.get_absolute_url(),
                                    notice_message=message)
    else:
        form = None
    return {
        'object': post,
        'form': form,
        'reply_to': reply_to,
        'feedurl': 'comments/%s' % post.id,
        'site': Site.objects.get_current(),
        'post_detail': True
    }
Exemplo n.º 5
0
def post_detail(request, year, month, day, slug):
    reply_to = _get_reply_to(request)
    year, month, day = int(year), int(month), int(day)
    post = get_object_or_404(Post.all_objects, slug=slug,
                             date__year=year,
                             date__month=month,
                             date__day=day)
    if post.comments_open():
        Form = (request.user.is_authenticated()
                and CommentForm
                or AnonymousCommentForm)
        form = build_form(Form, request, post=post, user=request.user,
                          remote_ip=request.META.get('REMOTE_ADDR'),
                          initial={'reply_to': reply_to})
        if form.is_valid():
            c, user_is_new = form.save()
            if not request.user.is_authenticated():
                if user_is_new:
                    #FIXED 23.01.2010
                    if SettingsCached.param.ANONYMOUS_COMMENTS_APPROVED:
                        c.user.backend = 'django.contrib.auth.backends.ModelBackend'
                        _login(request, c.user)
                    message = _('Please look in your mailbox for info about your account.')
                else:
                    ActionRecord.approvals.send_approval(c)
                    message = _('Please look in your mailbox for comment approval link.')
            else:
                message = None
            raise RedirectException(c.get_absolute_url(), notice_message=message)
    else:
        form = None
    
    return {
            'object': post,
            'form': form,
            'reply_to': reply_to,
            'feedurl': 'comments/%s' % post.id,
            'site': Site.objects.get_current(),
            'post_detail': True}
Exemplo n.º 6
0
def bind_weibo_user(request):

    oauth_access_token = request.session.get('oauth_access_token', None)
    client = APIClient(app_key=APP_KEY,
                       app_secret=APP_SECRET,
                       redirect_uri=_get_weibo_callback_url(request))
    client.set_access_token(oauth_access_token['access_token'],
                            oauth_access_token['expires_in'])
    weibo_user = client.get.users__show(uid=oauth_access_token['uid'])
    weibo_username = weibo_user.screen_name

    template_var = {}
    template_var['weibo_username'] = weibo_username
    if request.method == 'POST':
        email = request.POST.get('email', None)
        password = request.POST.get('password', None)
        if _login(request, email, password) == True:

            #weibo信息记录
            w_user = WeiboUser()
            w_user.user = request.user

            w_user.weibo_user_id = oauth_access_token['uid']
            w_user.weibo_username = weibo_username
            w_user.oauth_access_token = oauth_access_token['access_token']
            w_user.save()

            #发微博提示
            if request.POST.get('update_msg'):
                msg = request.POST.get('bind_msg')[0:140]
                client.post.statuses__update(status=msg)

            return HttpResponseRedirect(reverse('songs.views.my_home'))
        else:

            template_var['login_failure'] = True
            template_var['input_email'] = email
            return auth_login_view(
                request,
                template_name='register/bind_weibo_user.html',
                extra_context=template_var)
    else:
        return auth_login_view(request,
                               template_name='register/bind_weibo_user.html',
                               extra_context=template_var)
Exemplo n.º 7
0
def bind_weibo_user(request):

    oauth_access_token = request.session.get('oauth_access_token', None)
    client = APIClient(app_key=APP_KEY, app_secret=APP_SECRET, redirect_uri=_get_weibo_callback_url(request))
    client.set_access_token(oauth_access_token['access_token'], oauth_access_token['expires_in'])
    weibo_user = client.get.users__show(uid=oauth_access_token['uid'])
    weibo_username = weibo_user.screen_name

    template_var = {}
    template_var['weibo_username'] = weibo_username
    if request.method == 'POST':
        email = request.POST.get('email', None)
        password = request.POST.get('password', None)
        if _login(request, email, password) == True:

            #weibo信息记录
            w_user = WeiboUser()
            w_user.user = request.user

            w_user.weibo_user_id = oauth_access_token['uid']
            w_user.weibo_username = weibo_username
            w_user.oauth_access_token = oauth_access_token['access_token']
            w_user.save()

            #发微博提示
            if request.POST.get('update_msg'):
                msg = request.POST.get('bind_msg')[0:140]
                client.post.statuses__update(status=msg)

            return HttpResponseRedirect(reverse('songs.views.my_home'))
        else:

            template_var['login_failure'] = True
            template_var['input_email'] = email
            return auth_login_view(request, template_name='register/bind_weibo_user.html', extra_context=template_var)
    else:
        return auth_login_view(request, template_name='register/bind_weibo_user.html', extra_context=template_var)
Exemplo n.º 8
0
 def test_login_get(self):
     """ 로그인 화면 접근 가능성 테스트"""
     request = self.rf.get('/account/login')
     response = _login(request)
     assert response.status_code == 200