Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion routes/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -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_code,omitempty" schema:"invite_code"`
}

// AccountsCreateResponse contains the output of the AccountsCreate request.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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 {
Expand Down
1 change: 0 additions & 1 deletion routes/accounts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down