-
Notifications
You must be signed in to change notification settings - Fork 3
/
account.go
65 lines (53 loc) · 1.4 KB
/
account.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package main
import (
"encoding/json"
"io/ioutil"
"net/http"
"github.com/gorilla/mux"
)
func createAccount(w http.ResponseWriter, req *http.Request) {
vars := mux.Vars(req)
log.Infof("transport: %s, number: %s", vars["sms"], vars["number"])
w.WriteHeader(200)
}
func verifyCode(w http.ResponseWriter, req *http.Request) {
vars := mux.Vars(req)
log.Infof("verification_code: %s", vars["verification_code"])
/*{
"signalingKey" : "{base64_encoded_52_byte_key}",
"supportsSms" : false,
"registrationId" : "{14-bit number}"
}*/
w.WriteHeader(200)
}
type Attributes struct {
AuthKey string `json:"AuthKey"`
FetchesMessages bool `json:"fetchesMessages"`
Voice bool `json:"voice"`
Video bool `json:"video"`
RegistrationID string `json:"registrationId"`
SignalingKey string `json:"signalingKey"`
}
func saveAttributes(w http.ResponseWriter, req *http.Request) {
uname, _, ok := req.BasicAuth()
if !ok {
http.Error(w, "auth fail", 401)
return
}
vars := mux.Vars(req)
log.Infof("number: %s, device_id: %s", vars["number"], vars["device_id"])
body, err := ioutil.ReadAll(req.Body)
if err != nil {
http.Error(w, "server error", 500)
return
}
var attrib Attributes
err = json.Unmarshal(body, &attrib)
if err != nil {
http.Error(w, "server error", 500)
return
}
id := encodeNumber(uname)
writeDB(id[:], []byte("a"), body)
w.WriteHeader(200)
}