Can launch the executable with arguments to get reset token
This commit is contained in:
parent
0197446952
commit
6836e70e83
2 changed files with 53 additions and 14 deletions
44
lost.go
44
lost.go
|
|
@ -51,6 +51,25 @@ func (l LDAPConn) genToken(dn string, previous bool) string {
|
|||
return base64.StdEncoding.EncodeToString(hash.Sum(nil)[:])
|
||||
}
|
||||
|
||||
func lostPasswordToken(conn *LDAPConn, login string) (string, string, error) {
|
||||
// Bind as service to perform the search
|
||||
err := conn.ServiceBind()
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
|
||||
// Search the dn of the given user
|
||||
dn, err := conn.SearchDN(login, true)
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
|
||||
// Generate the token
|
||||
token := conn.genToken(dn, false)
|
||||
|
||||
return token, dn, nil
|
||||
}
|
||||
|
||||
func lostPassword(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != "POST" {
|
||||
displayTmpl(w, "lost.html", map[string]interface{}{})
|
||||
|
|
@ -65,24 +84,13 @@ func lostPassword(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
// Bind as service to perform the search
|
||||
err = conn.ServiceBind()
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
displayTmplError(w, http.StatusInternalServerError, "lost.html", map[string]interface{}{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
// Search the dn of the given user
|
||||
dn, err := conn.SearchDN(r.PostFormValue("login"), true)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
displayTmplError(w, http.StatusInternalServerError, "lost.html", map[string]interface{}{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
// Generate the token
|
||||
token := conn.genToken(dn, false)
|
||||
token, dn, err := lostPasswordToken(conn, r.PostFormValue("login"))
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
displayTmplError(w, http.StatusInternalServerError, "lost.html", map[string]interface{}{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
// Search the email address
|
||||
entries, err := conn.GetEntry(dn)
|
||||
|
|
@ -114,7 +122,7 @@ func lostPassword(w http.ResponseWriter, r *http.Request) {
|
|||
m.SetHeader("From", "noreply@nemunai.re")
|
||||
m.SetHeader("To", email)
|
||||
m.SetHeader("Subject", "SSO nemunai.re: password recovery")
|
||||
m.SetBody("text/plain", "Hello "+cn+"!\n\nSomeone, and we hope it's you, requested to reset your account password. \nIn order to continue, go to:\nhttps://ldap.nemunai.re/reset?l="+r.PostFormValue("login")+"&t="+token+"\n\nBest regards,\n-- \nnemunai.re SSO")
|
||||
m.SetBody("text/plain", "Hello "+cn+"!\n\nSomeone, and we hope it's you, requested to reset your account password. \nIn order to continue, go to:\n"+BASEURL+"/reset?l="+r.PostFormValue("login")+"&t="+token+"\n\nBest regards,\n-- \nnemunai.re SSO")
|
||||
|
||||
var s gomail.Sender
|
||||
if myLDAP.MailHost != "" {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue