Added dashboard login for LDAP users
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/gorilla/sessions"
|
"github.com/gorilla/sessions"
|
||||||
|
"go.senan.xyz/gonic/ldap"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (c *Controller) ServeLoginDo(w http.ResponseWriter, r *http.Request) {
|
func (c *Controller) ServeLoginDo(w http.ResponseWriter, r *http.Request) {
|
||||||
@@ -18,11 +19,19 @@ func (c *Controller) ServeLoginDo(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
user := c.dbc.GetUserByName(username)
|
user := c.dbc.GetUserByName(username)
|
||||||
if user == nil || password != user.Password {
|
if user == nil || password != user.Password {
|
||||||
|
// Because internal authentication failed, we can now try to use LDAP, if
|
||||||
|
// it was enabled by the user.
|
||||||
|
ok, err := ldap.CheckLDAPcreds(username, password, c.dbc)
|
||||||
|
if err != nil {
|
||||||
|
sessAddFlashW(session, []string{err.Error()})
|
||||||
|
} else if !ok {
|
||||||
sessAddFlashW(session, []string{"invalid username / password"})
|
sessAddFlashW(session, []string{"invalid username / password"})
|
||||||
|
|
||||||
sessLogSave(session, w, r)
|
sessLogSave(session, w, r)
|
||||||
http.Redirect(w, r, r.Referer(), http.StatusSeeOther)
|
http.Redirect(w, r, r.Referer(), http.StatusSeeOther)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// put the user name into the session. future endpoints after this one
|
// put the user name into the session. future endpoints after this one
|
||||||
// are wrapped with WithUserSession() which will get the name from the
|
// are wrapped with WithUserSession() which will get the name from the
|
||||||
// session and put the row into the request context
|
// session and put the row into the request context
|
||||||
|
|||||||
Reference in New Issue
Block a user