41 lines
866 B
Go
41 lines
866 B
Go
//
|
|
// Copyright (c) 2018
|
|
// Mainflux
|
|
//
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
//
|
|
|
|
package users
|
|
|
|
import "github.com/asaskevich/govalidator"
|
|
|
|
// User represents a Mainflux user account. Each user is identified given its
|
|
// email and password.
|
|
type User struct {
|
|
Email string
|
|
Password string
|
|
}
|
|
|
|
// Validate returns an error if user representation is invalid.
|
|
func (u User) Validate() error {
|
|
if u.Email == "" || u.Password == "" {
|
|
return ErrMalformedEntity
|
|
}
|
|
|
|
if !govalidator.IsEmail(u.Email) {
|
|
return ErrMalformedEntity
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// UserRepository specifies an account persistence API.
|
|
type UserRepository interface {
|
|
// Save persists the user account. A non-nil error is returned to indicate
|
|
// operation failure.
|
|
Save(User) error
|
|
|
|
// RetrieveByID retrieves user by its unique identifier (i.e. email).
|
|
RetrieveByID(string) (User, error)
|
|
}
|