Exemplo n.º 1
0
 def clean_password(self):
     db = init_db()
     user = db.users.find_one({'username':self.data['username']})
     if user == None:
         raise forms.ValidationError('用户不存在')
     m = md5.new()
     m.update(SALT)
     m.update(self.data['password'])
     if m.hexdigest() != user['password']:
         raise forms.ValidationError('密码错误')
     return self.data['password']
Exemplo n.º 2
0
from datetime import date

from django.shortcuts import render, redirect
from django.http import HttpResponse
from django.views.decorators.http import require_GET, require_POST
from django.core.urlresolvers import reverse
from bson.objectid import ObjectId

from posts.utils import init_db, login_required


db = init_db()


@require_POST
@login_required
def create(request, post_id):
    content = request.POST['content']
    comment = {'content': content, 'post_id': ObjectId(post_id),
               'username': request.session['username']}
    comments = db.comments
    comment_id = comments.insert(comment)
    context = {"comment_id": comment_id, "post_id": post_id,
               "comment": comment}
    return render(request, 'comments/show.html', context)


@require_GET
@login_required
def destroy(request, post_id, comment_id):
    comment = db.comments.find_one({'_id': ObjectId(comment_id)})
Exemplo n.º 3
0
 def clean_username(self):
     db = init_db()
     if db.users.find({'username':self.data['username']}).count() > 0:
         raise forms.ValidationError('邮箱已经注册')
     return self.data['username']