Refactoring
This commit is contained in:
parent
666b34150b
commit
7f3383944b
4 changed files with 50 additions and 50 deletions
|
@ -64,7 +64,7 @@ func passwordLost(user User, config *ConfigFile, ldapConn *ldap.Conn) error {
|
||||||
// Préparation du courriel à envoyer
|
// Préparation du courriel à envoyer
|
||||||
user.Password = suggestPassword()
|
user.Password = suggestPassword()
|
||||||
code := b64.URLEncoding.EncodeToString([]byte(user.UID + ";" + user.Password))
|
code := b64.URLEncoding.EncodeToString([]byte(user.UID + ";" + user.Password))
|
||||||
user.DN = "uid=" + searchRes.Entries[0].GetAttributeValue("cn") + ",ou=invitations,dc=resdigita,dc=org"
|
user.DN = "uid=" + searchRes.Entries[0].GetAttributeValue("cn") + "," + config.InvitationBaseDN
|
||||||
user.UID = searchRes.Entries[0].GetAttributeValue("cn")
|
user.UID = searchRes.Entries[0].GetAttributeValue("cn")
|
||||||
user.CN = searchRes.Entries[0].GetAttributeValue("cn")
|
user.CN = searchRes.Entries[0].GetAttributeValue("cn")
|
||||||
user.Mail = searchRes.Entries[0].GetAttributeValue("mail")
|
user.Mail = searchRes.Entries[0].GetAttributeValue("mail")
|
||||||
|
@ -81,11 +81,11 @@ func passwordLost(user User, config *ConfigFile, ldapConn *ldap.Conn) error {
|
||||||
if len(searchRes.Entries) == 0 {
|
if len(searchRes.Entries) == 0 {
|
||||||
/* Add the invitation */
|
/* Add the invitation */
|
||||||
addReq := ldap.NewAddRequest(
|
addReq := ldap.NewAddRequest(
|
||||||
user.DN,
|
"uid="+searchRes.Entries[0].GetAttributeValue("cn")+","+config.InvitationBaseDN,
|
||||||
nil)
|
nil)
|
||||||
addReq.Attribute("objectClass", []string{"top", "account", "simpleSecurityObject"})
|
addReq.Attribute("objectClass", []string{"top", "account", "simpleSecurityObject"})
|
||||||
addReq.Attribute("uid", []string{user.UID})
|
addReq.Attribute("uid", []string{searchRes.Entries[0].GetAttributeValue("cn")})
|
||||||
addReq.Attribute("userPassword", []string{"absdefghi"})
|
addReq.Attribute("userPassword", []string{suggestPassword()})
|
||||||
addReq.Attribute("seeAlso", []string{config.UserNameAttr + "=" + user.UID + "," + config.UserBaseDN})
|
addReq.Attribute("seeAlso", []string{config.UserNameAttr + "=" + user.UID + "," + config.UserBaseDN})
|
||||||
err = ldapConn.Add(addReq)
|
err = ldapConn.Add(addReq)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
1
utils.go
1
utils.go
|
@ -43,6 +43,7 @@ func openLdap(config *ConfigFile) (*ldap.Conn, error) {
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Suggesting a 12 char password with some excentrics
|
||||||
func suggestPassword() string {
|
func suggestPassword() string {
|
||||||
password := ""
|
password := ""
|
||||||
chars := "abcdfghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%&*+_-="
|
chars := "abcdfghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%&*+_-="
|
||||||
|
|
|
@ -56,52 +56,6 @@ func openNewUserLdap(config *ConfigFile) (*ldap.Conn, error) {
|
||||||
return l, err
|
return l, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleLostPassword(w http.ResponseWriter, r *http.Request) {
|
|
||||||
templateLostPasswordPage := getTemplate("passwd/lost.html")
|
|
||||||
if checkLogin(w, r) != nil {
|
|
||||||
http.Redirect(w, r, "/", http.StatusTemporaryRedirect)
|
|
||||||
}
|
|
||||||
|
|
||||||
data := PasswordLostData{
|
|
||||||
Common: NestedCommonTplData{
|
|
||||||
CanAdmin: false,
|
|
||||||
LoggedIn: false},
|
|
||||||
}
|
|
||||||
|
|
||||||
if r.Method == "POST" {
|
|
||||||
r.ParseForm()
|
|
||||||
data.Username = strings.TrimSpace(strings.Join(r.Form["username"], ""))
|
|
||||||
data.Mail = strings.TrimSpace(strings.Join(r.Form["mail"], ""))
|
|
||||||
data.OtherMailbox = strings.TrimSpace(strings.Join(r.Form["othermailbox"], ""))
|
|
||||||
user := User{
|
|
||||||
CN: strings.TrimSpace(strings.Join(r.Form["username"], "")),
|
|
||||||
UID: strings.TrimSpace(strings.Join(r.Form["username"], "")),
|
|
||||||
Mail: strings.TrimSpace(strings.Join(r.Form["mail"], "")),
|
|
||||||
OtherMailbox: strings.TrimSpace(strings.Join(r.Form["othermailbox"], "")),
|
|
||||||
}
|
|
||||||
ldapConn, err := openNewUserLdap(config)
|
|
||||||
if err != nil {
|
|
||||||
log.Printf(fmt.Sprintf("handleLostPassword 99 : %v %v", err, ldapConn))
|
|
||||||
data.Common.ErrorMessage = err.Error()
|
|
||||||
}
|
|
||||||
err = passwordLost(user, config, ldapConn)
|
|
||||||
if err != nil {
|
|
||||||
log.Printf(fmt.Sprintf("handleLostPassword 104 : %v %v", err, ldapConn))
|
|
||||||
data.Common.ErrorMessage = err.Error()
|
|
||||||
} else {
|
|
||||||
err = ldapConn.Bind(config.NewUserDN, config.NewUserPassword)
|
|
||||||
if err != nil {
|
|
||||||
log.Printf(fmt.Sprintf("handleLostPassword 109 : %v %v", err, ldapConn))
|
|
||||||
data.Common.ErrorMessage = err.Error()
|
|
||||||
} else {
|
|
||||||
data.Common.Success = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
data.Common.CanAdmin = false
|
|
||||||
templateLostPasswordPage.Execute(w, data)
|
|
||||||
}
|
|
||||||
|
|
||||||
func handleInviteNewAccount(w http.ResponseWriter, r *http.Request) {
|
func handleInviteNewAccount(w http.ResponseWriter, r *http.Request) {
|
||||||
l, err := ldapOpen(w)
|
l, err := ldapOpen(w)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -10,6 +10,51 @@ import (
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func handleLostPassword(w http.ResponseWriter, r *http.Request) {
|
||||||
|
templateLostPasswordPage := getTemplate("passwd/lost.html")
|
||||||
|
if checkLogin(w, r) != nil {
|
||||||
|
http.Redirect(w, r, "/", http.StatusTemporaryRedirect)
|
||||||
|
}
|
||||||
|
|
||||||
|
data := PasswordLostData{
|
||||||
|
Common: NestedCommonTplData{
|
||||||
|
CanAdmin: false,
|
||||||
|
LoggedIn: false},
|
||||||
|
}
|
||||||
|
|
||||||
|
if r.Method == "POST" {
|
||||||
|
r.ParseForm()
|
||||||
|
data.Username = strings.TrimSpace(strings.Join(r.Form["username"], ""))
|
||||||
|
data.Mail = strings.TrimSpace(strings.Join(r.Form["mail"], ""))
|
||||||
|
data.OtherMailbox = strings.TrimSpace(strings.Join(r.Form["othermailbox"], ""))
|
||||||
|
user := User{
|
||||||
|
CN: strings.TrimSpace(strings.Join(r.Form["username"], "")),
|
||||||
|
UID: strings.TrimSpace(strings.Join(r.Form["username"], "")),
|
||||||
|
Mail: strings.TrimSpace(strings.Join(r.Form["mail"], "")),
|
||||||
|
OtherMailbox: strings.TrimSpace(strings.Join(r.Form["othermailbox"], "")),
|
||||||
|
}
|
||||||
|
ldapConn, err := openNewUserLdap(config)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf(fmt.Sprintf("handleLostPassword 99 : %v %v", err, ldapConn))
|
||||||
|
data.Common.ErrorMessage = err.Error()
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
log.Printf(fmt.Sprintf("handleLostPassword 104 : %v %v", err, ldapConn))
|
||||||
|
data.Common.ErrorMessage = err.Error()
|
||||||
|
} else {
|
||||||
|
err = ldapConn.Bind(config.NewUserDN, config.NewUserPassword)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf(fmt.Sprintf("handleLostPassword 109 : %v %v", err, ldapConn))
|
||||||
|
data.Common.ErrorMessage = err.Error()
|
||||||
|
} else {
|
||||||
|
data.Common.Success = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
data.Common.CanAdmin = false
|
||||||
|
templateLostPasswordPage.Execute(w, data)
|
||||||
|
}
|
||||||
|
|
||||||
func handleFoundPassword(w http.ResponseWriter, r *http.Request) {
|
func handleFoundPassword(w http.ResponseWriter, r *http.Request) {
|
||||||
templateFoundPasswordPage := getTemplate("passwd.html")
|
templateFoundPasswordPage := getTemplate("passwd.html")
|
||||||
data := PasswdTplData{
|
data := PasswdTplData{
|
||||||
|
|
Loading…
Add table
Reference in a new issue