Skip to content
44 changes: 44 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,50 @@ curl --data "username=abc&password=def" localhost:5000/login
curl --header "Auth: <token>" localhost:5000/me
```

## Configuration variables

You can use either commandline flags:
```
{ api } master » ./api -help
Usage of api:
-bind=":5000": Network address used to bind
-classic_registration=false: Classic registration enabled?
-force_colors=false: Force colored prompt?
-log="text": Log formatter type. Either "json" or "text"
-rethinkdb_db="dev": Database name on the RethinkDB server
-rethinkdb_key="": Authentication key of the RethinkDB database
-rethinkdb_url="localhost:28015": Address of the RethinkDB database
-session_duration=72: Session duration expressed in hours
-version="v0": Shown API version
```

Or environment variables:
```
{ api } master » BIND=127.0.0.1:5000 CLASSIC_REGISTRATION=false \
FORCE_COLORS=false LOG=text RETHINKDB_DB=dev RETHINKDB_KEY="" \
RETHINKDB_URL=localhost:28015 SESSION_DURATION=72 VERSION=v0 ./api
```

Or configuration files:
```
{ api } master » cat api.conf
# lines beggining with a "#" character are treated as comments
bind :5000
classic_registration false
force_colors false
log text

rethinkdb_db dev
# configuration values can be empty
rethinkdb_key
# Keys and values can be also seperated by the "=" character
rethinkdb_url=localhost:28015

session_duration=72
version=v0
{ api } master » ./api -config api.conf
```

## Build status:

- `master` - [![Build Status](https://magnum.travis-ci.com/lavab/api.svg?token=kJbppXeTxzqpCVvt4t5X&branch=master)](https://magnum.travis-ci.com/lavab/api)
Expand Down
7 changes: 7 additions & 0 deletions db/table_tokens.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,10 @@ func (t *TokensTable) GetToken(id string) (*models.Token, error) {

return &result, nil
}

// DeleteByOwner deletes all tokens owned by id
func (t *TokensTable) DeleteByOwner(id string) error {
return t.Delete(map[string]interface{}{
"owner": id,
})
}
9 changes: 5 additions & 4 deletions env/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ package env

// Flags contains values of flags which are important in the whole API
type Flags struct {
BindAddress string
APIVersion string
LogFormatterType string
SessionDuration int
BindAddress string
APIVersion string
LogFormatterType string
SessionDuration int
ClassicRegistration bool
}
13 changes: 8 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ var (
logFormatterType = flag.String("log", "text", "Log formatter type. Either \"json\" or \"text\"")
sessionDuration = flag.Int("session_duration", 72, "Session duration expressed in hours")
forceColors = flag.Bool("force_colors", false, "Force colored prompt?")
// Registration settings
classicRegistration = flag.Bool("classic_registration", false, "Classic registration enabled?")
// Database-related flags
rethinkdbURL = flag.String("rethinkdb_url", func() string {
address := os.Getenv("RETHINKDB_PORT_28015_TCP_ADDR")
Expand All @@ -53,10 +55,11 @@ func main() {

// Put config into the environment package
env.Config = &env.Flags{
BindAddress: *bindAddress,
APIVersion: *apiVersion,
LogFormatterType: *logFormatterType,
SessionDuration: *sessionDuration,
BindAddress: *bindAddress,
APIVersion: *apiVersion,
LogFormatterType: *logFormatterType,
SessionDuration: *sessionDuration,
ClassicRegistration: *classicRegistration,
}

// Set up a new logger
Expand Down Expand Up @@ -150,12 +153,12 @@ func main() {
auth.Put("/accounts/:id", routes.AccountsUpdate)
auth.Delete("/accounts/:id", routes.AccountsDelete)
auth.Post("/accounts/:id/wipe-data", routes.AccountsWipeData)
auth.Get("/accounts/:id/sessions", routes.AccountsSessionsList)

// Tokens
auth.Get("/tokens", routes.TokensGet)
mux.Post("/tokens", routes.TokensCreate)
auth.Delete("/tokens", routes.TokensDelete)
auth.Delete("/tokens/:id", routes.TokensDelete)

// Threads
auth.Get("/threads", routes.ThreadsList)
Expand Down
4 changes: 4 additions & 0 deletions models/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ type Account struct {
// * premium: premium account
// * superuser: Lavaboom staff
Type string `json:"type" gorethink:"type"`

AltEmail string `json:"alt_email" gorethink:"alt_email"`

Status string `json:"status" gorethink:"status"`
}

// SetPassword changes the account's password
Expand Down
Loading