Beispiel #1
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")
Beispiel #2
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")
Beispiel #3
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")
Beispiel #4
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")
Beispiel #5
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")
Beispiel #6
0
def user_get(request):
    content = request.GET
    response = {}
    try:
        username = content.get("username")
        if not User.objects.filter(username=username):
            response = fail_response("has such username")
            return
        response = user_message(response, username)
    except Exception as e:
        response = err_response(e)
    finally:
        return JsonResponse(response)
Beispiel #7
0
def get_by_title(request):
    content = request.GET
    response = {}
    try:
        title = content.get("title")
        if not Post.objects.filter(post_title=title):
            response = fail_response("not exits")
            return
        post = Post.objects.get(post_title=title)
        response["title"] = title
        response["content"] = post.post_content
    except Exception as e:
        response = err_response(e)
    finally:
        return JsonResponse(response)