Code Monkey home page Code Monkey logo

accounts-entry's Introduction

Stories in Ready

Meteor accounts-entry Build Status

accounts-entry is a meteor package that relies on Iron Router and provides an alternative interface to accounts-ui, with whole pages for sign up and sign in.

Getting started

Run:

meteor add joshowens:accounts-entry

You can install the accounts-ui package, as it is still used for OAuth setup.

We wanted something to work with that used Iron Router, Bootstrap 3, and didn't require the forcing of the dropdown box that didn't seem to be easily styled. But we love the ease of adding more packages like accounts-facebook or accounts-twitter, so we fully support the OAuth packages by adding buttons to let people sign-up/sign-in with those services if you add them. By default, accounts-entry doesn't offer email/password login functionality. If you meteor add accounts-password, accounts-entry will offer your users the option to sign-up/sign-in with a username and password.

Example

Examples of the package in action (check out the sign up or sign in links):

Changelog

Compatibility

accounts-entry is presently compatible with Iron Router 1.0.3 and above.

Provided routes

You will get routes and the necessary templates for:

/sign-in
/sign-out
/sign-up
/forgot-password
/verification-pending

You can then either add links to those directly, or use the {{ special }} helper we provide to give you the apppropriate links for signed-in/signed-out users. The {{ special }} helper will display a sign-out link and the user's email address when they are signed-in.

Ensuring signed in users for routes

Simply add the following line of code: AccountsEntry.signInRequired(this); to require users be signed in for a route and to redirect the user to the included sign-in page and stop any rendering. Accounts-entry also tracks where the user was trying to go and will route them back after sign in.

Here is an Iron-Router route example:

  this.route('userProfile', {
    path: '/profile',
    template: 'profile',
    onBeforeAction: function () {
      AccountsEntry.signInRequired(this);
    }
  });

Setting up password login

Use mrt add accounts-password if you want to have email/username login authentication options. This is now optional and will only display if installed. You need to configure an OAuth option if you choose not to have password logins.

Setting up OAuth/social integrations

Use accounts-ui to configure your social/OAuth integrations (or manually create records in your database, if you have those skills). We don't have the nice instructions on how to configure the services built into this package, but if you choose to use {{ loginButtons }} elsewhere in your application (even temporarily), you can configure OAuth logins there.

Configuration

Signup codes

We have added support for a signupCode in case you want to have a special code to handout to keep signups at a pace you want. This code is checked if you turn on the client and server side options listed below.

The signup code is only checked for accounts-password logins, so know that OAuth logins will still allow people in.

In CLIENT code only

Since this is a young package, we are maintaining compatibility with accounts-ui (so if in a pinch accounts-entry is broken for you, you could easily switch to accounts-ui). We also use the UI for oauth configs from accounts-ui.

  Meteor.startup(function () {
    AccountsEntry.config({
      logo: 'logo.png'                  // if set displays logo above sign-in options
      privacyUrl: '/privacy-policy'     // if set adds link to privacy policy and 'you agree to ...' on sign-up page
      termsUrl: '/terms-of-use'         // if set adds link to terms  'you agree to ...' on sign-up page
      homeRoute: '/'                    // mandatory - path to redirect to after sign-out
      dashboardRoute: '/dashboard'      // mandatory - path to redirect to after successful sign-in
      profileRoute: 'profile'
      passwordSignupFields: 'EMAIL_ONLY'
      showSignupCode: true
      showOtherLoginServices: true      // Set to false to hide oauth login buttons on the signin/signup pages. Useful if you are using something like accounts-meld or want to oauth for api access
      extraSignUpFields: [{             // Add extra signup fields on the signup page
        field: "name",                           // The database property you want to store the data in
        name: "This Will Be The Initial Value",  // An initial value for the field, if you want one
        label: "Full Name",                      // The html lable for the field
        placeholder: "John Doe",                 // A placeholder for the field
        type: "text",                            // The type of field you want
        required: true                           // Adds html 5 required property if true
       }]
       useSchema: Schemas.User          // Sign Up form will use SimpleSchema fields, don't forget to use {autoform: { omit: true}} for server only fields
       fluidLayout: false               // Set to true to use bootstrap3 container-fluid and row-fluid classes.
       useContainer: true               // Set to false to use an unstyled "accounts-entry-container" class instead of a bootstrap3 "container" or "container-fluid" class. 
       signInAfterRegistration: true    // Set to false to avoid prevent users being automatically signed up upon sign-up e.g. to wait until their email has been verified. 
       emailVerificationPendingRoute: '/verification-pending' // The route to which users should be directed after sign-up. Only relevant if signInAfterRegistration is false.
       showSpinner: true                // Show the spinner when the client is talking to the server (spin.js)
       spinnerOptions: { color: "#000", top: "80%" } // options as per [spin.js](http://fgnass.github.io/spin.js/)

    });
  });

