tenant

package
v0.0.0-...-51d629d Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2016 License: BSD-3-Clause, BSD-3-Clause Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	USER_OK                  = iota
	USER_EXPIRED             = iota
	USER_INVALID             = iota
	USER_PASSWD_TOO_SHORT    = iota
	USER_PASSWORD_TOO_SIMPLE = iota
)
View Source
const USER_STORE_NAME = "User"

Standard name for the user store.

Variables

This section is empty.

Functions

func CheckNewPassword

func CheckNewPassword(newPassword string) error

func CreateSalt

func CreateSalt(len int) string

CreateSalt will create a magic number for use with other functions, like creating a GUID or a token.

Types

type User

type User struct {
	Id       int
	FullName string `name:"User's fullname" help:"User's full name (title, first, surname)"`
	Email    string `name:"User's email address" help:"User's email address."`
	IsSystem bool   `name:"System user" help:"True if the this is a client otherwise a standard user"`

	Guid string `name:"User's GUID" help:"How the user is identified by this system. A unique key"`

	Domain    string `name:"Domain" help:"The group that the user belongs to"`
	LoginName string `name:"Login name" help:"The name the user uses to login with"`
	Password  string `name:"Encrypted password" help:"This is the user's encrypted password."`
	Token     string // Generated at login-time

	Salt string // Magic number used to hash values for user

	IsActive   bool `name:"User is enabled"   help:"If disabled, the user will not be able to login"`
	IsLoggedIn bool // Is this user currently logged in

	LoginAt      time.Time // Last login time
	LogoutAt     time.Time // Last logout time
	LastAuthAt   time.Time // Last successful Authorisation
	LastFailedAt time.Time // Last failed login
	FailCount    int       // Current number of failed logins

	MaxSessionAt time.Time // When they MUST logout by
	TimeoutAt    time.Time // Required to authenticate by

	CreatedAt time.Time // Creation date (immutable)
	UpdatedAt time.Time // Last updated
	DeletedAt time.Time // When deleted

}

User is the internal record used to store all of the data that is held for a single user. The database routines need to take care of serialising/mapping the data out to long-term storage (DB, File, etc.)

func NewTestUser

func NewTestUser() *User

NewTestUser will generate a nonsense test user

func NewUser

func NewUser() *User
  • PUBLIC ROUTINES
  • -- User --

NewUser creates a new, empty user record. The domain is set to blank and the "Salt" field is a crypto-random number in order to produce unique values

func (*User) Authenticate

func (user *User) Authenticate(token string) error

Authenticate checks the user's token to see if it is valid. This is a post-login process The user's record should be saved after this operation

func (*User) ChangePassword

func (user *User) ChangePassword(oldPassword, newPassword string) error

ChangePassword to the new password. The user must be logged in for this

func (*User) CheckExpirationDates

func (user *User) CheckExpirationDates() error

CheckExpirationDates will see if the token is valid or expired. If it is expired, the token will be cleared and the proper status will be set

func (*User) CheckPassword

func (user *User) CheckPassword(testPassword string) error

func (*User) ConfirmLostPassword

func (user *User) ConfirmLostPassword(lostPwdToken string) (err error)

func (*User) CreateToken

func (user *User) CreateToken() string

CreateToken will generate a short-use token for confirmation with authentication. The token can be used as a ticket until it expires. Any program can gain access to user information with it.

func (*User) GenerateGuid

func (user *User) GenerateGuid()

Generate a unique GUID for the user record. This GUID will be based upon random numbers and the creation string.

func (*User) GenerateLostPassword

func (user *User) GenerateLostPassword() (newPassword string, err error)

This is used when a user loses their password. They request a password reset based upon their email address. If they are logged in, they will not be able to reset the password ( 'User still logged in'). When they are NOT logged in, a token is generated and set. The client program later calls this with the email address AND the token. When this is confirmed, the password is then set to the value of the token and the user can go ahead and login as normal.

func (*User) GetCreatedAtStr

func (user *User) GetCreatedAtStr() string

func (*User) GetDeletedAtStr

func (user *User) GetDeletedAtStr() string

func (*User) GetFailCountStr

func (user *User) GetFailCountStr() string

func (*User) GetID

func (user *User) GetID() int

func (*User) GetLastAuthAtStr

func (user *User) GetLastAuthAtStr() string

func (*User) GetLastFailedAtStr

