创建密码保护的日志

FarBox本身并不提供单日志的密码保护,但是,基于模板API,我们可以实现这个功能!

来源Oyiadin, 他提供的模板源码地址。

step1, 在显示文章列表里,对输出进行控制,如果有设定密码的(通过post.metadata.password判定),则使用如下的代码(Oyiadin将其放在include/password_form.jade这个文件中调用):

form(method="post", action="{{ post.url }}")
    p
        | 这是一篇受密码保护的文章,请提供
        if post.metadata.question
            | 问题的答案
        else
            | 密码
        | 以继续查看。

    label(for="password")
        {{ post.metadata.question or "密码:" }}
    input#password(name="password")
    //- 如果设置 type=password 的话,无法输入中文。
    input(type="submit", value="提交")

step2, 在文章的详细页中,对输入密码是否正确进行判断。

if not post.metadata.password or request.form.password|string == post.metadata.password|string
    post.content
 else
    include include/password_form

    if request.form.password|string
        p
            strong 输入错误,请重试。

注意事项

收密码保护的文章,在其它模板中,如果没有对应的逻辑,则是非密保的。

另外,文章的status不能为public, 因为可以通过?action=show_json来查看public的日志各种属性。

比如Oyiadin是用这种方式获取posts变量的:get_data(type='post', status=['public', 'secret'])

最终效果如图

Post Password

  • d2014-03-15 08:44

    Emz, looks nice!!!

  • Hey Ⅰ am so thгilled I fοund your webpage, I
    really found you by mistake, while I was researchіng on Dіgg for something else, Anyways I am herᥱ now and would just
    like to say kudos for a tremendous post and a all round entᥱrtaining blog (I also love the
    theme/design), I don’t have time to read it all at the minute but I haᴠe
    book-maгkeԁ it and also added youг RSS feeds, so when I
    have time I will be bаck to read much more, Please do keep up the grᥱat work.

  • derm exclusive tv offer2017-03-30 18:27

    Ꮲretty nice post. I simply stumbled upon your weblog and wanteԁ to mentiоn that I've trulү loved browsing your weblog
    posts. After aⅼl I wilⅼ be subscribing for
    your feed and I'm hoping you write once more very soon!

  • Mikki2018-08-09 08:23

    I'm not sure exactly why but this web site is loading very slow for me.

    Is anyone else having this problem or is it a problem on my end?
    I'll check back later on and see if the problem still exists.

  • pkmongobot2018-09-02 05:27

    aku metasa ini adalah salah satu dari begitu tidak sedikit berita utana bagi saya & aku
    senang mencarri ilmu artikel kamu namun harus di observasi
    kepada beberapa isu umum, cita rasa situs amat sangat
    ideal, artikelnya tefamat keren D. pekerjaan bagus sorak sorai.

  • 안전놀이터2018-09-23 08:37

    Hi! This is my first visit to your blog! We are a collection of volunteers and starting a new project in a community in the same niche.
    Your blog provided us valuable information to work on. You have done a
    extraordinary job!

  • 모바일바카라2018-09-25 00:50

    Magnificent beat ! I would like to apprentice while
    you amend your site, how could i subscribe for a blog site?

    The account aided me a acceptable deal. I had been a little
    bit acquainted of this your broadcast offered bright clear concept

  • Danny2018-10-08 14:40

    博主你好,我想请问http://superdannyblog.farbox.com/我之前的这个模板在bitcron里面能否提供,现在因为没有这个模板一直迟迟没迁移过去。希望能够解答我这个疑惑。

  • 666.porn cheerleader sex2018-12-01 07:25

    Hey there! Someone in my Myspace group shared this website with us so I came to check it out.
    I'm definitely enjoying the information. I'm bookmarking and will be tweeting
    this to my followers! Great blog and amazing design and style.

  • Kennith2019-01-15 08:55

    Would you like to be abgle too defhse your fears or
    worries more frequently than it is possible to at present.
    Sometimes individuals have excessive responses of fear or anxiety
    to circukstances that do not cause these responses too others.
    Apart from alll of these the imbalance in tridoshas also cause impotence or erectile dysfunction.

  • 카지노사이트2019-01-17 21:54

    Have you ever thought about adding a little bit more than just your
    articles? I mean, what you say is fundamental and all.
    Nevertheless imagine if you added some great visuals or video clips
    to give your posts more, "pop"! Your content is excellent but with pics
    and video clips, this website could undeniably be one of the best in its field.
    Amazing blog!

  • 카지노사이트2019-01-18 18:30

    If some one needs expert view regarding blogging and site-building then i advise him/her to go to see this webpage, Keep up the good work.