G Pas
This commit is contained in:
parent
4bd314864c
commit
803c2e952e
4 changed files with 50 additions and 21 deletions
2
gpas.go
2
gpas.go
|
@ -84,7 +84,7 @@ func passwordLost(user User, config *ConfigFile, ldapConn *ldap.Conn) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func passwordFound(user User, config *ConfigFile, ldapConn *ldap.Conn) (bool, error) {
|
func passwordFound(user User, config *ConfigFile, ldapConn *ldap.Conn) (bool, error) {
|
||||||
l := openLdap(*config)
|
l := openLdap(config)
|
||||||
err := l.Bind(user.DN, user.Password)
|
err := l.Bind(user.DN, user.Password)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
|
|
38
invite.go
38
invite.go
|
@ -46,12 +46,6 @@ type PasswordFoundData struct {
|
||||||
OtherMailbox string
|
OtherMailbox string
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleFoundPassword(w http.ResponseWriter, r *http.Request) {
|
|
||||||
templateFoundPasswordPage := getTemplate("passwd.html")
|
|
||||||
data := PasswordFoundData{}
|
|
||||||
templateFoundPasswordPage.Execute(w, data)
|
|
||||||
}
|
|
||||||
|
|
||||||
type PasswordLostData struct {
|
type PasswordLostData struct {
|
||||||
ErrorMessage string
|
ErrorMessage string
|
||||||
Success bool
|
Success bool
|
||||||
|
@ -60,19 +54,20 @@ type PasswordLostData struct {
|
||||||
OtherMailbox string
|
OtherMailbox string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func openNewUserLdap(config *ConfigFile) (*ldap.Conn, error) {
|
||||||
|
l := openLdap(config)
|
||||||
|
err := l.Bind(config.NewUserDN, config.NewUserPassword)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf(fmt.Sprintf("openNewUserLdap : %v %v", err, l))
|
||||||
|
// data.ErrorMessage = err.Error()
|
||||||
|
}
|
||||||
|
return l, err
|
||||||
|
}
|
||||||
|
|
||||||
func handleLostPassword(w http.ResponseWriter, r *http.Request) {
|
func handleLostPassword(w http.ResponseWriter, r *http.Request) {
|
||||||
templateLostPasswordPage := getTemplate("password_lost.html")
|
templateLostPasswordPage := getTemplate("password_lost.html")
|
||||||
data := PasswordLostData{}
|
data := PasswordLostData{}
|
||||||
l, err := ldapOpen(w)
|
|
||||||
if err != nil {
|
|
||||||
log.Printf(fmt.Sprintf("handleLostPassword : %v %v", err, l))
|
|
||||||
data.ErrorMessage = err.Error()
|
|
||||||
}
|
|
||||||
err = l.Bind(config.NewUserDN, config.NewUserPassword)
|
|
||||||
if err != nil {
|
|
||||||
log.Printf(fmt.Sprintf("handleLostPassword : %v %v", err, l))
|
|
||||||
data.ErrorMessage = err.Error()
|
|
||||||
}
|
|
||||||
if r.Method == "POST" {
|
if r.Method == "POST" {
|
||||||
r.ParseForm()
|
r.ParseForm()
|
||||||
data.Username = strings.TrimSpace(strings.Join(r.Form["username"], ""))
|
data.Username = strings.TrimSpace(strings.Join(r.Form["username"], ""))
|
||||||
|
@ -83,10 +78,15 @@ func handleLostPassword(w http.ResponseWriter, r *http.Request) {
|
||||||
Mail: data.Mail,
|
Mail: data.Mail,
|
||||||
OtherMailbox: data.OtherMailbox,
|
OtherMailbox: data.OtherMailbox,
|
||||||
}
|
}
|
||||||
err = passwordLost(user, config, l)
|
ldapConn, err := openNewUserLdap(config)
|
||||||
err = l.Bind(config.NewUserDN, config.NewUserPassword)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf(fmt.Sprintf("handleLostPassword : %v %v", err, l))
|
log.Printf(fmt.Sprintf("handleLostPassword : %v %v", err, ldapConn))
|
||||||
|
data.ErrorMessage = err.Error()
|
||||||
|
}
|
||||||
|
err = passwordLost(user, config, ldapConn)
|
||||||
|
err = ldapConn.Bind(config.NewUserDN, config.NewUserPassword)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf(fmt.Sprintf("handleLostPassword : %v %v", err, ldapConn))
|
||||||
data.ErrorMessage = err.Error()
|
data.ErrorMessage = err.Error()
|
||||||
} else {
|
} else {
|
||||||
data.Success = true
|
data.Success = true
|
||||||
|
|
29
profile.go
29
profile.go
|
@ -1,8 +1,13 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
b64 "encoding/base64"
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/gorilla/mux"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ProfileTplData struct {
|
type ProfileTplData struct {
|
||||||
|
@ -122,6 +127,30 @@ type PasswdTplData struct {
|
||||||
Success bool
|
Success bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func handleFoundPassword(w http.ResponseWriter, r *http.Request) {
|
||||||
|
templateFoundPasswordPage := getTemplate("passwd.html")
|
||||||
|
data := PasswdTplData{}
|
||||||
|
code := mux.Vars(r)["code"]
|
||||||
|
// code = strings.TrimSpace(strings.Join([]string{code}, ""))
|
||||||
|
newCode, _ := b64.URLEncoding.DecodeString(code)
|
||||||
|
ldapConn, err := openNewUserLdap(config)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf(fmt.Sprint("handleFoundPassword %v", err))
|
||||||
|
data.ErrorMessage = err.Error()
|
||||||
|
}
|
||||||
|
codeArray := strings.Split(string(newCode), ";")
|
||||||
|
user := User{
|
||||||
|
UID: codeArray[0],
|
||||||
|
Password: codeArray[1],
|
||||||
|
}
|
||||||
|
data.Success, err = passwordFound(user, config, ldapConn)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf(fmt.Sprint("handleFoundPassword %v", err))
|
||||||
|
data.ErrorMessage = err.Error()
|
||||||
|
}
|
||||||
|
templateFoundPasswordPage.Execute(w, data)
|
||||||
|
}
|
||||||
|
|
||||||
func handlePasswd(w http.ResponseWriter, r *http.Request) {
|
func handlePasswd(w http.ResponseWriter, r *http.Request) {
|
||||||
templatePasswd := getTemplate("passwd.html")
|
templatePasswd := getTemplate("passwd.html")
|
||||||
|
|
||||||
|
|
2
utils.go
2
utils.go
|
@ -10,7 +10,7 @@ import (
|
||||||
// "golang.org/x/text/encoding/unicode"
|
// "golang.org/x/text/encoding/unicode"
|
||||||
)
|
)
|
||||||
|
|
||||||
func openLdap(config ConfigFile) *ldap.Conn {
|
func openLdap(config *ConfigFile) *ldap.Conn {
|
||||||
l, err := ldap.DialURL(config.LdapServerAddr)
|
l, err := ldap.DialURL(config.LdapServerAddr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf(fmt.Sprint("Erreur connect LDAP %v", err))
|
log.Printf(fmt.Sprint("Erreur connect LDAP %v", err))
|
||||||
|
|
Loading…
Reference in a new issue