darkID-prototype/darkID-library-login-example/RESTfunctions.go
darkID-library-login-example/RESTfunctions.goRaw
1package main
2
3import (
4 "encoding/json"
5 "fmt"
6 "net/http"
7
8 "github.com/cryptoballot/rsablind"
9 "github.com/fatih/color"
10
11 "gopkg.in/mgo.v2/bson"
12)
13
14type User struct {
15 Id bson.ObjectId `json:"id" bson:"_id,omitempty"`
16 Email string `json:"email"`
17 Password string `json:"password"`
18 Token string `json:"token"`
19}
20
21func Index(w http.ResponseWriter, r *http.Request) {
22 fmt.Fprintln(w, "clientApp")
23}
24
25func Signup(w http.ResponseWriter, r *http.Request) {
26
27 decoder := json.NewDecoder(r.Body)
28 var user User
29 err := decoder.Decode(&user)
30 if err != nil {
31 panic(err)
32 }
33 defer r.Body.Close()
34
35 fmt.Print("user signup: ")
36 fmt.Println(user)
37
38 jResp, err := json.Marshal(user)
39 if err != nil {
40 panic(err)
41 }
42 fmt.Fprintln(w, string(jResp))
43}
44
45func Login(w http.ResponseWriter, r *http.Request) {
46
47 decoder := json.NewDecoder(r.Body)
48 var key Key
49 err := decoder.Decode(&key)
50 if err != nil {
51 panic(err)
52 }
53 defer r.Body.Close()
54 //TODO check if the user password exists in the database
55
56 fmt.Print("key login: ")
57 fmt.Println(key)
58 token, err := newToken()
59 check(err)
60
61 //validate if the pubK darkID is in the blockchain
62
63 //verify that the darkID is signed
64 if err := rsablind.VerifyBlindSignature(key.ServerVerifier, key.Hashed, key.UnblindedSig); err != nil {
65 fmt.Println(err)
66 } else {
67 color.Green("blind signature verified")
68 }
69
70 /*jResp, err := json.Marshal(token)
71 if err != nil {
72 panic(err)
73 }*/
74 fmt.Fprintln(w, string(token))
75}