mirror of
https://github.com/volatiletech/authboss.git
synced 2025-01-24 05:17:10 +02:00
Fix go vet errors
This commit is contained in:
parent
38660ece44
commit
e76838cc1e
@ -159,7 +159,7 @@ func (c *Confirm) confirmEmail(to, token string) {
|
|||||||
func (c *Confirm) confirmHandler(ctx *authboss.Context, w http.ResponseWriter, r *http.Request) error {
|
func (c *Confirm) confirmHandler(ctx *authboss.Context, w http.ResponseWriter, r *http.Request) error {
|
||||||
token := r.FormValue(FormValueConfirm)
|
token := r.FormValue(FormValueConfirm)
|
||||||
if len(token) == 0 {
|
if len(token) == 0 {
|
||||||
return authboss.ClientDataErr{FormValueConfirm}
|
return authboss.ClientDataErr{Name: FormValueConfirm}
|
||||||
}
|
}
|
||||||
|
|
||||||
toHash, err := base64.URLEncoding.DecodeString(token)
|
toHash, err := base64.URLEncoding.DecodeString(token)
|
||||||
|
@ -151,7 +151,7 @@ func TestConfirm_ConfirmHandlerErrors(t *testing.T) {
|
|||||||
Confirmed bool
|
Confirmed bool
|
||||||
Error error
|
Error error
|
||||||
}{
|
}{
|
||||||
{"http://localhost", false, authboss.ClientDataErr{FormValueConfirm}},
|
{"http://localhost", false, authboss.ClientDataErr{Name: FormValueConfirm}},
|
||||||
{"http://localhost?cnf=c$ats", false,
|
{"http://localhost?cnf=c$ats", false,
|
||||||
authboss.ErrAndRedirect{Location: "/", Err: errors.New("confirm: token failed to decode \"c$ats\" => illegal base64 data at input byte 1\n")},
|
authboss.ErrAndRedirect{Location: "/", Err: errors.New("confirm: token failed to decode \"c$ats\" => illegal base64 data at input byte 1\n")},
|
||||||
},
|
},
|
||||||
|
@ -263,12 +263,12 @@ func (m *MockClientStorer) Get(key string) (string, bool) {
|
|||||||
// GetErr gets a key's value or err if not exist
|
// GetErr gets a key's value or err if not exist
|
||||||
func (m *MockClientStorer) GetErr(key string) (string, error) {
|
func (m *MockClientStorer) GetErr(key string) (string, error) {
|
||||||
if m.GetShouldFail {
|
if m.GetShouldFail {
|
||||||
return "", authboss.ClientDataErr{key}
|
return "", authboss.ClientDataErr{Name: key}
|
||||||
}
|
}
|
||||||
|
|
||||||
v, ok := m.Values[key]
|
v, ok := m.Values[key]
|
||||||
if !ok {
|
if !ok {
|
||||||
return v, authboss.ClientDataErr{key}
|
return v, authboss.ClientDataErr{Name: key}
|
||||||
}
|
}
|
||||||
return v, nil
|
return v, nil
|
||||||
}
|
}
|
||||||
|
@ -74,7 +74,7 @@ func LoadTemplates(ab *authboss.Authboss, layout *template.Template, fpath strin
|
|||||||
func (t Templates) Render(ctx *authboss.Context, w http.ResponseWriter, r *http.Request, name string, data authboss.HTMLData) error {
|
func (t Templates) Render(ctx *authboss.Context, w http.ResponseWriter, r *http.Request, name string, data authboss.HTMLData) error {
|
||||||
tpl, ok := t[name]
|
tpl, ok := t[name]
|
||||||
if !ok {
|
if !ok {
|
||||||
return authboss.RenderErr{tpl.Name(), data, ErrTemplateNotFound}
|
return authboss.RenderErr{TemplateName: tpl.Name(), Data: data, Err: ErrTemplateNotFound}
|
||||||
}
|
}
|
||||||
|
|
||||||
data.MergeKV(
|
data.MergeKV(
|
||||||
@ -98,12 +98,12 @@ func (t Templates) Render(ctx *authboss.Context, w http.ResponseWriter, r *http.
|
|||||||
buffer := &bytes.Buffer{}
|
buffer := &bytes.Buffer{}
|
||||||
err := tpl.ExecuteTemplate(buffer, tpl.Name(), data)
|
err := tpl.ExecuteTemplate(buffer, tpl.Name(), data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return authboss.RenderErr{tpl.Name(), data, err}
|
return authboss.RenderErr{TemplateName: tpl.Name(), Data: data, Err: ErrTemplateNotFound}
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = io.Copy(w, buffer)
|
_, err = io.Copy(w, buffer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return authboss.RenderErr{tpl.Name(), data, err}
|
return authboss.RenderErr{TemplateName: tpl.Name(), Data: data, Err: ErrTemplateNotFound}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@ -113,23 +113,23 @@ func (t Templates) Render(ctx *authboss.Context, w http.ResponseWriter, r *http.
|
|||||||
func Email(mailer authboss.Mailer, email authboss.Email, htmlTpls Templates, nameHTML string, textTpls Templates, namePlain string, data interface{}) error {
|
func Email(mailer authboss.Mailer, email authboss.Email, htmlTpls Templates, nameHTML string, textTpls Templates, namePlain string, data interface{}) error {
|
||||||
tplHTML, ok := htmlTpls[nameHTML]
|
tplHTML, ok := htmlTpls[nameHTML]
|
||||||
if !ok {
|
if !ok {
|
||||||
return authboss.RenderErr{tplHTML.Name(), data, ErrTemplateNotFound}
|
return authboss.RenderErr{TemplateName: tplHTML.Name(), Data: data, Err: ErrTemplateNotFound}
|
||||||
}
|
}
|
||||||
|
|
||||||
tplPlain, ok := textTpls[namePlain]
|
tplPlain, ok := textTpls[namePlain]
|
||||||
if !ok {
|
if !ok {
|
||||||
return authboss.RenderErr{tplPlain.Name(), data, ErrTemplateNotFound}
|
return authboss.RenderErr{TemplateName: tplPlain.Name(), Data: data, Err: ErrTemplateNotFound}
|
||||||
}
|
}
|
||||||
|
|
||||||
htmlBuffer := &bytes.Buffer{}
|
htmlBuffer := &bytes.Buffer{}
|
||||||
if err := tplHTML.ExecuteTemplate(htmlBuffer, tplHTML.Name(), data); err != nil {
|
if err := tplHTML.ExecuteTemplate(htmlBuffer, tplHTML.Name(), data); err != nil {
|
||||||
return authboss.RenderErr{tplHTML.Name(), data, err}
|
return authboss.RenderErr{TemplateName: tplHTML.Name(), Data: data, Err: err}
|
||||||
}
|
}
|
||||||
email.HTMLBody = htmlBuffer.String()
|
email.HTMLBody = htmlBuffer.String()
|
||||||
|
|
||||||
plainBuffer := &bytes.Buffer{}
|
plainBuffer := &bytes.Buffer{}
|
||||||
if err := tplPlain.ExecuteTemplate(plainBuffer, tplPlain.Name(), data); err != nil {
|
if err := tplPlain.ExecuteTemplate(plainBuffer, tplPlain.Name(), data); err != nil {
|
||||||
return authboss.RenderErr{tplPlain.Name(), data, err}
|
return authboss.RenderErr{TemplateName: tplPlain.Name(), Data: data, Err: err}
|
||||||
}
|
}
|
||||||
email.TextBody = plainBuffer.String()
|
email.TextBody = plainBuffer.String()
|
||||||
|
|
||||||
|
@ -151,7 +151,7 @@ func (rec *Recover) startHandlerFunc(ctx *authboss.Context, w http.ResponseWrite
|
|||||||
|
|
||||||
// redirect to login when user not found to prevent username sniffing
|
// redirect to login when user not found to prevent username sniffing
|
||||||
if err := ctx.LoadUser(primaryID); err == authboss.ErrUserNotFound {
|
if err := ctx.LoadUser(primaryID); err == authboss.ErrUserNotFound {
|
||||||
return authboss.ErrAndRedirect{err, rec.RecoverOKPath, recoverInitiateSuccessFlash, ""}
|
return authboss.ErrAndRedirect{Err: err, Location: rec.RecoverOKPath, FlashSuccess: recoverInitiateSuccessFlash}
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -219,9 +219,9 @@ func (r *Recover) completeHandlerFunc(ctx *authboss.Context, w http.ResponseWrit
|
|||||||
case methodGET:
|
case methodGET:
|
||||||
_, err = verifyToken(ctx, req)
|
_, err = verifyToken(ctx, req)
|
||||||
if err == errRecoveryTokenExpired {
|
if err == errRecoveryTokenExpired {
|
||||||
return authboss.ErrAndRedirect{err, "/recover", "", recoverTokenExpiredFlash}
|
return authboss.ErrAndRedirect{Err: err, Location: "/recover", FlashError: recoverTokenExpiredFlash}
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
return authboss.ErrAndRedirect{err, "/", "", ""}
|
return authboss.ErrAndRedirect{Err: err, Location: "/"}
|
||||||
}
|
}
|
||||||
|
|
||||||
token := req.FormValue(formValueToken)
|
token := req.FormValue(formValueToken)
|
||||||
@ -230,7 +230,7 @@ func (r *Recover) completeHandlerFunc(ctx *authboss.Context, w http.ResponseWrit
|
|||||||
case methodPOST:
|
case methodPOST:
|
||||||
token := req.FormValue(formValueToken)
|
token := req.FormValue(formValueToken)
|
||||||
if len(token) == 0 {
|
if len(token) == 0 {
|
||||||
return authboss.ClientDataErr{formValueToken}
|
return authboss.ClientDataErr{Name: formValueToken}
|
||||||
}
|
}
|
||||||
|
|
||||||
password := req.FormValue(authboss.StorePassword)
|
password := req.FormValue(authboss.StorePassword)
|
||||||
@ -285,7 +285,7 @@ func (r *Recover) completeHandlerFunc(ctx *authboss.Context, w http.ResponseWrit
|
|||||||
func verifyToken(ctx *authboss.Context, r *http.Request) (attrs authboss.Attributes, err error) {
|
func verifyToken(ctx *authboss.Context, r *http.Request) (attrs authboss.Attributes, err error) {
|
||||||
token := r.FormValue(formValueToken)
|
token := r.FormValue(formValueToken)
|
||||||
if len(token) == 0 {
|
if len(token) == 0 {
|
||||||
return nil, authboss.ClientDataErr{token}
|
return nil, authboss.ClientDataErr{Name: token}
|
||||||
}
|
}
|
||||||
|
|
||||||
decoded, err := base64.URLEncoding.DecodeString(token)
|
decoded, err := base64.URLEncoding.DecodeString(token)
|
||||||
|
@ -93,7 +93,7 @@ func (reg *Register) registerPostHandler(ctx *authboss.Context, w http.ResponseW
|
|||||||
if user, err := ctx.Storer.Get(key); err != nil && err != authboss.ErrUserNotFound {
|
if user, err := ctx.Storer.Get(key); err != nil && err != authboss.ErrUserNotFound {
|
||||||
return err
|
return err
|
||||||
} else if user != nil {
|
} else if user != nil {
|
||||||
validationErrs = append(validationErrs, authboss.FieldError{reg.PrimaryID, errors.New("Already in use")})
|
validationErrs = append(validationErrs, authboss.FieldError{Name: reg.PrimaryID, Err: errors.New("Already in use")})
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(validationErrs) != 0 {
|
if len(validationErrs) != 0 {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user