From dbcf2a1c8c107c26f68f9987ed81a2a4a714ac56 Mon Sep 17 00:00:00 2001 From: Piotr Zduniak Date: Thu, 15 Jan 2015 12:12:03 +0100 Subject: [PATCH 1/3] AccountCreateRequest typo fix --- routes/accounts.go | 2 +- routes/accounts_test.go | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/routes/accounts.go b/routes/accounts.go index 1ada6a8..bce8ead 100644 --- a/routes/accounts.go +++ b/routes/accounts.go @@ -31,7 +31,7 @@ type AccountsCreateRequest struct { Username string `json:"username,omitempty" schema:"username"` Password string `json:"password,omitempty" schema:"password"` AltEmail string `json:"alt_email,omitempty" schema:"alt_email"` - InviteCode string `json:"InviteCode,omitempty" schema:"InviteCode"` + InviteCode string `json:"invite_ode,omitempty" schema:"invite_code"` } // AccountsCreateResponse contains the output of the AccountsCreate request. diff --git a/routes/accounts_test.go b/routes/accounts_test.go index f072dc4..4d70454 100644 --- a/routes/accounts_test.go +++ b/routes/accounts_test.go @@ -7,7 +7,6 @@ import ( "github.com/dchest/uniuri" "github.com/franela/goreq" . "github.com/smartystreets/goconvey/convey" - //"github.com/stretchr/testify/require" "golang.org/x/crypto/sha3" "github.com/lavab/api/env" From 2f1876011934b7a5827c84b0be2aa01f202e4e0c Mon Sep 17 00:00:00 2001 From: Piotr Zduniak Date: Thu, 15 Jan 2015 13:11:31 +0100 Subject: [PATCH 2/3] Another accounts typo --- routes/accounts.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routes/accounts.go b/routes/accounts.go index bce8ead..706e55f 100644 --- a/routes/accounts.go +++ b/routes/accounts.go @@ -31,7 +31,7 @@ type AccountsCreateRequest struct { Username string `json:"username,omitempty" schema:"username"` Password string `json:"password,omitempty" schema:"password"` AltEmail string `json:"alt_email,omitempty" schema:"alt_email"` - InviteCode string `json:"invite_ode,omitempty" schema:"invite_code"` + InviteCode string `json:"invite_code,omitempty" schema:"invite_code"` } // AccountsCreateResponse contains the output of the AccountsCreate request. From bff6305cf8e94248b1e655f4a3a0531c7753a9c5 Mon Sep 17 00:00:00 2001 From: Piotr Zduniak Date: Thu, 15 Jan 2015 14:55:49 +0100 Subject: [PATCH 3/3] Public key updating --- routes/accounts.go | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/routes/accounts.go b/routes/accounts.go index 706e55f..84c73c0 100644 --- a/routes/accounts.go +++ b/routes/accounts.go @@ -429,6 +429,7 @@ type AccountsUpdateRequest struct { FactorValue []string `json:"factor_value" schema:"factor_value"` Token string `json:"token" schema:"token"` Settings interface{} `json:"settings" schema:"settings"` + PublicKey string `json:"public_key" schema:"public_key"` } // AccountsUpdateResponse contains the result of the AccountsUpdate request. @@ -565,6 +566,38 @@ func AccountsUpdate(c web.C, w http.ResponseWriter, r *http.Request) { user.Settings = input.Settings } + if input.PublicKey !+ "" { + key, err:= env.Keys.FindByFingerprint(input.PublicKey) + if err != nil { + env.Log.WithFields(logrus.Fields{ + "error": err.Error(), + "fingerprint": input.PublicKey, + }).Error("Unable to find a key") + + utils.JSONResponse(w, 400, &AccountsUpdateResponse{ + Success: false, + Message: "Invalid public key", + }) + return + } + + if key.Owner != user.ID { + env.Log.WithFields(logrus.Fields{ + "user_id:": user.ID, + "owner": key.Owner, + "fingerprint": input.PublicKey, + }).Error("Unable to find a key") + + utils.JSONResponse(w, 400, &AccountsUpdateResponse{ + Success: false, + Message: "Invalid public key", + }) + return + } + + user.PGPKey = input.PublicKey + } + if input.FactorType != "" { // Check if such factor exists if _, exists := env.Factors[input.FactorType]; !exists {