Mainflux.mainflux/users/users.go

41 lines
866 B
Go
Raw Normal View History

//
// Copyright (c) 2018
// Mainflux
//
// SPDX-License-Identifier: Apache-2.0
//
2018-05-11 05:53:25 +08:00
package users
2018-05-11 07:00:10 +08:00
import "github.com/asaskevich/govalidator"
2018-05-11 05:53:25 +08:00
2018-05-11 07:00:10 +08:00
// User represents a Mainflux user account. Each user is identified given its
// email and password.
type User struct {
Email string
Password string
2018-05-11 05:53:25 +08:00
}
2018-05-11 07:00:10 +08:00
// Validate returns an error if user representation is invalid.
func (u User) Validate() error {
if u.Email == "" || u.Password == "" {
2018-05-11 05:53:25 +08:00
return ErrMalformedEntity
}
2018-05-11 07:00:10 +08:00
if !govalidator.IsEmail(u.Email) {
return ErrMalformedEntity
2018-05-11 05:53:25 +08:00
}
2018-05-11 07:00:10 +08:00
return nil
2018-05-11 05:53:25 +08:00
}
2018-05-11 07:00:10 +08:00
// 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)
2018-05-11 05:53:25 +08:00
}