mirror of
https://github.com/mainflux/mainflux.git
synced 2025-04-29 13:49:28 +08:00

* MF-1261 - Use StatusUnauthorized for authn and StatusForbidden for authz Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * ErrExternalKey typo Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Rename ErrUnauthorizedAcces -> ErrAuthentication Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix bootstrap error Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix status code in openapi Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix test description Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix test description Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix test description Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Add errors cases Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix status codes Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Add gRPC stutus code Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix tests description Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix openapi and encodeError Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix grpc message Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix test descriptions Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Revert sdk error Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix typo Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
133 lines
2.3 KiB
Go
133 lines
2.3 KiB
Go
// Copyright (c) Mainflux
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package api
|
|
|
|
import (
|
|
"github.com/mainflux/mainflux/pkg/errors"
|
|
"github.com/mainflux/mainflux/users"
|
|
)
|
|
|
|
type userReq struct {
|
|
user users.User
|
|
}
|
|
|
|
func (req userReq) validate() error {
|
|
return req.user.Validate()
|
|
}
|
|
|
|
type createUserReq struct {
|
|
user users.User
|
|
token string
|
|
}
|
|
|
|
func (req createUserReq) validate() error {
|
|
return req.user.Validate()
|
|
}
|
|
|
|
type viewUserReq struct {
|
|
token string
|
|
userID string
|
|
}
|
|
|
|
func (req viewUserReq) validate() error {
|
|
if req.token == "" {
|
|
return errors.ErrAuthentication
|
|
}
|
|
return nil
|
|
}
|
|
|
|
type listUsersReq struct {
|
|
token string
|
|
offset uint64
|
|
limit uint64
|
|
email string
|
|
metadata users.Metadata
|
|
}
|
|
|
|
func (req listUsersReq) validate() error {
|
|
if req.token == "" {
|
|
return errors.ErrAuthentication
|
|
}
|
|
return nil
|
|
}
|
|
|
|
type updateUserReq struct {
|
|
token string
|
|
Metadata map[string]interface{} `json:"metadata,omitempty"`
|
|
}
|
|
|
|
func (req updateUserReq) validate() error {
|
|
if req.token == "" {
|
|
return errors.ErrAuthentication
|
|
}
|
|
return nil
|
|
}
|
|
|
|
type passwResetReq struct {
|
|
Email string `json:"email"`
|
|
Host string `json:"host"`
|
|
}
|
|
|
|
func (req passwResetReq) validate() error {
|
|
if req.Email == "" || req.Host == "" {
|
|
return errors.ErrMalformedEntity
|
|
}
|
|
return nil
|
|
}
|
|
|
|
type resetTokenReq struct {
|
|
Token string `json:"token"`
|
|
Password string `json:"password"`
|
|
ConfPass string `json:"confirm_password"`
|
|
}
|
|
|
|
func (req resetTokenReq) validate() error {
|
|
if req.Password == "" || req.ConfPass == "" {
|
|
return errors.ErrMalformedEntity
|
|
}
|
|
if req.Token == "" {
|
|
return users.ErrMissingResetToken
|
|
}
|
|
if req.Password != req.ConfPass {
|
|
return errors.ErrMalformedEntity
|
|
}
|
|
return nil
|
|
}
|
|
|
|
type passwChangeReq struct {
|
|
Token string `json:"token"`
|
|
Password string `json:"password"`
|
|
OldPassword string `json:"old_password"`
|
|
}
|
|
|
|
func (req passwChangeReq) validate() error {
|
|
if req.Token == "" {
|
|
return errors.ErrAuthentication
|
|
}
|
|
if req.OldPassword == "" {
|
|
return errors.ErrMalformedEntity
|
|
}
|
|
return nil
|
|
}
|
|
|
|
type listMemberGroupReq struct {
|
|
token string
|
|
offset uint64
|
|
limit uint64
|
|
metadata users.Metadata
|
|
groupID string
|
|
}
|
|
|
|
func (req listMemberGroupReq) validate() error {
|
|
if req.token == "" {
|
|
return errors.ErrAuthentication
|
|
}
|
|
|
|
if req.groupID == "" {
|
|
return errors.ErrMalformedEntity
|
|
}
|
|
|
|
return nil
|
|
}
|