mirror of https://github.com/statping/statping
newsletter feature
parent
fd75693331
commit
5eecb5fa53
|
@ -71,6 +71,22 @@
|
||||||
<input @keyup="canSubmit" v-model="setup.confirm_password" id="password_confirm" type="password" class="form-control" placeholder="password" required>
|
<input @keyup="canSubmit" v-model="setup.confirm_password" id="password_confirm" type="password" class="form-control" placeholder="password" required>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-8">
|
||||||
|
<label>Email Address</label>
|
||||||
|
<input @keyup="canSubmit" v-model="setup.email" id="email" type="text" class="form-control" placeholder="myemail@domain.com">
|
||||||
|
</div>
|
||||||
|
<div class="col-4">
|
||||||
|
<label class="d-none d-sm-block">Newsletter</label>
|
||||||
|
<span @click="setup.newsletter = !!setup.newsletter" class="switch">
|
||||||
|
<input v-model="setup.newsletter" type="checkbox" name="using_cdn" class="switch" id="send_newsletter" :checked="setup.newsletter">
|
||||||
|
<label for="send_newsletter"></label>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<small>We will not share your email, emails are only for major updates.</small>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div v-if="error" class="col-12 alert alert-danger">
|
<div v-if="error" class="col-12 alert alert-danger">
|
||||||
|
@ -111,7 +127,9 @@
|
||||||
username: "",
|
username: "",
|
||||||
password: "",
|
password: "",
|
||||||
confirm_password: "",
|
confirm_password: "",
|
||||||
sample_data: true
|
sample_data: true,
|
||||||
|
newsletter: true,
|
||||||
|
email: "",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -9,6 +9,9 @@ import (
|
||||||
"github.com/statping/statping/types/services"
|
"github.com/statping/statping/types/services"
|
||||||
"github.com/statping/statping/utils"
|
"github.com/statping/statping/utils"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"net/url"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -29,6 +32,8 @@ func processSetupHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
project := r.PostForm.Get("project")
|
project := r.PostForm.Get("project")
|
||||||
description := r.PostForm.Get("description")
|
description := r.PostForm.Get("description")
|
||||||
domain := r.PostForm.Get("domain")
|
domain := r.PostForm.Get("domain")
|
||||||
|
newsletter := r.PostForm.Get("newsletter")
|
||||||
|
sendNews, _ := strconv.ParseBool(newsletter)
|
||||||
|
|
||||||
log.WithFields(utils.ToFields(core.App, confgs)).Debugln("new configs posted")
|
log.WithFields(utils.ToFields(core.App, confgs)).Debugln("new configs posted")
|
||||||
|
|
||||||
|
@ -96,6 +101,13 @@ func processSetupHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
core.App = c
|
core.App = c
|
||||||
|
|
||||||
|
if sendNews {
|
||||||
|
log.Infoln("Sending email address to newsletter server")
|
||||||
|
if err := registerNews(confgs.Email, confgs.Domain); err != nil {
|
||||||
|
log.Errorln(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
log.Infoln("Initializing new Statping instance")
|
log.Infoln("Initializing new Statping instance")
|
||||||
|
|
||||||
if _, err := services.SelectAllServices(true); err != nil {
|
if _, err := services.SelectAllServices(true); err != nil {
|
||||||
|
@ -120,3 +132,17 @@ func processSetupHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
returnJson(out, w, r)
|
returnJson(out, w, r)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func registerNews(email, domain string) error {
|
||||||
|
v := url.Values{}
|
||||||
|
v.Set("email", email)
|
||||||
|
v.Set("domain", domain)
|
||||||
|
v.Set("timezone", "UTC")
|
||||||
|
rb := strings.NewReader(v.Encode())
|
||||||
|
|
||||||
|
_, _, err := utils.HttpRequest("https://news.statping.com", "POST", nil, nil, rb, 10*time.Second, true, nil)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue