2018-12-18 08:23:12 +00:00
|
|
|
package main
|
2018-12-05 20:03:40 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"database/sql"
|
2018-12-18 08:23:12 +00:00
|
|
|
"fmt"
|
2018-12-05 20:03:40 +00:00
|
|
|
_ "github.com/lib/pq"
|
2018-12-18 08:23:12 +00:00
|
|
|
"io/ioutil"
|
2018-12-05 20:03:40 +00:00
|
|
|
"log"
|
2018-12-18 08:23:12 +00:00
|
|
|
"net/http"
|
|
|
|
"os"
|
2018-12-05 20:03:40 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func crash(err error) {
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
db, err := sql.Open("postgres", os.Getenv("DB"))
|
|
|
|
crash(err)
|
|
|
|
|
2018-12-05 20:48:20 +00:00
|
|
|
http.HandleFunc("/helper/verification-code", func(w http.ResponseWriter, r *http.Request) {
|
2019-01-08 22:22:23 +00:00
|
|
|
account := r.PostFormValue("number")
|
2018-12-05 20:03:40 +00:00
|
|
|
var code string
|
|
|
|
err := db.QueryRow("SELECT verification_code FROM pending_accounts WHERE number = $1", account).Scan(&code)
|
2018-12-19 00:35:27 +00:00
|
|
|
log.Printf("Looking for verification code for %s", account)
|
2018-12-18 08:23:12 +00:00
|
|
|
if err != nil {
|
2019-01-08 22:15:04 +00:00
|
|
|
panic(err)
|
2018-12-18 08:23:12 +00:00
|
|
|
} else {
|
|
|
|
fmt.Fprintf(w, "%s\n", code)
|
2018-12-18 08:20:55 +00:00
|
|
|
}
|
2018-12-05 20:03:40 +00:00
|
|
|
})
|
2018-12-05 21:04:52 +00:00
|
|
|
|
2018-12-05 21:19:28 +00:00
|
|
|
http.HandleFunc("/v1/directory/reconcile", func(w http.ResponseWriter, r *http.Request) {
|
2018-12-18 08:23:12 +00:00
|
|
|
_, err := ioutil.ReadAll(r.Body)
|
2018-12-05 21:49:32 +00:00
|
|
|
defer r.Body.Close()
|
|
|
|
crash(err)
|
2018-12-05 22:02:49 +00:00
|
|
|
w.Header().Set("Content-Type", "application/json")
|
|
|
|
w.Write([]byte("{\"status\": \"OK\"}\n"))
|
2018-12-05 21:04:52 +00:00
|
|
|
})
|
2018-12-05 20:03:40 +00:00
|
|
|
log.Fatal(http.ListenAndServe(":8082", nil))
|
|
|
|
}
|