示例#1
0
def message(request):
    '''
    留言板
    '''
    mes = Kola_message.objects.order_by('-pub_date')[:100]
    errors=[]
    flag = ""
    if request.method == "POST":
        #验证部分代码 +++++++++++++++++++++++++++++++++++++++++++++++
        challenge = request.POST.get('geetest_challenge')
        validate = request.POST.get('geetest_validate')
        seccode = request.POST.get('geetest_seccode')
        gt = geetest.geetest('geetest_KEY')
        if not gt.geetest_validate(challenge, validate, seccode):
            errors.append(u'验证未通过,请先通过验证')       
        #  ——————————————————————————————————————————————————————————
            
        if not request.POST.get('message',''):
            errors.append(u'请输入留言内容')
        if not errors:
            message =Kola_message(
                name=request.POST.get('name',''),
                email= request.POST.get('email',''),
                text= request.POST.get('message',''),
                )
            message.save()
            flag = u"留言成功提交。"
            try:
                title = "message:"+request.POST.get('name','').encode('utf-8')+';'+request.POST.get('email','').encode('utf-8')
                content = request.POST.get('message','').encode('utf-8')
                PyEmail.SendMail('*****@*****.**',title,content) 
            except:
                pass
    return render(request,'message.html',locals())
示例#2
0
def index(request):
    login_flag = False
    kola_name = ''
    errors = []
    flag = ''
    news_list = []
    if "login_flag" in request.session:
        login_flag = True
        kola_name = request.session['name']
    news = News.objects.order_by("-dt")
    if request.method == "POST":

        # 使用geetest验证码验证 +++++++++++++++++++++++++++++++++++++
        challenge = request.POST.get('geetest_challenge')
        validate = request.POST.get('geetest_validate')
        seccode = request.POST.get('geetest_seccode')
        gt = geetest.geetest('geetest_KEY')
        if not gt.geetest_validate(challenge, validate, seccode):
            errors.append(u'验证未通过,请先通过验证')
        # ———————————————————————————————————————————————————————————

        if len(request.POST.get('news', '')) < 70:
            errors.append(u'提交内容长度必须大于70字.')
        if len(request.POST.get('news', '')) > 1000:
            errors.append(u"提交内容长度过长,不超过1000个字.")
        if not errors:
            new_news = News(
                title=request.POST.get('news', ''),
                source=u"匿名新闻",
            )
            new_news.save()
            request.session["news_flag"] = True
            flag = u"匿名新闻提交成功。"
            return HttpResponseRedirect('/news/')

    paginator = Paginator(news, 40)  # Show 25 contacts per page
    page = request.GET.get('page')
    try:
        contacts = paginator.page(page)
    except PageNotAnInteger:
        # If page is not an integer, deliver first page.
        contacts = paginator.page(1)
    except EmptyPage:
        # If page is out of range (e.g. 9999), deliver last page of results.
        contacts = paginator.page(paginator.num_pages)
    return render(request, 'news_index.html', locals())
示例#3
0
def index(request):
    login_flag = False
    kola_name = ''
    errors = []
    flag = ''
    news_list = []
    if "login_flag" in request.session:
        login_flag = True
        kola_name = request.session['name']
    news = News.objects.order_by("-dt")
    if request.method == "POST":
        
        # 使用geetest验证码验证 +++++++++++++++++++++++++++++++++++++
        challenge = request.POST.get('geetest_challenge')
        validate = request.POST.get('geetest_validate')
        seccode = request.POST.get('geetest_seccode')
        gt = geetest.geetest('geetest_KEY')      
        if not gt.geetest_validate(challenge, validate, seccode):
            errors.append(u'验证未通过,请先通过验证')  
        # ———————————————————————————————————————————————————————————
        
        if len(request.POST.get('news',''))<70:
            errors.append(u'提交内容长度必须大于70字.')
        if len(request.POST.get('news',''))>1000:
            errors.append(u"提交内容长度过长,不超过1000个字.")
        if not errors:
            new_news =News(
                title=request.POST.get('news',''),
                source=u"匿名新闻",
                )
            new_news.save()
            request.session["news_flag"] = True
            flag = u"匿名新闻提交成功。"
            return HttpResponseRedirect('/news/')

    paginator = Paginator(news, 40) # Show 25 contacts per page
    page = request.GET.get('page')
    try:
        contacts = paginator.page(page)
    except PageNotAnInteger:
        # If page is not an integer, deliver first page.
        contacts = paginator.page(1)
    except EmptyPage:
        # If page is out of range (e.g. 9999), deliver last page of results.
        contacts = paginator.page(paginator.num_pages)    
    return render(request,'news_index.html',locals())
