コード例 #1
0
ファイル: views.py プロジェクト: deisaack/digitech
def signup(request):
    if request.method == 'POST':
        form = SignUpForm(request.POST)
        if not form.is_valid():
            return render(request, 'authentication/signup.html',
                          {'form': form})

        else:
            ''' Begin reCAPTCHA validation '''
            recaptcha_response = request.POST.get('g-recaptcha-response')
            url = 'https://www.google.com/recaptcha/api/siteverify'
            values = {
                'secret': settings.GOOGLE_RECAPTCHA_SECRET_KEY,
                'response': recaptcha_response
            }
            data = urllib.parse.urlencode(values).encode()
            req = urllib.request.Request(url, data=data)
            response = urllib.request.urlopen(req)
            result = json.loads(response.read().decode())
            ''' End reCAPTCHA validation '''

            if result['success']:
                username = form.cleaned_data.get('username')
                email = form.cleaned_data.get('email')
                password = form.cleaned_data.get('password')
                User.objects.create_user(username=username, password=password,
                                         email=email)
                user = authenticate(username=username, password=password)
                login(request, user)
                welcome_post = '{0} has joined the network.'.format(user.username,
                                                                    user.username)
                feed = Feed(user=user, post=welcome_post)
                feed.save()
                return redirect('/')
            else:
                messages.error(request, 'Invalid reCAPTCHA. Please try again.')

            return redirect('/')
        #
        # username = form.cleaned_data.get('username')
        # email = form.cleaned_data.get('email')
        # password = form.cleaned_data.get('password')
        # User.objects.create_user(username=username, password=password,
        #                          email=email)
        # user = authenticate(username=username, password=password)
        # login(request, user)
        # welcome_post = '{0} has joined the network.'.format(user.username,
        #                                                     user.username)
        # feed = Feed(user=user, post=welcome_post)
        # feed.save()
        # return redirect('/')


    else:
        return render(request, 'authentication/signup.html',
                      {'form': SignUpForm()})
コード例 #2
0
ファイル: views.py プロジェクト: deisaack/digitech
def post(request):
    last_feed = request.POST.get('last_feed')
    user = request.user
    csrf_token = (csrf(request)['csrf_token'])
    feed = Feed()
    feed.user = user
    post = request.POST['post']
    post = post.strip()
    if len(post) > 0:
        feed.post = post[:255]
        feed.save()
    html = _html_feeds(last_feed, user, csrf_token)
    return HttpResponse(html)