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
12 changes: 8 additions & 4 deletions circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ dependencies:
- if [[ ! -e redis-2.8.18/src/redis-server ]]; then wget http://download.redis.io/releases/redis-2.8.18.tar.gz && tar xvzf redis-2.8.18.tar.gz; fi
- if [[ ! -e redis-2.8.18/src/redis-server ]]; then cd redis-2.8.18 && make; fi
- go get github.com/apcera/gnatsd
- go get golang.org/x/tools/cmd/cover
- go get github.com/mattn/goveralls
post:
- rethinkdb --bind all:
background: true
Expand All @@ -25,12 +27,14 @@ dependencies:

test:
override:
- go test -v ./...
- go test -v github.com/lavab/api/setup
- go test -v -covermode=count -coverprofile=coverage.out github.com/lavab/api/routes
- goveralls -coverprofile=coverage.out -service=circleci -repotoken $COVERALLS_TOKEN

deployment:
hub:
branch: master
commands:
- docker login -u $DOCKER_USER -p $DOCKER_PASS https://registry.lavaboom.io
- docker build -t registry.lavaboom.io/api/master
- docker push registry.lavaboom.io/api/master
- docker login -e circleci@lavaboom.io -u $DOCKER_USER -p $DOCKER_PASS https://registry.lavaboom.io
- docker build -t registry.lavaboom.io/lavaboom/api .
- docker push registry.lavaboom.io/lavaboom/api
1 change: 1 addition & 0 deletions env/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ type Flags struct {
APIVersion string
LogFormatterType string
ForceColors bool
EmailDomain string

SessionDuration int
ClassicRegistration bool
Expand Down
2 changes: 2 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ var (
apiVersion = flag.String("api_version", "v0", "Shown API version")
logFormatterType = flag.String("log", "text", "Log formatter type. Either \"json\" or \"text\"")
forceColors = flag.Bool("force_colors", false, "Force colored prompt?")
emailDomain = flag.String("email_domain", "lavaboom.io", "Domain of the default email service")
// Registration settings
sessionDuration = flag.Int("session_duration", 72, "Session duration expressed in hours")
classicRegistration = flag.Bool("classic_registration", false, "Classic registration enabled?")
Expand Down Expand Up @@ -86,6 +87,7 @@ func main() {
APIVersion: *apiVersion,
LogFormatterType: *logFormatterType,
ForceColors: *forceColors,
EmailDomain: *emailDomain,

SessionDuration: *sessionDuration,
ClassicRegistration: *classicRegistration,
Expand Down
42 changes: 21 additions & 21 deletions routes/accounts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ func TestAccountsRoute(t *testing.T) {
Method: "POST",
Uri: server.URL + "/accounts",
ContentType: "application/json",
Body: routes.AccountsCreateRequest{
Username: username,
AltEmail: email,
},
Body: `{
"username": "` + username + `",
"alt_email": "` + email + `"
}`,
}.Do()
So(err, ShouldBeNil)

Expand All @@ -83,10 +83,10 @@ func TestAccountsRoute(t *testing.T) {
Method: "POST",
Uri: server.URL + "/accounts",
ContentType: "application/json",
Body: routes.AccountsCreateRequest{
Username: username,
AltEmail: email,
},
Body: `{
"username": "` + username + `",
"alt_email": "` + email + `"
}`,
}.Do()
So(err, ShouldBeNil)

Expand All @@ -103,10 +103,10 @@ func TestAccountsRoute(t *testing.T) {
Method: "POST",
Uri: server.URL + "/accounts",
ContentType: "application/json",
Body: routes.AccountsCreateRequest{
Username: uniuri.New(),
AltEmail: email,
},
Body: `{
"username": "` + uniuri.New() + `",
"alt_email": "` + email + `"
}`,
}.Do()
So(err, ShouldBeNil)

Expand All @@ -123,10 +123,10 @@ func TestAccountsRoute(t *testing.T) {
Method: "POST",
Uri: server.URL + "/accounts",
ContentType: "application/json",
Body: routes.AccountsCreateRequest{
Username: uniuri.New(),
InviteCode: uniuri.New(),
},
Body: `{
"username": "` + uniuri.New() + `",
"invite_code": "` + uniuri.New() + `"
}`,
}.Do()
So(err, ShouldBeNil)

Expand All @@ -143,10 +143,10 @@ func TestAccountsRoute(t *testing.T) {
Method: "POST",
Uri: server.URL + "/accounts",
ContentType: "application/json",
Body: routes.AccountsCreateRequest{
Username: account.Name,
InviteCode: uniuri.New(),
},
Body: `{
"username": "` + account.Name + `",
"invite_code": "` + uniuri.New() + `"
}`,
}.Do()
So(err, ShouldBeNil)

Expand Down Expand Up @@ -281,7 +281,7 @@ func TestAccountsRoute(t *testing.T) {
Body: routes.AccountsCreateRequest{
Username: account.Name,
InviteCode: verificationToken.ID,
Password: "c0067d4af4e87f00dbac63b6156828237059172d1bbeac67427345d6a9fda484",
Password: "d0cfc2e5319b82cdc71a33873e826c93d7ee11363f8ac91c4fa3a2cfcd2286e5",
},
}.Do()

Expand Down
17 changes: 17 additions & 0 deletions routes/emails.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,26 @@ func EmailsCreate(c web.C, w http.ResponseWriter, r *http.Request) {
return
}

// Fetch the user object from the database
account, err := env.Accounts.GetTokenOwner(c.Env["token"].(*models.Token))
if err != nil {
// The session refers to a non-existing user
env.Log.WithFields(logrus.Fields{
"id": session.ID,
"error": err.Error(),
}).Warn("Valid session referred to a removed account")

utils.JSONResponse(w, 410, &EmailsCreateResponse{
Success: false,
Message: "Account disabled",
})
return
}

// Create a new email struct
email := &models.Email{
Kind: "sent",
From: []string{account.Name + "@" + env.Config.EmailDomain},
To: input.To,
Resource: models.MakeResource(session.Owner, input.Subject),
AttachmentIDs: input.Attachments,
Expand Down