Using Schemas

Here a brief sample of Schema, inspired in aldeed:collection sample

Schema = {};

// Notice that just UserProfile will be used
Schema.UserProfile = new SimpleSchema({
  firstName: {
    type: String,
    regEx: /^[a-zA-Z-]{2,25}$/,
  },
  lastName: {
    type: String,
    regEx: /^[a-zA-Z]{2,25}$/,
  },
  birthday: {
    type: Date,
  },
  gender: {
    type: String,
    allowedValues: [ 'M', 'F' ],
    optional: true
  }
});

Schema.User = new SimpleSchema({
  emails: {
    type: [ Object ],
    // this must be optional if you also use other login services like facebook,
    // but if you use only accounts-password, then it can be required
    autoform: { omit: true }
  },
  "emails.$.address": {
    type: String,
    regEx: SimpleSchema.RegEx.Email,
  },
  "emails.$.verified": {
    type: Boolean
  },
  createdAt: {
    type: Date,
    autoform: { omit: true }
  },
  profile: {
    type: Schema.UserProfile,
    optional: true
  },
  services: {
    type: Object,
    blackbox: true,
    autoform: { omit: true }, // Notice you have to omit this to not be recognized by AutoForm
  },
  
  // Option 2: [String] type
  // If you are sure you will never need to use role groups, then
  // you can specify [String] as the type
  roles: {
    type: [ String ],
    optional: true,
    autoform: { omit: true }
  }
});

Meteor.users.attachSchema( Schema.User );

In SERVER code only

Call AccountsEntry.config with a hash of optional configuration:

  Meteor.startup(function () {
    AccountsEntry.config({
      signupCode: 's3cr3t',         // only restricts username+password users, not OAuth
      defaultProfile:
          someDefault: 'default',
       addRolesAtSignUp: []             // You can specify roles to be added at sign up, you have to add alanning:roles package. (Just strings by now)
    });
  });

Note: only set a signupCode if you want to use that feature.

The default configuration includes:

  wrapLinks: true                   // wraps accounts-entry links in <li> for bootstrap compatability purposes
  homeRoute: '/'                    // MUST BE SET - redirect to this path after sign-out
  dashboardRoute: '/dashboard'      // MUST BE SET - redirect to this path after sign-in

Remember, you must provide a route for home (used when signing out) and dashboard (used after signing in).

Interested in building a quick meteor app that starts with Accounts-Entry?

We've created a meteor-boilerplate repo that you can clone as a starting point for an app. It follows all our standards that we use for building apps for our clients.

accounts-entry's People

Contributors

alesvaupotic avatar alethes avatar ameagher avatar art1sec8 avatar benmgreene avatar bshardi avatar cfly15 avatar cunneen avatar dandv avatar dkoo761 avatar eahefnawy avatar fakenickels avatar fix avatar gaborpop avatar hellogerard avatar musgravejw avatar noamyoungerm avatar pahans avatar pavel-kurnosov avatar pwldp avatar queso avatar rgoomar avatar robertlowe avatar ryw avatar scole96 avatar seriousm avatar softwarerero avatar spencercarli avatar splendido avatar timbrandin avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.