Skip to content

Latest commit

 

History

History
235 lines (213 loc) · 7.36 KB

Guide.md

File metadata and controls

235 lines (213 loc) · 7.36 KB

#User Management User Management is a suite of packages for the Meteor.js platform. It provides customizable user management UI templates for different front-end frameworks (currently only Polymer, but more will follow soon). At the moment it includes Forms for listing, showing, editing and creatign users. This package depends on and is built based on the useraccounts package suite, which you should look into if you are not familiar with it. (https://github.com/meteor-useraccounts/core)

#Documentation ##Features

  • security aware
  • robust validation
  • fully reactive
  • easily styleable and extandable

##Quick Start ###Available Versions

  • softbricks:user-management-polymer styled for Polymer
  • plus others coming soon

###Setup Choos one of the packages from the available styled versions and istall it:

meteor add softbricks:user-management-polymer

Note 1: no additional packages nor CSS/LESS/SASS files providing styles are included by useraccounts packages. This is to let you choose your preferred way to include them!

Note 2: You don't have to add softbricks:user-management to your app! It is automatically added when you add useraccounts:...

###Templates available Templates for you to use in your code:

  • umShowUsers
  • umShowUser
  • umEditUser
  • umAddUser

You can add these to your code as you would with any other template:

{{> umShowUsers}}

##Basic Customization ###I18n Support (Not done yet!) i18n is achieved using accounts-t9n. The only thing you have to do is ensure

T9n.setLanguage('<lang>');

is called somewhere, whenever you want to switch language. ###Configuration API For configuration and interaction there is the UserManagementTemplates Object, which is exposed globally for you to use. There are basically two different ways to interact with UserManagementTemplates for basic configuration:

  • UserManagementTemplates.configureRoute(route_code, options);
  • (UserManagementTemplates.configure(options); coming soon)

These functions should be called in top-level code, not inside Meteor.startup().
There is no specific order for the above calls to be effective, and you can do many of them possibly in different files

Routing

There are no routes provided by default. But you can easily configure routes for showing a user list, showing specific users, editing users and adding users using UserManagementTemplates.configureRoute. This is done internally relying on the Iron-Router package.
The simplest way is to make the call passing just the route code (available codes are: showUsers, showUser, editUser, addUser):

UserManagementTemplates.configureRoute('showUsers');

This will setup the show users route with a list of all registered users.
But you can also pass in more options to adapt it to your needs with:

UserManagementTemplates.configureRoute(route_code, options);

The following is a complete example of a route configuration:

AccountsTemplates.configureRoute('signIn', {
    name: 'signin',
    path: '/login',
    template: 'myLogin',
    layoutTemplate: 'myLayout',
});

Fields name, path, template, and layoutTemplate are passed down directly to Router.map

Action route_code Route Name Route Path Template
list all users showUsers umShowUsers /showUsers umShowUsers
show details of one user showUser umShowUser /showUser/:userId umShowUser
edit a user editUser umEditUser /editUser/:userId umEditUser
add a user addUser umAddUser /addUser umAddUser
add a group addGroup umAddGroup /addGroup umAddGroup
show groups showGroups umShowGroups /showGroups umShowGroups
show a group showGroup umShowGroup /showGroup/:groupId umShowGroup
edit a group editGroup umEditGroup /editGroup/:groupId umEditGroup
manage roles manageRoles umManageRoles /manageRoles umManageRoles
add a roles addRole umAddRole /addRole umAddRole
add a group role addGroupRole umAddGroupRole /editGroup/:groupId/addGroupRole umAddGroupRole
add a user to a group role addUserToGroupRole umAddUserToGroupRole /editGroup/:groupId/addUserToGroupRole/:userId umAddUserToGroupRole
If `layoutTemplate` is not specified, it falls back to what is currently set up with Iron-Router

Schemas

User Schema

// User Schema
{
    emails: [],
    emails.$.address: SimpleSchema.RegEx.Email,
    emails.$.verified: Boolean,
    username: String,
    profile: {
        fullname: String,
        activated: Boolean, //should be 'active' ?
        fields: {}, // will be filled later with additional fields collection
    },
    createdAt: Date
    services: {} // what is this for?
    roles: [String]
}

Additional fields Schema

// Additional Fields Schema
{
    key: String
    label: String
}

Merging Schemas is supported by SimpleSchema/Collection2:

"If the schemas are attached to collections using collection2, then package users can simply attach their extension schema after that, and the two schemas will be merged."

This means, that once the additional fields collection is updated, we simply attach another (manipulated) schema to the Meteor.users collection. When a field is removed, we need some more logic to clear up the collections. This is how it works:

var fields = AdditionalFields.find();
var extendingSchema = {
    fields: {}
};
fields.forEach(function(field){
    extendingSchema.fields[field.key] = {
        type: String,
        label: field.label,
        optional: true
    }
});
Meteor.users.attachSchema(extendingSchema); // wont overwrite but will extend :)

Group Schema

// Group Schema
{
    groupname: String,
    leader: String,
    parentGroup: String,
    users: [Object] // should be members!
    users.$.id: String // easier to use like this, instead of list of strings
}

If groups are added, the user schema needs to be extended with this:

// Extension for user schema
{
    profile: {
        groups: [Object]
        groups.$.id: String // easier to use like this, instead of list of strings
    }
}