func (user *User) GetLastFailedAtStr() string

func (*User) GetLoginAtStr

func (user *User) GetLoginAtStr() string

func (*User) GetLogoutAtStr

func (user *User) GetLogoutAtStr() string

func (*User) GetMaxSessionAtStr

func (user *User) GetMaxSessionAtStr() string

func (*User) GetTimeoutStr

func (user *User) GetTimeoutStr() string

func (*User) GetUpdatedAtStr

func (user *User) GetUpdatedAtStr() string

func (*User) Login

func (user *User) Login(password string) error

Login will authenticate the user and create the tokens required later

func (*User) Logout

func (user *User) Logout() error

Logout will mark the record as 'logged out' and the user will be removed from the system

func (*User) SetCreatedAt

func (user *User) SetCreatedAt(t time.Time) error

func (*User) SetDeletedAt

func (user *User) SetDeletedAt(t time.Time) error

func (*User) SetDomain

func (user *User) SetDomain(val string) error

SetDomain will set the domain name for this record.

func (*User) SetEmail

func (user *User) SetEmail(val string) error

func (*User) SetFailCount

func (user *User) SetFailCount(i int) error

func (*User) SetGuid

func (user *User) SetGuid(val string) error

func (*User) SetID

func (user *User) SetID(id int) error

Set, or reset, the user's ID. When an ID is set, the GUID is reset.

func (*User) SetIsActive

func (user *User) SetIsActive(val bool) error

func (*User) SetIsLoggedIn

func (user *User) SetIsLoggedIn(val bool) error

func (*User) SetIsSystem

func (user *User) SetIsSystem(val bool) error

func (*User) SetLastAuthAt

func (user *User) SetLastAuthAt(t time.Time) error

func (*User) SetLastFailedAt

func (user *User) SetLastFailedAt(t time.Time) error

func (*User) SetLoginAt

func (user *User) SetLoginAt(t time.Time) error

func (*User) SetLoginName

func (user *User) SetLoginName(name string) error

func (*User) SetLogoutAt

func (user *User) SetLogoutAt(t time.Time) error

func (*User) SetMaxSessionAt

func (user *User) SetMaxSessionAt(t time.Time) error

func (*User) SetName

func (user *User) SetName(name string) error

SetName sets the fullname for the user

func (*User) SetPassword

func (user *User) SetPassword(newPassword string) error

func (*User) SetPasswordStr

func (user *User) SetPasswordStr(pwd string) error

func (*User) SetSalt

func (user *User) SetSalt(val string) error

func (*User) SetTimeoutAt

func (user *User) SetTimeoutAt(t time.Time) error

func (*User) SetToken

func (user *User) SetToken(val string) error

func (*User) SetUpdatedAt

func (user *User) SetUpdatedAt(t time.Time) error

func (*User) String

func (u *User) String() string

type UserCli

type UserCli struct {
	FullName  string `name:"User's full name"     help:"The full user's name (title, first and last) of the user."`
	LoginName string `name:"User's login id"      help:"This is what the user would use to identify themselves to the system."`
	Email     string `name:"User's email address" help:"The user's real email address, if available."`
	Domain    string `name:"User's group"         help:"What group, or domain, does this user belong to."`
	Password  string `name:"Password"             help:"Password for user"`

	Level  string // Level for the user. From the flags set.
	Enable bool   `name:"Enable"               help:"Enable user record"`
}

UserCli contains tags used for prompting

func NewUserCli

func NewUserCli() *UserCli

type UserControl

type UserControl struct {
	MaximumSessionDuration  time.Duration
	TimeSinceAuthentication time.Duration
}

func (*UserControl) SetMaxDuration

func (uc *UserControl) SetMaxDuration(interval string) (err error)

SetMaxDuration will take a maximimum time a user can have a session alive

func (*UserControl) SetTimeout

func (uc *UserControl) SetTimeout(interval string) (err error)

SetTimeout will take an interval string used to set the timeout required before an authentication must happen

type UserInterface

type UserInterface interface {
	Login(string) error
	Logout()
	ChangePassword(oldPassword, newPassword string) error
	Authenticate(token string) error
}

UserInterface defines what is required for a user record.

type UserJson

type UserJson struct {
	FullName  string
	Email     string
	LoginName string
	Password  string
}

This is the minimum data needed for a user's record. It is NOT used for anything other than a minimum set.

Jump to

Keyboard shortcuts

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