Adding Users

6

Μεταφρασμένο Ποσοστό

Σε αυτό το κεφάλαιο θα:

  • Learn about user accounts in Meteor.
  • Add all the authentication we'll need for Microscope.
  • Use the built-in accounts-ui package to get an instant user interface.
  • ////

    ////

    ////

    Accounts: users made simple

    ////

    ////

    ////

    meteor add ian:accounts-ui-bootstrap-3
    meteor add accounts-password
    
    Terminal

    ////

    ////

    <template name="layout">
      <div class="container">
        {{> header}}
        <div id="main" class="row-fluid">
          {{> yield}}
        </div>
      </div>
    </template>
    
    client/templates/application/layout.html
    <template name="header">
      <nav class="navbar navbar-default" role="navigation">
        <div class="container-fluid">
          <div class="navbar-header">
            <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navigation">
              <span class="sr-only">Toggle navigation</span>
              <span class="icon-bar"></span>
              <span class="icon-bar"></span>
              <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand" href="{{pathFor 'postsList'}}">Microscope</a>
          </div>
          <div class="collapse navbar-collapse" id="navigation">
            <ul class="nav navbar-nav navbar-right">
              {{> loginButtons}}
            </ul>
          </div>
        </div>
      </nav>
    </template>
    
    client/templates/includes/header.html

    ////

    Meteor's built-in accounts UI
    Meteor’s built-in accounts UI

    ////

    ////

    Accounts.ui.config({
      passwordSignupFields: 'USERNAME_ONLY'
    });
    
    client/helpers/config.js

    Commit 6-1

    Added accounts and added template to the header

    Creating Our First User

    ////

    ////

     Meteor.users.findOne();
    
    Browser console

    ////

    ////

     Meteor.users.find().count();
    1
    
    Browser console

    ////

    ////

    > db.users.count()
    2
    
    Mongo console

    ////

    A Mystery Publication!

    ////

    ////

    ////

    ////

    ////

    ////

    > db.users.findOne()
    {
        "createdAt" : 1365649830922,
        "_id" : "kYdBd9hr3fWPGPcii",
        "services" : {
            "password" : {
                "srp" : {
                    "identity" : "qyFCnw4MmRbmGyBdN",
                    "salt" : "YcBjRa7ArXn5tdCdE",
                    "verifier" : "df2c001edadf4e475e703fa8cd093abd4b63afccbca48fad1d2a0986ff2bcfba920d3f122d358c4af0c287f8eaf9690a2c7e376d701ab2fe1acd53a5bc3e843905d5dcaf2f1c47c25bf5dd87764d1f58c8c01e4539872a9765d2b27c700dcdedadf5ac82521467356d3f91dbeaf9848158987c6d359c5423e6b9cabf34fa0b45"
                }
            },
            "resume" : {
                "loginTokens" : [
                    {
                        "token" : "BMHipQqjfLoPz7gru",
                        "when" : 1365649830922
                    }
                ]
            }
        },
        "username" : "tmeasday"
    }
    
    Mongo console

    ////

     Meteor.users.findOne();
    Object {_id: "kYdBd9hr3fWPGPcii", username: "tmeasday"}
    
    Browser console

    ////

    ////