Mercurial > gemma
diff pkg/models/user.go @ 1879:9a2fbeaabd52 dev-pdf-generation
merging in from branch default
author | Bernhard Reiter <bernhard@intevation.de> |
---|---|
date | Tue, 15 Jan 2019 10:07:10 +0100 |
parents | f1c3fe8b79f5 |
children | 71b722809b2b |
line wrap: on
line diff
--- a/pkg/models/user.go Tue Jan 15 09:54:46 2019 +0100 +++ b/pkg/models/user.go Tue Jan 15 10:07:10 2019 +0100 @@ -23,11 +23,17 @@ ) type ( - Email string - Country string - Role string + // Email is a string formed by a valid EMail address. + Email string + // Country is a valid country 2 letter code. + Country string + // Role is a string with a valid gemma role. + Role string + // UserName is a string forming a valid user name. UserName string + // BoundingBox is a spatial bounding box of user's + // responsibility area. BoundingBox struct { X1 float64 `json:"x1"` Y1 float64 `json:"y1"` @@ -35,6 +41,7 @@ Y2 float64 `json:"y2"` } + // User is a serialized JSON form of user data. User struct { User UserName `json:"user"` Role Role `json:"role"` @@ -44,6 +51,7 @@ Extent *BoundingBox `json:"extent"` } + // PWResetUser is send to request a password reset for a user. PWResetUser struct { User string `json:"user"` } @@ -65,6 +73,7 @@ errNoEmailAddress = errors.New("Not a valid email address") ) +// UnmarshalJSON ensures that the given string forms a valid email address. func (e *Email) UnmarshalJSON(data []byte) error { var s string if err := json.Unmarshal(data, &s); err != nil { @@ -77,10 +86,12 @@ return nil } +// Value implements the driver.Valuer interface. func (e Email) Value() (driver.Value, error) { return string(e), nil } +// Scan implements the sql.Scanner interface. func (e *Email) Scan(src interface{}) (err error) { if s, ok := src.(string); ok { *e = Email(s) @@ -92,10 +103,12 @@ var errNoValidUser = errors.New("Not a valid user") +// IsValid checks if a given user name is valid. func (u UserName) IsValid() bool { return u != "" } +// UnmarshalJSON ensures that the given string forms a valid user name. func (u *UserName) UnmarshalJSON(data []byte) error { var s string if err := json.Unmarshal(data, &s); err != nil { @@ -108,6 +121,7 @@ return errNoValidUser } +// Scan implements the sql.Scanner interface. func (u *UserName) Scan(src interface{}) (err error) { if s, ok := src.(string); ok { *u = UserName(s) @@ -125,6 +139,8 @@ errNoValidCountry = errors.New("Not a valid country") ) +// UnmarshalJSON ensures that the given string forms a valid +// two letter country code. func (c *Country) UnmarshalJSON(data []byte) error { var s string if err := json.Unmarshal(data, &s); err != nil { @@ -140,10 +156,12 @@ return errNoValidCountry } +// Value implements the driver.Valuer interface. func (c Country) Value() (driver.Value, error) { return string(c), nil } +// Scan implements the sql.Scanner interfaces. func (c *Country) Scan(src interface{}) (err error) { if s, ok := src.(string); ok { *c = Country(s) @@ -162,10 +180,12 @@ errNoValidRole = errors.New("Not a valid role") ) +// Value implements the driver.Valuer interface. func (r Role) Value() (driver.Value, error) { return string(r), nil } +// Scan implements the sql.Scanner interface. func (r *Role) Scan(src interface{}) (err error) { if s, ok := src.(string); ok { *r = Role(s) @@ -175,6 +195,7 @@ return } +// UnmarshalJSON ensure that the given string is a valid user name. func (r *Role) UnmarshalJSON(data []byte) error { var s string if err := json.Unmarshal(data, &s); err != nil {