Documentation ¶
Index ¶
- Constants
- func CheckNewPassword(newPassword string) error
- func CreateSalt(len int) string
- type User
- func (user *User) Authenticate(token string) error
- func (user *User) ChangePassword(oldPassword, newPassword string) error
- func (user *User) CheckExpirationDates() error
- func (user *User) CheckPassword(testPassword string) error
- func (user *User) ConfirmLostPassword(lostPwdToken string) (err error)
- func (user *User) CreateToken() string
- func (user *User) GenerateGuid()
- func (user *User) GenerateLostPassword() (newPassword string, err error)
- func (user *User) GetCreatedAtStr() string
- func (user *User) GetDeletedAtStr() string
- func (user *User) GetFailCountStr() string
- func (user *User) GetID() int
- func (user *User) GetLastAuthAtStr() string
- func (user *User) GetLastFailedAtStr() string
- func (user *User) GetLoginAtStr() string
- func (user *User) GetLogoutAtStr() string
- func (user *User) GetMaxSessionAtStr() string
- func (user *User) GetTimeoutStr() string
- func (user *User) GetUpdatedAtStr() string
- func (user *User) Login(password string) error
- func (user *User) Logout() error
- func (user *User) SetCreatedAt(t time.Time) error
- func (user *User) SetDeletedAt(t time.Time) error
- func (user *User) SetDomain(val string) error
- func (user *User) SetEmail(val string) error
- func (user *User) SetFailCount(i int) error
- func (user *User) SetGuid(val string) error
- func (user *User) SetID(id int) error
- func (user *User) SetIsActive(val bool) error
- func (user *User) SetIsLoggedIn(val bool) error
- func (user *User) SetIsSystem(val bool) error
- func (user *User) SetLastAuthAt(t time.Time) error
- func (user *User) SetLastFailedAt(t time.Time) error
- func (user *User) SetLoginAt(t time.Time) error
- func (user *User) SetLoginName(name string) error
- func (user *User) SetLogoutAt(t time.Time) error
- func (user *User) SetMaxSessionAt(t time.Time) error
- func (user *User) SetName(name string) error
- func (user *User) SetPassword(newPassword string) error
- func (user *User) SetPasswordStr(pwd string) error
- func (user *User) SetSalt(val string) error
- func (user *User) SetTimeoutAt(t time.Time) error
- func (user *User) SetToken(val string) error
- func (user *User) SetUpdatedAt(t time.Time) error
- func (u *User) String() string
- type UserCli
- type UserControl
- type UserInterface
- type UserJson
Constants ¶
const ( USER_OK = iota USER_EXPIRED = iota USER_INVALID = iota USER_PASSWD_TOO_SHORT = iota USER_PASSWORD_TOO_SIMPLE = iota )
const USER_STORE_NAME = "User"
Standard name for the user store.
Variables ¶
This section is empty.
Functions ¶
func CheckNewPassword ¶
func CreateSalt ¶
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 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 ¶
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 ¶
ChangePassword to the new password. The user must be logged in for this
func (*User) CheckExpirationDates ¶
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) ConfirmLostPassword ¶
func (*User) CreateToken ¶
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 ¶
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) GetDeletedAtStr ¶
func (*User) GetFailCountStr ¶
func (*User) GetLastAuthAtStr ¶
func (*User) GetLastFailedAtStr ¶
func (*User) GetLoginAtStr ¶
func (*User) GetLogoutAtStr ¶
func (*User) GetMaxSessionAtStr ¶
func (*User) GetTimeoutStr ¶
func (*User) GetUpdatedAtStr ¶
func (*User) Logout ¶
Logout will mark the record as 'logged out' and the user will be removed from the system
func (*User) SetFailCount ¶
func (*User) SetIsActive ¶
func (*User) SetIsLoggedIn ¶
func (*User) SetIsSystem ¶
func (*User) SetLoginName ¶
func (*User) SetPassword ¶
func (*User) SetPasswordStr ¶
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