add abo logic
This commit is contained in:
parent
410ee3253c
commit
a8a6039d8d
2
main.go
2
main.go
|
|
@ -55,7 +55,7 @@ func serveTemplate(w http.ResponseWriter, r *http.Request) {
|
||||||
var scales = getMyDevs(userName)
|
var scales = getMyDevs(userName)
|
||||||
var last_metrics []OneMetric
|
var last_metrics []OneMetric
|
||||||
|
|
||||||
if r.URL.Path == "/scales.html" {
|
if (r.URL.Path == "/scales.html") || (r.URL.Path == "/abos.html") {
|
||||||
// wir holen noch die letzten Metriken
|
// wir holen noch die letzten Metriken
|
||||||
for _, v := range scales {
|
for _, v := range scales {
|
||||||
last_metric := getLastMetrics(v)
|
last_metric := getLastMetrics(v)
|
||||||
|
|
|
||||||
29
scales.go
29
scales.go
|
|
@ -3,6 +3,7 @@ package main
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
"regexp"
|
||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -23,6 +24,12 @@ func save_scale_settingsHandler(response http.ResponseWriter, request *http.Requ
|
||||||
// we only want the single item.
|
// we only want the single item.
|
||||||
mydeveui := deveui[0]
|
mydeveui := deveui[0]
|
||||||
|
|
||||||
|
if (len(mydeveui) != 16) {
|
||||||
|
log.Println("specified 'deveui' has invalid length")
|
||||||
|
fmt.Fprintf(response, "{ \"rc\": 8, \"msg\": \"specified deveui has invalid length\" }")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if !(Contains(getMyDevs(name),mydeveui)) {
|
if !(Contains(getMyDevs(name),mydeveui)) {
|
||||||
log.Println("specified 'deveui' does not belong to this user")
|
log.Println("specified 'deveui' does not belong to this user")
|
||||||
fmt.Fprintf(response, "{ \"rc\": 2, \"msg\": \"specified deveui does not belong to this user\" }")
|
fmt.Fprintf(response, "{ \"rc\": 2, \"msg\": \"specified deveui does not belong to this user\" }")
|
||||||
|
|
@ -40,6 +47,14 @@ func save_scale_settingsHandler(response http.ResponseWriter, request *http.Requ
|
||||||
}
|
}
|
||||||
myalias := alias[0]
|
myalias := alias[0]
|
||||||
|
|
||||||
|
// validate alias
|
||||||
|
match, _ := regexp.MatchString("^[a-zA-Z0-9 ]{1,16}$", myalias)
|
||||||
|
if !(match) {
|
||||||
|
log.Println("Url Param 'alias' is not valid")
|
||||||
|
fmt.Fprintf(response, "{ \"rc\": 9, \"msg\": \"alias is not valid\" }")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
alarmactive, ok3 := request.URL.Query()["alarmactive"]
|
alarmactive, ok3 := request.URL.Query()["alarmactive"]
|
||||||
|
|
||||||
if !ok3 || len(alarmactive[0]) < 1 {
|
if !ok3 || len(alarmactive[0]) < 1 {
|
||||||
|
|
@ -49,6 +64,12 @@ func save_scale_settingsHandler(response http.ResponseWriter, request *http.Requ
|
||||||
}
|
}
|
||||||
myalarmactive := alarmactive[0]
|
myalarmactive := alarmactive[0]
|
||||||
|
|
||||||
|
if !((myalarmactive == "0") || (myalarmactive == "1")) {
|
||||||
|
log.Println("Url Param 'alarmactive' is not valid")
|
||||||
|
fmt.Fprintf(response, "{ \"rc\": 10, \"msg\": \"alarmactive is not valid\" }")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
smsnumber, ok4 := request.URL.Query()["smsnumber"]
|
smsnumber, ok4 := request.URL.Query()["smsnumber"]
|
||||||
|
|
||||||
if !ok4 || len(smsnumber[0]) < 1 {
|
if !ok4 || len(smsnumber[0]) < 1 {
|
||||||
|
|
@ -57,6 +78,14 @@ func save_scale_settingsHandler(response http.ResponseWriter, request *http.Requ
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
mysmsnumber := smsnumber[0]
|
mysmsnumber := smsnumber[0]
|
||||||
|
|
||||||
|
match1, _ := regexp.MatchString(`^\+[0-9]{11,11}$`, mysmsnumber)
|
||||||
|
if !(match1) {
|
||||||
|
log.Println("Url Param 'smsnumber' is not valid")
|
||||||
|
fmt.Fprintf(response, "{ \"rc\": 11, \"msg\": \"smsnumber is not valid, must be in in format +41791234567\" }")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
var mydev Dev
|
var mydev Dev
|
||||||
mydev.Deveui = mydeveui
|
mydev.Deveui = mydeveui
|
||||||
mydev.Alias = myalias
|
mydev.Alias = myalias
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,31 @@
|
||||||
|
{{define "body_content"}}
|
||||||
|
<p class="title is-4">Abos</p>
|
||||||
|
<p>Hier können blablabla...</p>
|
||||||
|
<div class="columns is-marginless">
|
||||||
|
<div class="column is-full"></div>
|
||||||
|
</div>
|
||||||
|
{{ if ne .UserName "" }}
|
||||||
|
{{range .LastMetrics}}
|
||||||
|
<div class="columns is-vcentered is-marginless">
|
||||||
|
<div class="column is-full has-background-primary">
|
||||||
|
<span id="alias_{{.Deveui}}" class="is-size-5">{{.Alias}}</span>
|
||||||
|
<div class="select is-pulled-right is-vcentered">
|
||||||
|
<select class="has-background-light">
|
||||||
|
<option>keine Verlängerung</option>
|
||||||
|
<option>1 Jahr verlängern</option>
|
||||||
|
<option>2 Jahre verlängern</option>
|
||||||
|
<option>3 Jahre verlängern</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="columns">
|
||||||
|
<div class="column is-full"></div>
|
||||||
|
</div>
|
||||||
|
{{end}}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{{ else }}
|
||||||
|
<h4>Bitte zuerst <a href="login.html">einloggen</a></h4>
|
||||||
|
{{end}}
|
||||||
|
{{end}}
|
||||||
|
|
@ -9,9 +9,8 @@
|
||||||
</header>
|
</header>
|
||||||
<section class="modal-card-body">
|
<section class="modal-card-body">
|
||||||
<!-- Content ... -->
|
<!-- Content ... -->
|
||||||
<p id="deveui" hidden></p>
|
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<label id="label" class="label">Bezeichnung (1234567812345678)</label>
|
<label id="label" class="label">Bezeichnung</label>
|
||||||
<div class="control has-icons-right">
|
<div class="control has-icons-right">
|
||||||
<input id="alias" class="input" type="text" maxlength="16">
|
<input id="alias" class="input" type="text" maxlength="16">
|
||||||
<span id="alias_exclamation" class="icon is-small is-right">
|
<span id="alias_exclamation" class="icon is-small is-right">
|
||||||
|
|
@ -40,6 +39,10 @@
|
||||||
</div>
|
</div>
|
||||||
<p id="smsnumber_errormsg" class="help is-danger"></p>
|
<p id="smsnumber_errormsg" class="help is-danger"></p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="is-size-7">
|
||||||
|
Device ID: <span id="deveui"></span>
|
||||||
|
</div>
|
||||||
</section>
|
</section>
|
||||||
<footer class="modal-card-foot">
|
<footer class="modal-card-foot">
|
||||||
<button id="modal-save" class="button is-success">OK</button>
|
<button id="modal-save" class="button is-success">OK</button>
|
||||||
|
|
@ -100,6 +103,12 @@
|
||||||
</nav>
|
</nav>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<p id="paid_until_{{.Deveui}}" class="has-text-centered" style="align-items: center;"><a class="button is-warning is-small" href="/abos.html">
|
||||||
|
<span class="icon">
|
||||||
|
<i class="fa fa-shopping-cart"></i>
|
||||||
|
</span>
|
||||||
|
<span>Abo verlängern (aktiv bis 01.01.1999)</span>
|
||||||
|
</a></p>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -127,9 +136,7 @@ $(".show-modal").click(function() {
|
||||||
var alarmactive = $('#alarmactive_'+deveui).html();
|
var alarmactive = $('#alarmactive_'+deveui).html();
|
||||||
var smsnumber = $('#smsnumber_'+deveui).html();
|
var smsnumber = $('#smsnumber_'+deveui).html();
|
||||||
|
|
||||||
var label = "Bezeichnung (" + deveui + ")";
|
|
||||||
$("#alias").val(alias);
|
$("#alias").val(alias);
|
||||||
$("#label").html(label);
|
|
||||||
console.log(alarmactive);
|
console.log(alarmactive);
|
||||||
if (alarmactive == "1") {
|
if (alarmactive == "1") {
|
||||||
$('#checkbox').prop('checked', true);
|
$('#checkbox').prop('checked', true);
|
||||||
|
|
@ -152,11 +159,12 @@ $("#modal-save").click(function() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validation Code
|
// Validation Code
|
||||||
|
var is_valid = true;
|
||||||
if (!validate('alias',$('#alias').val())) {
|
if (!validate('alias',$('#alias').val())) {
|
||||||
$('#alias_errormsg').html('Ungültige Bezeichnung; erlaubte Zeichen A-Z, 0-9 und Leerschlag');
|
$('#alias_errormsg').html('Ungültige Bezeichnung; erlaubte Zeichen A-Z, 0-9 und Leerschlag');
|
||||||
$("#alias").addClass("is-danger");
|
$("#alias").addClass("is-danger");
|
||||||
$("#alias_exclamation").show();
|
$("#alias_exclamation").show();
|
||||||
return;
|
is_valid = false;
|
||||||
} else {
|
} else {
|
||||||
$('#alias_errormsg').html('');
|
$('#alias_errormsg').html('');
|
||||||
$("#alias").removeClass("is-danger");
|
$("#alias").removeClass("is-danger");
|
||||||
|
|
@ -167,13 +175,17 @@ $("#modal-save").click(function() {
|
||||||
$('#smsnumber_errormsg').html('Beispiel einer gültigen SMS Nummer: +41761234567');
|
$('#smsnumber_errormsg').html('Beispiel einer gültigen SMS Nummer: +41761234567');
|
||||||
$("#smsnumber").addClass("is-danger");
|
$("#smsnumber").addClass("is-danger");
|
||||||
$("#smsnumber_exclamation").show();
|
$("#smsnumber_exclamation").show();
|
||||||
return;
|
is_valid = false;
|
||||||
} else {
|
} else {
|
||||||
$('#smsnumber_errormsg').html('');
|
$('#smsnumber_errormsg').html('');
|
||||||
$("#smsnumber").removeClass("is-danger");
|
$("#smsnumber").removeClass("is-danger");
|
||||||
$("#smsnumber_exclamation").hide();
|
$("#smsnumber_exclamation").hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!(is_valid)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: "save_scale_settings",
|
url: "save_scale_settings",
|
||||||
type: "get", //send it through get method
|
type: "get", //send it through get method
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue