Documentation ¶
Index ¶
- Variables
- func IsEmailAlreadyTakenError(err error) bool
- func IsLoginNameAlreadyTakenError(err error) bool
- func IsNotFoundError(err error) bool
- func IsServiceError(err error) bool
- func IsUserEmailMustBeVerifiedError(err error) bool
- type Config
- type Dependencies
- type EventCollector
- type EventStream
- type IdFactory
- type Item
- type PasswordHasher
- type UserService
- func (us *UserService) Authenticate(loginName, loginPassword string) (string, error)
- func (us *UserService) ChangeEmail(userID, email string) error
- func (us *UserService) ChangeLoginCredentials(userID, newLogin, newPassword string) error
- func (us *UserService) ChangeProfileName(userID, profileName string) error
- func (us *UserService) CheckAndSetEmailVerified(userID, email string) error
- func (us *UserService) CreateUser(profileName, email, loginName, loginPassword string) (string, error)
- func (us *UserService) GetUser(id string) (user.User, error)
- func (us *UserService) NewResetLoginCredentialsToken(email string) (string, error)
- func (us *UserService) ResetCredentialsWithToken(resetPasswordToken, new_login_name, new_login_password string) (string, error)
- func (us *UserService) SetEmailVerified(userID string) error
- type UserStorage
- type UserStorageWrapper
- func (w *UserStorageWrapper) FindByEmail(email string) (user.User, error)
- func (w *UserStorageWrapper) FindByLoginName(loginName string) (user.User, error)
- func (w *UserStorageWrapper) FindByResetPasswordToken(token string) (user.User, error)
- func (w *UserStorageWrapper) Get(userId string) (user.User, error)
- func (w *UserStorageWrapper) Save(user user.User) error
Constants ¶
This section is empty.
Variables ¶
var ( InvalidConfig = errgo.New("Invalid config") InvalidArguments = errgo.New("Invalid arguments.") InvalidCredentials = errgo.New("Invalid credentials.") InvalidVerificationEmail = errgo.New("Email adress does not match current email for user.") ResetPasswordTokenExpired = errgo.New("The ResetPasswordToken has expired.") UserEmailMustBeVerified = errgo.New("Email must be verified to authenticate.") )
Functions ¶
func IsNotFoundError ¶
func IsServiceError ¶
Types ¶
type Config ¶
type Config struct { AuthEmailMustBeVerified bool MaxItems int // How long can a ResetPasswordToken be used? ResetPasswordExpireTime time.Duration }
func (Config) Validate ¶
func (c Config) Validate()
Validate checks all values and panics if any one is invalid.
func (Config) ValidateValues ¶
type Dependencies ¶
type Dependencies struct { IdFactory IdFactory Hasher PasswordHasher UserStorage UserStorage // EventStream.Publish() is called for every succesfull event in the UserService. Should also forward to EventCollector. EventStream EventStream }
type EventCollector ¶
func NewEventCollector ¶
func NewEventCollector(maxItems int) *EventCollector
func (*EventCollector) Get ¶
func (esc *EventCollector) Get() []Item
func (*EventCollector) WriteJSONStreamOnce ¶
func (esc *EventCollector) WriteJSONStreamOnce(w io.Writer) error
WriteJSONOnce writes the current collected items into the writer. Each item is written on its own line.
type EventStream ¶
type EventStream interface { // Log forwards the given entry to the eventlog. Publish(tag string, entry []byte) }
EventLog abstracts any eventlog for store the business events of the UserService. Could write to RabbitMQ, Apache Kafka or just plain files. This is a write-only interface, errors are propagted to stderr or similar..
type Item ¶
type Item struct { Tag string Json []byte Timestamp time.Time // contains filtered or unexported fields }
func (*Item) MarshalJSON ¶
type PasswordHasher ¶
type PasswordHasher interface { NeedsRehash(password_hash string) bool Hash(password string) string Verify(password, passwordHash string) bool }
This follows the design of the PHP password_* functions. The client don't need to know anything about the user algorithms.
type UserService ¶
type UserService struct { Dependencies Config // EventCollector is used by any consumer of the UserService which needs access to the previous events. EventCollector *EventCollector }
func NewUserService ¶
func NewUserService(config Config, deps Dependencies) *UserService
func (*UserService) Authenticate ¶
func (us *UserService) Authenticate(loginName, loginPassword string) (string, error)
Authenticate checks whether a user with the given login credentials exists. Returns an error if the credentials are incorrect or the user cannot be authorized.
Error Helpers
func (*UserService) ChangeEmail ¶
func (us *UserService) ChangeEmail(userID, email string) error
func (*UserService) ChangeLoginCredentials ¶
func (us *UserService) ChangeLoginCredentials(userID, newLogin, newPassword string) error
func (*UserService) ChangeProfileName ¶
func (us *UserService) ChangeProfileName(userID, profileName string) error
func (*UserService) CheckAndSetEmailVerified ¶
func (us *UserService) CheckAndSetEmailVerified(userID, email string) error
func (*UserService) CreateUser ¶
func (us *UserService) CreateUser(profileName, email, loginName, loginPassword string) (string, error)
func (*UserService) NewResetLoginCredentialsToken ¶
func (us *UserService) NewResetLoginCredentialsToken(email string) (string, error)
NewResetLoginCredentialsToken creates a new reset password token, associates it with the user and returns it. The consumer should forward this token to the user's email (or via another communication medium which is known to reach the real user) to verify that the initiator is the real user.
Event: user.new_reset_password_token(user_id, email, token)
Returs the new token to reset the password with or an error if no user could be found.
func (*UserService) ResetCredentialsWithToken ¶
func (us *UserService) ResetCredentialsWithToken(resetPasswordToken, new_login_name, new_login_password string) (string, error)
ResetCredentialsWithToken checks for users with the given token and resets their login credentials to given values.
Event: user.
func (*UserService) SetEmailVerified ¶
func (us *UserService) SetEmailVerified(userID string) error
type UserStorage ¶
type UserStorageWrapper ¶
type UserStorageWrapper struct {
UserStorage UserStorage
}
func (*UserStorageWrapper) FindByEmail ¶
func (w *UserStorageWrapper) FindByEmail(email string) (user.User, error)
func (*UserStorageWrapper) FindByLoginName ¶
func (w *UserStorageWrapper) FindByLoginName(loginName string) (user.User, error)
func (*UserStorageWrapper) FindByResetPasswordToken ¶
func (w *UserStorageWrapper) FindByResetPasswordToken(token string) (user.User, error)