2019-01-24 16:26:36 +00:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
2018-11-29 16:23:44 +00:00
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
2019-01-15 13:03:24 +00:00
|
|
|
package console
|
2018-11-29 16:23:44 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/zeebo/errs"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2019-03-29 17:42:20 +00:00
|
|
|
passMinLength = 6
|
2018-11-29 16:23:44 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// ErrValidation validation related error class
|
|
|
|
var ErrValidation = errs.Class("validation error")
|
|
|
|
|
|
|
|
// validationError is slice of ErrValidation class errors
|
|
|
|
type validationErrors []error
|
|
|
|
|
|
|
|
// Add new ErrValidation err
|
|
|
|
func (validation *validationErrors) Add(format string, args ...interface{}) {
|
2018-11-30 13:04:59 +00:00
|
|
|
*validation = append(*validation, ErrValidation.New(format, args...))
|
2018-11-29 16:23:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// AddWrap adds new ErrValidation wrapped err
|
|
|
|
func (validation *validationErrors) AddWrap(err error) {
|
|
|
|
*validation = append(*validation, ErrValidation.Wrap(err))
|
|
|
|
}
|
|
|
|
|
|
|
|
// Combine returns combined validation errors
|
|
|
|
func (validation *validationErrors) Combine() error {
|
2019-03-29 12:30:23 +00:00
|
|
|
return errs.Combine(*validation...)
|
2018-11-29 16:23:44 +00:00
|
|
|
}
|
|
|
|
|
2019-11-25 21:36:36 +00:00
|
|
|
// ValidatePassword validates password
|
|
|
|
func ValidatePassword(pass string) error {
|
2018-12-10 15:57:06 +00:00
|
|
|
var errs validationErrors
|
|
|
|
|
|
|
|
if len(pass) < passMinLength {
|
2019-04-10 01:15:12 +01:00
|
|
|
errs.Add(passwordIncorrectErrMsg, passMinLength)
|
2018-12-10 15:57:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return errs.Combine()
|
|
|
|
}
|
2019-10-29 14:24:16 +00:00
|
|
|
|
2019-11-25 21:36:36 +00:00
|
|
|
// ValidateFullName validates full name.
|
|
|
|
func ValidateFullName(name string) error {
|
2019-10-29 14:24:16 +00:00
|
|
|
if name == "" {
|
|
|
|
return errs.New("full name can not be empty")
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|