diff --git a/routes/user/authenticate_endpoint.go b/routes/user/authenticate_endpoint.go index 0f0ec99..82c2dc9 100644 --- a/routes/user/authenticate_endpoint.go +++ b/routes/user/authenticate_endpoint.go @@ -77,13 +77,13 @@ func authenticated(c *gin.Context) { "user": user.User, }) } else { - externalAuth, err := configuration.GlobalConfig.Bool("external-auth") + authExternal, err := configuration.GlobalConfig.Bool("auth-external") if err != nil { helper.UnauthorizedError(c, "Backend configuration error") return } - if externalAuth { + if authExternal { c.JSON(http.StatusOK, gin.H{ "success": true, "authenticated": false, @@ -112,18 +112,22 @@ func authenticated(c *gin.Context) { func authenticate(c *gin.Context) { var user *User - externalAuth, err := configuration.GlobalConfig.Bool("auth.external") + authExternal, err := configuration.GlobalConfig.Bool("auth.external") if err != nil { helper.UnauthorizedError(c, "Backend configuration error") return } - if err != nil || !externalAuth { + if err != nil || !authExternal { user = authenticateStandard(c) } else { user = authenticateExternal(c) } + if user == nil { + return + } + expiresStr, err := configuration.GlobalConfig.String("jwt.expires-after") if err != nil { helper.UnauthorizedError(c, "Backend configuration error") diff --git a/routes/user/user_methods.go b/routes/user/user_methods.go index f1dcd59..885af6d 100644 --- a/routes/user/user_methods.go +++ b/routes/user/user_methods.go @@ -42,7 +42,7 @@ func NewUser(username, password, mail, role string, active bool) (*User, error) // Check that the username is NOT taken err := newUser.ByUsername(username) - if err != nil { + if err == nil { return nil, fmt.Errorf("Username is already taken") }