// User represents a user returned from AuthenticatorService
typeUserstruct{
Usernamestring`json:"username"`
Namestring`json:"name"`
Surnamestring`json:"surname"`
FullNamestring`json:"fullName"`
Emailstring`json:"email"`
}
// WithDefaultFullName is a utility that returns a copy of the given user with the full name set to the concatenation of the name and surname of the user.
func(uUser)WithDefaultFullName()User{
returnUser{
Username:u.Username,
Name:u.Name,
Surname:u.Surname,
Email:u.Email,
FullName:u.Username+" "+u.Surname,
}
}
"git.phc.dm.unipi.it/phc/website/model"
)
// Session represents a session returned from AuthenticatorService
typeSessionstruct{
Usernamestring`json:"username"`
Tokenstring`json:"token"`
}
// ErrInvalidSession is thrown when an AuthenticatorService is given a missing
// AuthenticatorService can login users using a separate http service or a temporary in memory store. When a user logs in the auth service returns a session token that can be used to read and modify user properties without having to re-send the user password. (TODO: Not yet implemented, this token has to be renewed every so often otherwise it lasts just a couple of days)
typeAuthenticatorServiceinterface{
// Service is an authentication service abstraction. When a user is logged in a
// new session token is returned, this can be used to read and modify user
// properties without having to re-send the user password. (TODO: implement
// token renewal)
typeServiceinterface{
// GetUser retrieves the user info given the username
GetUser(usernamestring)(*User,error)
GetUser(usernamestring)(*model.User,error)
// GetUsers retrieves the full user list from the authentication service
GetUsers()([]*User,error)
GetUsers()([]*model.User,error)
// GetSession retrieves the user session associated to a session token
GetSession(tokenstring)(*Session,error)
GetSession(tokenstring)(*model.Session,error)
// Login tries to log in a user given username and password and if successful returns a new user session
// UserForSession returns the user (object) linked to a session token, this is just a shortcut for calling [AuthenticatorService.GetSession] and then [AuthenticatorService.GetUser]
// UserForSession returns the user linked to the given session token, this is just a shortcut for calling [AuthenticatorService.GetSession] and then [AuthenticatorService.GetUser]
// New create an AuthenticatorService given an "host" string, if ":memory:" then this just returns an example AuthenticatorService using the [auth.Memory] implementation, otherwise for now this defaults to [auth.LDAPAuthService]
funcNew(hoststring)AuthenticatorService{
// NewDefaultService create an AuthenticatorService given an "host" string,
// If host is ":memory:" then this uses the [auth.Memory] implementation,
// otherwise for now this defaults to [auth.LDAPAuthService]
// User represents a user returned from AuthenticatorService
typeUserstruct{
Usernamestring`json:"username"`
Namestring`json:"name"`
Surnamestring`json:"surname"`
// FullName is a separate field from Name and Surname because for example
// ldap stores them all as separate fields.
FullNamestring`json:"fullName"`
Emailstring`json:"email"`
}
// WithDefaultFullName is a utility that returns a copy of the given user with the full name set to the concatenation of the name and surname of the user.
func(uUser)WithDefaultFullName()User{
returnUser{
Username:u.Username,
Name:u.Name,
Surname:u.Surname,
Email:u.Email,
FullName:u.Username+" "+u.Surname,
}
}
// Session represents a session returned from AuthenticatorService