示例#4
0
def message(request):
    '''
    留言板
    '''
    mes = Kola_message.objects.order_by('-pub_date')[:100]
    errors = []
    flag = ""
    if request.method == "POST":
        #验证部分代码 +++++++++++++++++++++++++++++++++++++++++++++++
        challenge = request.POST.get('geetest_challenge')
        validate = request.POST.get('geetest_validate')
        seccode = request.POST.get('geetest_seccode')
        gt = geetest.geetest('geetest_KEY')
        if not gt.geetest_validate(challenge, validate, seccode):
            errors.append(u'验证未通过,请先通过验证')
        #  ——————————————————————————————————————————————————————————

        if not request.POST.get('message', ''):
            errors.append(u'请输入留言内容')
        if not errors:
            message = Kola_message(
                name=request.POST.get('name', ''),
                email=request.POST.get('email', ''),
                text=request.POST.get('message', ''),
            )
            message.save()
            flag = u"留言成功提交。"
            try:
                title = "message:" + request.POST.get(
                    'name', '').encode('utf-8') + ';' + request.POST.get(
                        'email', '').encode('utf-8')
                content = request.POST.get('message', '').encode('utf-8')
                PyEmail.SendMail('*****@*****.**', title, content)
            except:
                pass
    return render(request, 'message.html', locals())
示例#5
0
文件: user.py 项目: simidaxu/1024nj
import requests

from base import *
from lib.variables import *
from form.user import *
from lib.variables import gen_random
from lib.xss import XssCleaner
from lib.utils import find_mentions
from lib.reddit import hot
from lib.utils import pretty_date

from lib.mobile import is_mobile_browser

import geetest

gt = geetest.geetest("b3def7f6a704f9649f2d907b1b661e70")

from qiniu import Auth
from qiniu import BucketManager
from qiniu import put_data

access_key = "DaQzr1UhFQD6im_kJJjZ8tQUKQW7ykiHo4ZWfC25"
secret_key = "Ge61JJtUSC5myXVrntdVOqAZ5L7WpXR_Taa9C8vb"
q = Auth(access_key, secret_key)
bucket = BucketManager(q)

DEBUG_FLAG = True


def do_login(self, user_id):
    user_info = self.user_model.get_user_by_uid(user_id)
示例#6
0
from base import *
from lib.variables import *
from form.user import *
from lib.variables import gen_random
from lib.xss import XssCleaner
from lib.utils import find_mentions
from lib.utils import getJsonKeyValue
from lib.reddit import hot
from lib.utils import pretty_date
from lib.dateencoder import DateEncoder

from lib.mobile import is_mobile_browser

import geetest

gt=geetest.geetest("b3def7f6a704f9649f2d907b1b661e70")

from qiniu import Auth
from qiniu import BucketManager
from qiniu import put_data

access_key = "DaQzr1UhFQD6im_kJJjZ8tQUKQW7ykiHo4ZWfC25"
secret_key = "Ge61JJtUSC5myXVrntdVOqAZ5L7WpXR_Taa9C8vb"
q = Auth(access_key, secret_key)
bucket = BucketManager(q)

DEBUG_FLAG = True

def do_login(self, user_id):
    user_info = self.user_model.get_user_by_uid(user_id)
    user_id = user_info["uid"]