-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathhandlers_http.go
More file actions
64 lines (50 loc) · 1.48 KB
/
handlers_http.go
File metadata and controls
64 lines (50 loc) · 1.48 KB
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
// Copyright 2016 Nevio Vesic
// Please check out LICENSE file for more information about limitations
// MIT License
package main
import (
"encoding/json"
"net/http"
"time"
disposable "github.com/0x19/disposable/protos"
log "github.com/Sirupsen/logrus"
"github.com/gorilla/mux"
"golang.org/x/net/context"
)
// HandleVerifyEmail -
func HandleVerifyEmail(s *Service, w http.ResponseWriter, req *http.Request) {
w.Header().Set("Content-Type", "application/json")
vars := mux.Vars(req)
var vreq disposable.DisposableRequest
if err := DecodeRequestBody(&vreq, req.Body); err != nil {
j, derr := json.MarshalIndent(err, "", " ")
if derr != nil {
log.Errorf("[http_handle_verify_email] Unable to decode json into disposable request due to (err: %s)", derr)
http.Error(w, derr.Error(), http.StatusInternalServerError)
return
}
w.WriteHeader(http.StatusBadRequest)
w.Write(j)
return
}
log.Infof("[http_handle_verify_email] Got new email verification request (req_vars: %+v) - (body: %+v)", vars, vreq)
timeout, cancel := context.WithTimeout(context.Background(), time.Second*5)
defer cancel()
accresp, err := s.Verify(timeout, &vreq)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
j, err := json.MarshalIndent(accresp, "", " ")
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
if !accresp.Status {
w.WriteHeader(http.StatusBadRequest)
w.Write(j)
return
}
w.Write(j)
return
}