Fix lint issues
continuous-integration/drone/pr Build is failing Details

This commit is contained in:
kolaente 2020-11-21 13:54:35 +01:00
parent d7f2ee1682
commit 966e4d6ed6
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
14 changed files with 49 additions and 41 deletions

View File

@ -18,7 +18,6 @@
package cmd
import (
"code.vikunja.io/api/pkg/models"
"fmt"
"os"
"strconv"
@ -27,6 +26,7 @@ import (
"code.vikunja.io/api/pkg/initialize"
"code.vikunja.io/api/pkg/log"
"code.vikunja.io/api/pkg/models"
"code.vikunja.io/api/pkg/user"
"github.com/olekukonko/tablewriter"
"github.com/spf13/cobra"

View File

@ -17,7 +17,6 @@
package integrations
import (
"code.vikunja.io/api/pkg/modules/auth"
"net/http"
"net/http/httptest"
"net/url"
@ -29,6 +28,7 @@ import (
"code.vikunja.io/api/pkg/db"
"code.vikunja.io/api/pkg/files"
"code.vikunja.io/api/pkg/models"
"code.vikunja.io/api/pkg/modules/auth"
"code.vikunja.io/api/pkg/routes"
"code.vikunja.io/api/pkg/user"
"code.vikunja.io/web"

View File

@ -17,9 +17,10 @@
package openid
import (
"code.vikunja.io/api/pkg/user"
"os"
"testing"
"code.vikunja.io/api/pkg/user"
)
// TestMain is the main test function used to bootstrap the test env

View File

@ -17,10 +17,8 @@
package openid
import (
"code.vikunja.io/api/pkg/modules/auth"
"context"
"encoding/json"
petname "github.com/dustinkirkland/golang-petname"
"math/rand"
"net/http"
"regexp"
@ -31,8 +29,10 @@ import (
"code.vikunja.io/api/pkg/config"
"code.vikunja.io/api/pkg/log"
"code.vikunja.io/api/pkg/models"
"code.vikunja.io/api/pkg/modules/auth"
"code.vikunja.io/api/pkg/user"
"github.com/coreos/go-oidc"
petname "github.com/dustinkirkland/golang-petname"
"github.com/labstack/echo/v4"
"golang.org/x/oauth2"
)
@ -64,7 +64,7 @@ func init() {
}
func getKeyFromName(name string) string {
reg, _ := regexp.Compile("[^a-z0-9]+")
reg := regexp.MustCompile("[^a-z0-9]+")
return reg.ReplaceAllString(strings.ToLower(name), "")
}
@ -242,6 +242,9 @@ func getOrCreateUser(cl *claims, issuer, subject string) (u *user.User, err erro
if user.IsErrUsernameExists(err) {
uu.Username = petname.Generate(3, "-")
u, err = user.CreateUser(uu)
if err != nil {
return nil, err
}
}
// And create its namespace
@ -249,19 +252,21 @@ func getOrCreateUser(cl *claims, issuer, subject string) (u *user.User, err erro
if err != nil {
return nil, err
}
} else {
// If it exists, check if the email address changed and change it if not
if cl.Email != u.Email {
u.Email = cl.Email
u, err = user.UpdateUser(&user.User{
ID: u.ID,
Email: cl.Email,
Issuer: issuer,
Subject: subject,
})
if err != nil {
return nil, err
}
return
}
// If it exists, check if the email address changed and change it if not
if cl.Email != u.Email {
u.Email = cl.Email
u, err = user.UpdateUser(&user.User{
ID: u.ID,
Email: cl.Email,
Issuer: issuer,
Subject: subject,
})
if err != nil {
return nil, err
}
}

View File

@ -17,9 +17,10 @@
package openid
import (
"testing"
"code.vikunja.io/api/pkg/db"
"github.com/stretchr/testify/assert"
"testing"
)
func TestGetOrCreateUser(t *testing.T) {

View File

@ -17,7 +17,6 @@
package handler
import (
auth2 "code.vikunja.io/api/pkg/modules/auth"
"io"
"net/http"
"strconv"
@ -26,6 +25,7 @@ import (
"code.vikunja.io/api/pkg/files"
"code.vikunja.io/api/pkg/log"
"code.vikunja.io/api/pkg/models"
auth2 "code.vikunja.io/api/pkg/modules/auth"
"code.vikunja.io/api/pkg/modules/background"
"code.vikunja.io/api/pkg/modules/background/unsplash"
"code.vikunja.io/web"

View File

@ -17,6 +17,8 @@
package v1
import (
"net/http"
"code.vikunja.io/api/pkg/config"
"code.vikunja.io/api/pkg/modules/auth/openid"
"code.vikunja.io/api/pkg/modules/keyvalue"
@ -25,7 +27,6 @@ import (
"code.vikunja.io/api/pkg/modules/migration/wunderlist"
"code.vikunja.io/api/pkg/version"
"github.com/labstack/echo/v4"
"net/http"
)
type vikunjaInfos struct {

View File

@ -17,10 +17,10 @@
package v1
import (
"code.vikunja.io/api/pkg/modules/auth"
"net/http"
"code.vikunja.io/api/pkg/models"
"code.vikunja.io/api/pkg/modules/auth"
"code.vikunja.io/web/handler"
"github.com/labstack/echo/v4"
)

View File

@ -17,10 +17,10 @@
package v1
import (
"code.vikunja.io/api/pkg/modules/auth"
"net/http"
"code.vikunja.io/api/pkg/models"
"code.vikunja.io/api/pkg/modules/auth"
user2 "code.vikunja.io/api/pkg/user"
"code.vikunja.io/web/handler"
"github.com/dgrijalva/jwt-go"

View File

@ -17,10 +17,10 @@
package v1
import (
auth2 "code.vikunja.io/api/pkg/modules/auth"
"net/http"
"code.vikunja.io/api/pkg/models"
auth2 "code.vikunja.io/api/pkg/modules/auth"
"code.vikunja.io/web/handler"
"github.com/labstack/echo/v4"
)

View File

@ -17,11 +17,11 @@
package v1
import (
auth2 "code.vikunja.io/api/pkg/modules/auth"
"net/http"
"strconv"
"code.vikunja.io/api/pkg/models"
auth2 "code.vikunja.io/api/pkg/modules/auth"
"code.vikunja.io/api/pkg/user"
"code.vikunja.io/web/handler"
"github.com/labstack/echo/v4"

View File

@ -18,13 +18,13 @@
package routes
import (
auth2 "code.vikunja.io/api/pkg/modules/auth"
"net/http"
"strconv"
"time"
"code.vikunja.io/api/pkg/config"
"code.vikunja.io/api/pkg/log"
auth2 "code.vikunja.io/api/pkg/modules/auth"
"code.vikunja.io/api/pkg/red"
"github.com/labstack/echo/v4"
"github.com/ulule/limiter/v3"

View File

@ -47,14 +47,14 @@
package routes
import (
"code.vikunja.io/api/pkg/modules/auth"
"code.vikunja.io/api/pkg/modules/auth/openid"
"strings"
"time"
"code.vikunja.io/api/pkg/config"
"code.vikunja.io/api/pkg/log"
"code.vikunja.io/api/pkg/models"
"code.vikunja.io/api/pkg/modules/auth"
"code.vikunja.io/api/pkg/modules/auth/openid"
"code.vikunja.io/api/pkg/modules/background"
backgroundHandler "code.vikunja.io/api/pkg/modules/background/handler"
"code.vikunja.io/api/pkg/modules/background/unsplash"

View File

@ -24,11 +24,13 @@ import (
"golang.org/x/crypto/bcrypt"
)
const issuerLocal = `local`
// CreateUser creates a new user and inserts it into the database
func CreateUser(user *User) (newUser *User, err error) {
if user.Issuer == "" {
user.Issuer = "local"
user.Issuer = issuerLocal
}
// Check if we have all needed information
@ -43,7 +45,7 @@ func CreateUser(user *User) (newUser *User, err error) {
return nil, err
}
if user.Issuer == "local" {
if user.Issuer == issuerLocal {
// Hash the password
user.Password, err = hashPassword(user.Password)
if err != nil {
@ -52,7 +54,7 @@ func CreateUser(user *User) (newUser *User, err error) {
}
user.IsActive = true
if config.MailerEnabled.GetBool() && user.Issuer == "local" {
if config.MailerEnabled.GetBool() && user.Issuer == issuerLocal {
// The new user should not be activated until it confirms his mail address
user.IsActive = false
// Generate a confirm token
@ -76,7 +78,7 @@ func CreateUser(user *User) (newUser *User, err error) {
return nil, err
}
err = sendConfirmEmail(user)
sendConfirmEmail(user)
return newUserOut, err
}
@ -89,8 +91,8 @@ func hashPassword(password string) (string, error) {
func checkIfUserIsValid(user *User) error {
if user.Email == "" ||
(user.Issuer != "local" && user.Subject == "") ||
(user.Issuer == "local" && (user.Password == "" ||
(user.Issuer != issuerLocal && user.Subject == "") ||
(user.Issuer == issuerLocal && (user.Password == "" ||
user.Username == "")) {
return ErrNoUsernamePassword{}
}
@ -120,7 +122,7 @@ func checkIfUserExists(user *User) (err error) {
Subject: user.Subject,
}
if user.Issuer != "local" {
if user.Issuer != issuerLocal {
userToCheck.Email = ""
}
@ -132,17 +134,17 @@ func checkIfUserExists(user *User) (err error) {
return err
}
}
if exists && user.Issuer == "local" {
if exists && user.Issuer == issuerLocal {
return ErrUserEmailExists{user.ID, user.Email}
}
return nil
}
func sendConfirmEmail(user *User) error {
func sendConfirmEmail(user *User) {
// Dont send a mail if no mailer is configured
if !config.MailerEnabled.GetBool() {
return nil
return
}
// Send the user a mail with a link to confirm the mail
@ -152,6 +154,4 @@ func sendConfirmEmail(user *User) error {
}
mail.SendMailWithTemplate(user.Email, user.Username+" + Vikunja = <3", "confirm-email", data)
return nil
}