Ejemplo n.º 1
0
def post_del(request):
    content = request.GET
    postId = content.get('postId')
    if not Post.objects.filter(id=postId):
        return fail_response("this post not exits")
    post = Post.objects.get(id=postId)
    post.delete()
    return success_response("success delete")
Ejemplo n.º 2
0
def post_publish(request):
    post = Post()
    content = request.POST
    title, content = content.get('title'), content.get("content")
    if not title or not len(title.replace(" ", "")):
        return fail_response("has null title")
    post.config(title, content)
    post.save()
    return success_response("success publish")
Ejemplo n.º 3
0
def user_register(request):
    content = request.POST
    username, nickname, password = content.get("username"), content.get(
        "nickname"), content.get("password")
    if User.objects.filter(username=username):
        return fail_response("not has such username")
    user = User()
    user.Config(username, nickname, password)
    user.save()
    return success_response("success register")
Ejemplo n.º 4
0
def user_login(request):
    content = request.GET
    username, password = content.get("username"), content.get("password")

    if not username or not password:
        return fail_response("username or password is null")
    if not User.objects.filter(username=username):
        return fail_response("username or password is error")
    user = User.objects.get(username=username)
    if not user.password == password:
        return fail_response("username or password is error")

    return success_response("success login")
Ejemplo n.º 5
0
def user_modify(request):
    content = request.POST
    username = content.get("username")
    if not username:
        return fail_response("username is null")
    if not User.objects.filter(username=username):
        return fail_response("not has such user")
    user = User.objects.get(username=username)
    for key in content.keys():
        if hasattr(user, key):
            value = content.get(key)
            setattr(user, key, value)
    user.save()
    return success_response("success modify")