fix ldap sync for disabled users, check if admin username is an email address, rename username to email

This commit is contained in:
Christoph Haas
2021-02-26 23:43:29 +01:00
parent 5bc3aa0036
commit e1c7a43496
4 changed files with 15 additions and 9 deletions

View File

@@ -3,6 +3,7 @@ package password
import (
"fmt"
"math/rand"
"regexp"
"strings"
"time"
@@ -14,6 +15,8 @@ import (
"gorm.io/gorm"
)
var emailRegex = regexp.MustCompile("^[a-zA-Z0-9.!#$%&'*+\\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$")
// Provider implements a password login method for a database backend.
type Provider struct {
db *gorm.DB
@@ -104,6 +107,10 @@ func (provider Provider) GetUserModel(ctx *authentication.AuthContext) (*authent
}
func (provider Provider) InitializeAdmin(email, password string) error {
if !emailRegex.MatchString(email) {
return errors.New("admin username must be an email address")
}
admin := users.User{}
provider.db.Unscoped().Where("email = ?", email).FirstOrInit(&admin)