Skip to content

Commit 1bd7a51

Browse files
committed
-
1 parent 96b510d commit 1bd7a51

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

Diff for: CHANGES

+4-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,7 @@ first release
33

44
1.1.0-release-build300419
55
- salted and hashed passwords in database
6-
- send random recovery passwords on mail
6+
- send random recovery passwords on mail
7+
8+
1.1.1-release-build030519
9+
- reset the password to random only if the mail was successfully sent

Diff for: ui_reset_random.go

+8-7
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
package main
44

55
import (
6-
"log"
76
"net/http"
87

98
"github.com/geosoft1/token"
@@ -22,12 +21,8 @@ func reset(w http.ResponseWriter, r *http.Request) {
2221
http.Error(w, http.StatusText(http.StatusNotAcceptable), http.StatusNotAcceptable)
2322
return
2423
}
25-
// TODO reset password to random, uncomment the following 4 lines
24+
// generate a random password
2625
user.Password = token.GetToken(token_len)
27-
if err := sqlUpdateUser(&user); err != nil {
28-
http.Error(w, http.StatusText(http.StatusNotAcceptable), http.StatusNotAcceptable)
29-
return
30-
}
3126
// https://stackoverflow.com/a/24431749
3227
mail := gomail.NewMessage()
3328
mail.SetAddressHeader("From", config.SMTP.User, config.SMTP.Name)
@@ -37,7 +32,13 @@ func reset(w http.ResponseWriter, r *http.Request) {
3732
dialer := gomail.NewPlainDialer(config.SMTP.Server, config.SMTP.Port, config.SMTP.User, config.SMTP.Password)
3833
//dialer.TLSConfig = &tls.Config{InsecureSkipVerify: true}
3934
if err := dialer.DialAndSend(mail); err != nil {
40-
log.Println(err)
35+
http.Error(w, http.StatusText(http.StatusServiceUnavailable), http.StatusServiceUnavailable)
36+
return
37+
}
38+
// reset the password to random only if the mail was successfully sent
39+
if err := sqlUpdateUser(&user); err != nil {
40+
http.Error(w, http.StatusText(http.StatusNotAcceptable), http.StatusNotAcceptable)
41+
return
4142
}
4243
w.Header().Set("Content-Type", "text/html; charset=utf-8")
4344
w.Write([]byte("A mail with instructions was send, read and <a href=\"/\">sign in</a>"))

0 commit comments

Comments
 (0)