Ejemplo n.º 1
0
def login_check(fun):
    print('-----mongo_blog----longin_check-----------')
    @wraps(fun)
    def wrapper_fun(request, *args, **kwargs):
        if {'user', 'sessionid'} <= set(request.COOKIES) and is_session_exists(request.COOKIES['sessionid']):
            return fun(request, *args, **kwargs)
        return render(request, 'login_register.html')
    return wrapper_fun
Ejemplo n.º 2
0
def register(request):
    print('----------mongo_blog-----register--------------')
    print(request.POST)
    content = check_request_type(request)
    username = content.get('username')
    password = content.get('password')
    email = content.get('email')
    User.objects.create(username=username, password=password, email=email)
    return render(request, 'login_register.html')
Ejemplo n.º 3
0
def paginator_view(request):
    print('-----------------------------')
    article_list = Article.objects.all()
    articles = paginator_tool(request, article_list)
    res = dict()
    if articles:
        res['articles'] = json.loads(serializers.serialize("json", articles))
    else:
        res['msg'] = 'vip666888'
    return JsonResponse(res)
Ejemplo n.º 4
0
def add_article(request):
    print('------------add_article--------------------')
    if request.POST:
        content = request.POST
        article_name = content.get('title')
        user_id = content.get('user_id')
        article_click = 0
        article_content = content.get('content')

        print(content)

        Article.objects.create(
            article_name=article_name,
            user_id=int(user_id),
            article_click=article_click,
            article_content=article_content,
        )
    return redirect('blog:content')
Ejemplo n.º 5
0
def logout(request):
    print('-------logout------mongo_blog-----------')
    print(request)
    if request.method == 'POST':
        print('post :  ', request.POST)
    else:
        print('get :  ', request.GET)
    logout_tool(request)
    response = redirect(reverse('blog:register_page'))
    response.delete_cookie('username')
    return response
Ejemplo n.º 6
0
def index(request):
    print('-----mongo_blog----index------------')
    # TODO: static_html
    res = dict()
    article_list = Article.objects.all()
    articles = paginator_tool(request, article_list)
    res = dict()
    if articles:
        res['articles'] = articles
    else:
        res['msg'] = '000'
    print('---------articles--------------')
    # print(res['articles'])
    # print(res['articles'].number)
    # print(res['articles'].paginator.num_pages)
    username = request.COOKIES['user']
    check = User.objects.filter(username__exact=username)
    if check:
        print('--------check---------')
        user = User.objects.get(username=username)
        res['user'] = user
        print(res)
        return render(request, 'index.html', res)
    return render(request, 'login_register.html')
Ejemplo n.º 7
0
def login(request):
    print('-----mongo_blog-------login---------------------')
    content = check_request_type(request)
    username = content.get('username')
    password = content.get('password')
    try:
        remember = content.get('remember')
    except MultiValueDictKeyError as e:
        remember = False
    print('----------------content-----------------')
    print(content)
    check = User.objects.filter(username__exact=username,
                                password__exact=password)
    if check:
        print('--------------------check------------')
        print(check[0])
        user = User.objects.get(username=username)
        response = JsonResponse({'user': username})
        # login_tool(request, user)
        print('----------------remember----------------')
        print(remember)
        # if remember is 'false':
        # request.session.set_expiry(0)
        response.set_cookie('user',
                            username,
                            expires=datetime.now() + timedelta(days=1))
        print('-----2---response-------------')
        print(response.content)
        return response
    msg = '账号或密码错误'
    return JsonResponse({'msg': msg})