美文网首页英语吧
Authentication Project: Secret P

Authentication Project: Secret P

作者: 此之木 | 来源:发表于2019-10-13 22:25 被阅读0次

    Sign Up Page

    After a complex set up process, finally we can start to write our routes!

    Step One: Write register route

    We will write our register route which will render to a “register” page. In this page, it will have a simple sign up form.

    Step Two: Create Sign up form

    We add “register.ejs” in the “views” folder. Then, we create a simple form which the url link will be “/register”.

    Then, we run the app.js and get the “/register”, so we can see the form.

    Step Three: Set up body parser

    For every form post request, we need to add body parser to make it work.

    Step Four: Handle user sign up

    Once users sign up, it will lead them to the secret page. Therefore, we need to write a post route. Inside the post route, we add passport authenticate, which will log the user in and store the correct information and run the serialize method. And we specify to use“local” strategy.

    I sign up with two user names: chai and tom. Then, I find my username in the mongodb database.

    Then, once I sign up, it shows the secret page.

    相关文章

      网友评论

        本文标题:Authentication Project: Secret P

        本文链接:https://www.haomeiwen.com/subject/azkzxctx.html