mirror of
https://github.com/ClusterCockpit/cc-backend
synced 2024-11-10 08:57:25 +01:00
LDAP users have no email address
This commit is contained in:
parent
5235feb1d6
commit
33f6792fbf
12
auth/auth.go
12
auth/auth.go
@ -72,11 +72,11 @@ func (auth *Authentication) Init(db *sqlx.DB, ldapConfig *LdapConfig) error {
|
|||||||
auth.db = db
|
auth.db = db
|
||||||
_, err := db.Exec(`
|
_, err := db.Exec(`
|
||||||
CREATE TABLE IF NOT EXISTS user (
|
CREATE TABLE IF NOT EXISTS user (
|
||||||
username varchar(255) PRIMARY KEY,
|
username varchar(255) PRIMARY KEY NOT NULL,
|
||||||
password varchar(255) DEFAULT NULL,
|
password varchar(255) DEFAULT NULL,
|
||||||
ldap tinyint DEFAULT 0,
|
ldap tinyint NOT NULL DEFAULT 0,
|
||||||
name varchar(255) DEFAULT NULL,
|
name varchar(255) DEFAULT NULL,
|
||||||
roles varchar(255) DEFAULT NULL,
|
roles varchar(255) NOT NULL DEFAULT "[]",
|
||||||
email varchar(255) DEFAULT NULL);`)
|
email varchar(255) DEFAULT NULL);`)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -241,14 +241,18 @@ func FetchUser(ctx context.Context, db *sqlx.DB, username string) (*model.User,
|
|||||||
}
|
}
|
||||||
|
|
||||||
user := &model.User{Username: username}
|
user := &model.User{Username: username}
|
||||||
|
var name, email sql.NullString
|
||||||
if err := sq.Select("name", "email").From("user").Where("user.username = ?", username).
|
if err := sq.Select("name", "email").From("user").Where("user.username = ?", username).
|
||||||
RunWith(db).QueryRow().Scan(&user.Name, &user.Email); err != nil {
|
RunWith(db).QueryRow().Scan(&name, &email); err != nil {
|
||||||
if err == sql.ErrNoRows {
|
if err == sql.ErrNoRows {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
user.Name = name.String
|
||||||
|
user.Email = email.String
|
||||||
return user, nil
|
return user, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user