chore: valide mail for registration
All checks were successful
ci/woodpecker/push/test Pipeline was successful
ci/woodpecker/push/playwright Pipeline was successful
ci/woodpecker/push/deplyoment Pipeline was successful

This commit is contained in:
kekskurse 2025-03-13 22:03:10 +01:00
parent 0b192b8f7e
commit 81183d2307
3 changed files with 20 additions and 3 deletions

View file

@ -6,5 +6,6 @@ var (
ErrUserHasInvalideChars = errors.New("username has invalide chars") ErrUserHasInvalideChars = errors.New("username has invalide chars")
ErrUsernameIsTaken = errors.New("username already takebn") ErrUsernameIsTaken = errors.New("username already takebn")
ErrPasswordNotComplexEnough = errors.New("password not complex enough") ErrPasswordNotComplexEnough = errors.New("password not complex enough")
ErrMailAddressInvalide = errors.New("email address invalide")
ErrCantCreateUser = errors.New("cant create user") ErrCantCreateUser = errors.New("cant create user")
) )

View file

@ -1,6 +1,7 @@
package miniauth package miniauth
import ( import (
"net/mail"
"regexp" "regexp"
"git.keks.cloud/kekskurse/miniauth/pkg/userstore" "git.keks.cloud/kekskurse/miniauth/pkg/userstore"
@ -20,8 +21,8 @@ func NewMiniauth(us userstore.Store) Miniauth {
return m return m
} }
func (m Miniauth) RegisterUser(username string, mail string, password string) error { func (m Miniauth) RegisterUser(username string, email string, password string) error {
log := m.log.With().Str("func", "RegisterUser").Str("username", username).Str("mail", mail).Logger() log := m.log.With().Str("func", "RegisterUser").Str("username", username).Str("mail", email).Logger()
err := m.checkUsernameForRegistration(username) err := m.checkUsernameForRegistration(username)
if err != nil { if err != nil {
return utils.WrapError(ErrUserHasInvalideChars, err, log) 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) 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) id, err := m.store.UserWrite(username, password)
if err != nil { if err != nil {
return utils.WrapError(ErrCantCreateUser, err, log) 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() log = log.With().Int64("userid", id).Logger()
err = m.store.MailAdd(mail, id, true) err = m.store.MailAdd(email, id, true)
if err != nil { if err != nil {
return utils.WrapError(ErrCantCreateUser, err, log) return utils.WrapError(ErrCantCreateUser, err, log)
} }
// TODO Send mail
return nil return nil
} }

View file

@ -32,6 +32,14 @@ func TestRegistration(t *testing.T) {
exptErr: ErrPasswordNotComplexEnough, exptErr: ErrPasswordNotComplexEnough,
exptErrString: "password not complex enough: Password length must be not lower that 15 chars", 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) ma := getMiniAuth(t)