2017-09-23 01:03:27 +02:00
|
|
|
package manager
|
|
|
|
|
2017-10-01 01:07:37 +02:00
|
|
|
import "github.com/asaskevich/govalidator"
|
|
|
|
|
2017-09-23 01:03:27 +02:00
|
|
|
// User represents a Mainflux user account. Each user is identified given its
|
|
|
|
// email and password.
|
|
|
|
type User struct {
|
2018-03-11 18:06:01 +01:00
|
|
|
Email string `gorm:"type:varchar(254);primary_key"`
|
|
|
|
Password string `gorm:"type:char(60)"`
|
2017-09-23 01:03:27 +02:00
|
|
|
}
|
|
|
|
|
2017-10-06 23:03:24 +02:00
|
|
|
// Validate returns an error if user representation is invalid.
|
2017-10-01 01:07:37 +02:00
|
|
|
func (u *User) Validate() error {
|
2017-09-23 01:03:27 +02:00
|
|
|
if u.Email == "" || u.Password == "" {
|
2017-10-01 01:07:37 +02:00
|
|
|
return ErrMalformedEntity
|
|
|
|
}
|
|
|
|
|
|
|
|
if !govalidator.IsEmail(u.Email) {
|
|
|
|
return ErrMalformedEntity
|
2017-09-23 01:03:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
// One retrieves user by its unique identifier (i.e. email).
|
|
|
|
One(string) (User, error)
|
|
|
|
}
|