コード例 #1
0
ファイル: view.py プロジェクト: Yoogur/django-vue
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")
コード例 #2
0
ファイル: view.py プロジェクト: Yoogur/django-vue
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")
コード例 #3
0
ファイル: view.py プロジェクト: Yoogur/django-vue
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")
コード例 #4
0
ファイル: view.py プロジェクト: Yoogur/django-vue
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")
コード例 #5
0
ファイル: view.py プロジェクト: Yoogur/django-vue
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")
コード例 #6
0
ファイル: view.py プロジェクト: Yoogur/django-vue
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)
コード例 #7
0
ファイル: view.py プロジェクト: Yoogur/django-vue
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)