set ldap auth

This commit is contained in:
Matthieu Lamalle 2019-11-28 10:21:17 +01:00
parent 62a91653c3
commit d53fd64121
6 changed files with 16 additions and 12 deletions

1
.gitignore vendored
View File

@ -1,2 +1,3 @@
foods.db foods.db
server.conf server.conf
server

View File

@ -5,4 +5,3 @@ Projet Go de vote pour choisir ce qu'on mange au déjeuner
TODO : TODO :
Afficher une liste de restaurants locaux répondant au vote du jour Afficher une liste de restaurants locaux répondant au vote du jour
Afficher le résultat du vote

View File

@ -11,7 +11,7 @@ import (
// LogIn auth the client // LogIn auth the client
func LogIn(username string, password string) (ok bool, user map[string]string) { func LogIn(username string, password string) (ok bool, user map[string]string) {
var configFile = "../server.conf" var configFile = "server.conf"
var conf *config.Config var conf *config.Config
var conferr error var conferr error
conf, conferr = config.NewFromFile(configFile) conf, conferr = config.NewFromFile(configFile)
@ -30,6 +30,7 @@ func LogIn(username string, password string) (ok bool, user map[string]string) {
GroupFilter: "(memberUid=%s)", GroupFilter: "(memberUid=%s)",
Attributes: conf.LDAP.Attributes, Attributes: conf.LDAP.Attributes,
} }
log.Print(ldapclient)
defer ldapclient.Close() defer ldapclient.Close()
ok, user, err := ldapclient.Authenticate(username, password) ok, user, err := ldapclient.Authenticate(username, password)

BIN
foods.db

Binary file not shown.

BIN
server

Binary file not shown.

View File

@ -1,6 +1,7 @@
package main package main
import ( import (
"cadoles/foodoles/auth"
"cadoles/foodoles/bdd" "cadoles/foodoles/bdd"
"cadoles/foodoles/config" "cadoles/foodoles/config"
"cadoles/foodoles/foodlist" "cadoles/foodoles/foodlist"
@ -51,12 +52,14 @@ func main() {
// ServerHTTP is the entry point to all requests // ServerHTTP is the entry point to all requests
func (u *User) ServeHTTP(w http.ResponseWriter, r *http.Request) { func (u *User) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if err := r.ParseForm(); err != nil { if err := r.ParseForm(); err != nil {
log.Printf("ParseForm() err: %v", err) log.Printf("ParseForm() err: %v", err)
} else { } else {
u.Auth(r.FormValue("user"), r.FormValue("password")) u.Auth(r.FormValue("user"), r.FormValue("password"))
} }
if u.Name == "" { if u.Name == "" {
LogInPage(w, r) LogInPage(w, r)
return return
} }
@ -77,14 +80,14 @@ func (u *User) ServeHTTP(w http.ResponseWriter, r *http.Request) {
// Auth is the login page for user // Auth is the login page for user
func (u *User) Auth(user string, pass string) bool { func (u *User) Auth(user string, pass string) bool {
// auth, _ := auth.LogIn(user, pass) auth, _ := auth.LogIn(user, pass)
// if auth { if auth {
// u.Name = user u.Name = user
// u.Password = pass u.Password = pass
// } }
u.Name = "mlamalle" // auth := true
u.Password = "password" // u.Name = "mlamalle"
var auth = true // u.Password = "pass"
return auth return auth
} }