func RegisterHandler(w http.ResponseWriter, r *http.Request) { var addr = r.FormValue("email") var password = r.FormValue("password") Info("New user: %v", addr) user, err := SaveUser(&User{ Email: addr, Password: password, }) switch err { case ERR_DUPLICATE_ADDRESS: ReturnJSON(API_INVALID_PARAM, "That email address is already taken") case nil: break default: panic(err) } // Send user confirmation email body := fmt.Sprintf(`Thank you for signing up with FtNox. Please click on this link to confirm your email address: https://%v/auth/email_confirm?code=%v`, Config.Domain, user.EmailCode) err = sendemail.SendEmail("Welcome to FtNox", body, []string{user.Email}) if err != nil { ReturnJSON(API_ERROR, err.Error()) } ReturnJSON(API_OK, nil) }
func sendEmail(message string) { defer func() { if err := recover(); err != nil { log.Printf("sendEmail error: %v", err) } }() subject := message if len(subject) > 80 { subject = subject[:80] } err := sendemail.SendEmail(subject, message, []string{"*****@*****.**"}) if err != nil { log.Printf("sendEmail error: %v\n%v", err, message) } }