user

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 31, 2017 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Manager

type Manager interface {
	Storer

	Authenticate(username string, secret []byte) (*User, error)
}

Manager provides a generic interface to users in order to build a DataStore

type MongoManager

type MongoManager struct {
	// DB is the Mongo connection that holds the base session that can be copied and closed.
	DB     *mgo.Database
	Hasher fosite.Hasher
}

MongoManager manages the Mongo Session instance of a User. Implements user.Manager.

func (*MongoManager) Authenticate

func (m *MongoManager) Authenticate(username string, secret []byte) (*User, error)

Authenticate wraps AuthenticateByUsername to allow users to be found via their username. Returns a user record if authentication is successful.

func (*MongoManager) AuthenticateByID

func (m *MongoManager) AuthenticateByID(id string, secret []byte) (*User, error)

AuthenticateByID gets the stored user by ID and authenticates it using a hasher

func (*MongoManager) AuthenticateByUsername

func (m *MongoManager) AuthenticateByUsername(username string, secret []byte) (*User, error)

AuthenticateByUsername gets the stored user by username and authenticates it using a hasher

func (*MongoManager) CreateUser

func (m *MongoManager) CreateUser(u *User) error

CreateUser stores a new user into mongo

func (*MongoManager) DeleteUser

func (m *MongoManager) DeleteUser(id string) error

DeleteUser removes a user from mongo

func (*MongoManager) GetUser

func (m *MongoManager) GetUser(id string) (*User, error)

GetUser gets a user document that has been previously stored in mongo

func (*MongoManager) GetUserByUsername

func (m *MongoManager) GetUserByUsername(username string) (*User, error)

GetUserByUsername gets a user document by searching for a username that has been previously stored in mongo

func (*MongoManager) GetUsers

func (m *MongoManager) GetUsers(orgid string) (map[string]User, error)

GetUsers returns a map of IDs mapped to a User object that are stored in mongo

func (*MongoManager) GrantScopeToUser

func (m *MongoManager) GrantScopeToUser(id string, scope string) error

GrantScopeToUser adds a scope to a user if it doesn't already exist in the mongo record

func (*MongoManager) RemoveScopeFromUser

func (m *MongoManager) RemoveScopeFromUser(id string, scope string) error

RemoveScopeFromUser takes a scoped right away from the given user.

func (*MongoManager) UpdateUser

func (m *MongoManager) UpdateUser(u *User) error

UpdateUser updates a user record. This is done using the equivalent of an object replace.

type Storer

type Storer interface {
	GetConcreteUser(id string) (*User, error)
	GetUser(id string) (User, error)
	GetUsers() (map[string]User, error)
	CreateUser(u *User) error
	UpdateUser(u *User) error
	DeleteUser(id string) error
	GrantScope(scope string) error
	RemoveScope(scope string) error
	AuthenticateByID(id string, secret []byte) (*User, error)
	AuthenticateByUsername(username string, secret []byte) (*User, error)
}

Storer provides a definition of specific methods that are required to store a User in a data store.

type User

type User struct {
	// ID is the uniquely assigned uuid that references the user
	ID string `bson:"_id" json:"id" xml:"id"`

	// The organisation the user belongs to
	OrganisationID string `bson:"organisation_id,omitempty" json:"organisation_id,omitempty" xml:"organisation_id,omitempty"`

	// Username is used to authenticate a user
	Username string `bson:"username" json:"username" xml:"username"`

	//
	Password string `bson:"password" json:"-" xml:"-"`

	// Scopes contains the scopes that have been granted to
	Scopes []string `bson:"scopes" json:"scopes" xml:"scopes"`

	// FirstName stores the user's Last Name
	FirstName string `bson:"first_name" json:"first_name" xml:"first_name"`

	// LastName stores the user's Last Name
	LastName string `bson:"last_name" json:"last_name" xml:"last_name"`

	// ProfileURI is a pointer to where their profile picture lives
	ProfileURI string `bson:"profile_uri" json:"profile_uri,omitempty" xml:"profile_uri,omitempty"`
}

User provides the specific types for storing, editing, deleting and retrieving a User record in mongo.

func (User) Authenticate

func (u User) Authenticate(cleartext string, hasher fosite.Hasher) error

Authenticate compares a cleartext string against the user's

func (User) GetFullName

func (u User) GetFullName() (fn string)

GetFullName concatenates the User's First Name and Last Name for templating purposes

func (*User) GetHashedSecret

func (u *User) GetHashedSecret() []byte

GetHashedSecret returns the Users's Hashed Secret as a byte array

func (*User) SetPassword

func (u *User) SetPassword(cleartext string, hasher fosite.Hasher) (err error)

SetPassword takes a cleartext secret, hashes it with a hasher and sets it as the user's password

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL