mirror of
https://git.rwth-aachen.de/acs/public/villas/web-backend-go/
synced 2025-03-30 00:00:12 +01:00
smaller bugfixes for external authentication
This commit is contained in:
parent
47b094b68d
commit
c81c1bb04f
2 changed files with 9 additions and 5 deletions
|
@ -77,13 +77,13 @@ func authenticated(c *gin.Context) {
|
||||||
"user": user.User,
|
"user": user.User,
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
externalAuth, err := configuration.GlobalConfig.Bool("external-auth")
|
authExternal, err := configuration.GlobalConfig.Bool("auth-external")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
helper.UnauthorizedError(c, "Backend configuration error")
|
helper.UnauthorizedError(c, "Backend configuration error")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if externalAuth {
|
if authExternal {
|
||||||
c.JSON(http.StatusOK, gin.H{
|
c.JSON(http.StatusOK, gin.H{
|
||||||
"success": true,
|
"success": true,
|
||||||
"authenticated": false,
|
"authenticated": false,
|
||||||
|
@ -112,18 +112,22 @@ func authenticated(c *gin.Context) {
|
||||||
func authenticate(c *gin.Context) {
|
func authenticate(c *gin.Context) {
|
||||||
var user *User
|
var user *User
|
||||||
|
|
||||||
externalAuth, err := configuration.GlobalConfig.Bool("auth.external")
|
authExternal, err := configuration.GlobalConfig.Bool("auth.external")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
helper.UnauthorizedError(c, "Backend configuration error")
|
helper.UnauthorizedError(c, "Backend configuration error")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil || !externalAuth {
|
if err != nil || !authExternal {
|
||||||
user = authenticateStandard(c)
|
user = authenticateStandard(c)
|
||||||
} else {
|
} else {
|
||||||
user = authenticateExternal(c)
|
user = authenticateExternal(c)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if user == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
expiresStr, err := configuration.GlobalConfig.String("jwt.expires-after")
|
expiresStr, err := configuration.GlobalConfig.String("jwt.expires-after")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
helper.UnauthorizedError(c, "Backend configuration error")
|
helper.UnauthorizedError(c, "Backend configuration error")
|
||||||
|
|
|
@ -42,7 +42,7 @@ func NewUser(username, password, mail, role string, active bool) (*User, error)
|
||||||
|
|
||||||
// Check that the username is NOT taken
|
// Check that the username is NOT taken
|
||||||
err := newUser.ByUsername(username)
|
err := newUser.ByUsername(username)
|
||||||
if err != nil {
|
if err == nil {
|
||||||
return nil, fmt.Errorf("Username is already taken")
|
return nil, fmt.Errorf("Username is already taken")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue