chore: valide mail for registration
This commit is contained in:
parent
0b192b8f7e
commit
81183d2307
3 changed files with 20 additions and 3 deletions
|
|
@ -6,5 +6,6 @@ var (
|
|||
ErrUserHasInvalideChars = errors.New("username has invalide chars")
|
||||
ErrUsernameIsTaken = errors.New("username already takebn")
|
||||
ErrPasswordNotComplexEnough = errors.New("password not complex enough")
|
||||
ErrMailAddressInvalide = errors.New("email address invalide")
|
||||
ErrCantCreateUser = errors.New("cant create user")
|
||||
)
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package miniauth
|
||||
|
||||
import (
|
||||
"net/mail"
|
||||
"regexp"
|
||||
|
||||
"git.keks.cloud/kekskurse/miniauth/pkg/userstore"
|
||||
|
|
@ -20,8 +21,8 @@ func NewMiniauth(us userstore.Store) Miniauth {
|
|||
return m
|
||||
}
|
||||
|
||||
func (m Miniauth) RegisterUser(username string, mail string, password string) error {
|
||||
log := m.log.With().Str("func", "RegisterUser").Str("username", username).Str("mail", mail).Logger()
|
||||
func (m Miniauth) RegisterUser(username string, email string, password string) error {
|
||||
log := m.log.With().Str("func", "RegisterUser").Str("username", username).Str("mail", email).Logger()
|
||||
err := m.checkUsernameForRegistration(username)
|
||||
if err != nil {
|
||||
return utils.WrapError(ErrUserHasInvalideChars, err, log)
|
||||
|
|
@ -32,6 +33,11 @@ func (m Miniauth) RegisterUser(username string, mail string, password string) er
|
|||
return utils.WrapError(ErrPasswordNotComplexEnough, err, log)
|
||||
}
|
||||
|
||||
_, err = mail.ParseAddress(email)
|
||||
if err != nil {
|
||||
return utils.WrapError(ErrMailAddressInvalide, err, log)
|
||||
}
|
||||
|
||||
id, err := m.store.UserWrite(username, password)
|
||||
if err != nil {
|
||||
return utils.WrapError(ErrCantCreateUser, err, log)
|
||||
|
|
@ -39,11 +45,13 @@ func (m Miniauth) RegisterUser(username string, mail string, password string) er
|
|||
|
||||
log = log.With().Int64("userid", id).Logger()
|
||||
|
||||
err = m.store.MailAdd(mail, id, true)
|
||||
err = m.store.MailAdd(email, id, true)
|
||||
if err != nil {
|
||||
return utils.WrapError(ErrCantCreateUser, err, log)
|
||||
}
|
||||
|
||||
// TODO Send mail
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -32,6 +32,14 @@ func TestRegistration(t *testing.T) {
|
|||
exptErr: ErrPasswordNotComplexEnough,
|
||||
exptErrString: "password not complex enough: Password length must be not lower that 15 chars",
|
||||
},
|
||||
{
|
||||
name: "invaloid password",
|
||||
username: "kekskurse",
|
||||
password: "abc123d,.,jfhfh",
|
||||
mail: "mailabd.de",
|
||||
exptErr: ErrMailAddressInvalide,
|
||||
exptErrString: "email address invalide: mail: missing '@' or angle-addr",
|
||||
},
|
||||
}
|
||||
|
||||
ma := getMiniAuth(t)
|
||||
|
|
|
|||
Reference in a new issue