1
0
mirror of https://github.com/mattermost/focalboard.git synced 2025-07-12 23:50:27 +02:00

First pass linter cleanup (#603)

* first pass linter cleanup

* address review comments
This commit is contained in:
Doug Lauder
2021-06-21 05:21:42 -04:00
committed by GitHub
parent c4154cd2dd
commit 66975bdfe9
49 changed files with 329 additions and 322 deletions

View File

@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"net"
"net/http"
@ -18,6 +19,10 @@ import (
"github.com/mattermost/focalboard/server/services/mlog"
)
const (
MinimumPasswordLength = 8
)
// LoginRequest is a login request
// swagger:model
type LoginRequest struct {
@ -102,13 +107,13 @@ type ChangePasswordRequest struct {
NewPassword string `json:"newPassword"`
}
// IsValid validates a password change request
// IsValid validates a password change request.
func (rd *ChangePasswordRequest) IsValid() error {
if rd.OldPassword == "" {
return errors.New("Old password is required")
return errors.New("old password is required")
}
if rd.NewPassword == "" {
return errors.New("New password is required")
return errors.New("new password is required")
}
if err := isValidPassword(rd.NewPassword); err != nil {
return err
@ -118,8 +123,8 @@ func (rd *ChangePasswordRequest) IsValid() error {
}
func isValidPassword(password string) error {
if len(password) < 8 {
return errors.New("Password must be at least 8 characters")
if len(password) < MinimumPasswordLength {
return fmt.Errorf("password must be at least %d characters", MinimumPasswordLength)
}
return nil
}
@ -243,9 +248,9 @@ func (a *API) handleRegister(w http.ResponseWriter, r *http.Request) {
// Validate token
if len(registerData.Token) > 0 {
workspace, err := a.app.GetRootWorkspace()
if err != nil {
a.errorResponse(w, http.StatusInternalServerError, "", err)
workspace, err2 := a.app.GetRootWorkspace()
if err2 != nil {
a.errorResponse(w, http.StatusInternalServerError, "", err2)
return
}
@ -255,9 +260,9 @@ func (a *API) handleRegister(w http.ResponseWriter, r *http.Request) {
}
} else {
// No signup token, check if no active users
userCount, err := a.app.GetRegisteredUserCount()
if err != nil {
a.errorResponse(w, http.StatusInternalServerError, "", err)
userCount, err2 := a.app.GetRegisteredUserCount()
if err2 != nil {
a.errorResponse(w, http.StatusInternalServerError, "", err2)
return
}
if userCount > 0 {
@ -335,7 +340,7 @@ func (a *API) handleChangePassword(w http.ResponseWriter, r *http.Request) {
}
var requestData ChangePasswordRequest
if err := json.Unmarshal(requestBody, &requestData); err != nil {
if err = json.Unmarshal(requestBody, &requestData); err != nil {
a.errorResponse(w, http.StatusInternalServerError, "", err)
return
}
@ -374,9 +379,9 @@ func (a *API) attachSession(handler func(w http.ResponseWriter, r *http.Request)
now := time.Now().Unix()
session := &model.Session{
ID: "single-user",
ID: SingleUser,
Token: token,
UserID: "single-user",
UserID: SingleUser,
AuthService: a.authService,
Props: map[string]interface{}{},
CreateAt: now,
@ -441,6 +446,5 @@ func (a *API) adminRequired(handler func(w http.ResponseWriter, r *http.Request)
}
handler(w, r)
return
}
}