summaryrefslogtreecommitdiff
path: root/system/db/user.go
diff options
context:
space:
mode:
authorSteve <nilslice@gmail.com>2017-01-16 16:14:00 -0800
committerGitHub <noreply@github.com>2017-01-16 16:14:00 -0800
commit2af951230eddc45ba429cff10d7566ad98fd343b (patch)
tree7543be03fae8aeeacc8eb48dbe16ab2d42fbca0b /system/db/user.go
parent3249b82b2a4f1aa0ae9e6943cd72dd7eebae8a4a (diff)
[core] Adding toggle for CORS, GZIP in admin/cms configuration (#30)
This PR enables admins to disable/enable CORS and GZIP from within the admin CMS configuration page. Both are enabled by default. Note: currently, the GZIP implementation is 100% on the fly, for every qualifying API endpoint request. This could add significant CPU usage, but dramatically decreases bandwidth. Will be considering other better implementations, but for now YMMV. Possible optimizations: - pooling gzip Writers vs. creating a new one for each response - caching gzipped responses (in memory? on disk?) - enforcing size threshold (only gzip content larger than N bytes)
Diffstat (limited to 'system/db/user.go')
-rw-r--r--system/db/user.go20
1 files changed, 19 insertions, 1 deletions
diff --git a/system/db/user.go b/system/db/user.go
index 02fda95..164ae7b 100644
--- a/system/db/user.go
+++ b/system/db/user.go
@@ -26,6 +26,9 @@ func SetUser(usr *user.User) (int, error) {
err := store.Update(func(tx *bolt.Tx) error {
email := []byte(usr.Email)
users := tx.Bucket([]byte("__users"))
+ if users == nil {
+ return bolt.ErrBucketNotFound
+ }
// check if user is found by email, fail if nil
exists := users.Get(email)
@@ -69,6 +72,9 @@ func UpdateUser(usr, updatedUsr *user.User) error {
err := store.Update(func(tx *bolt.Tx) error {
users := tx.Bucket([]byte("__users"))
+ if users == nil {
+ return bolt.ErrBucketNotFound
+ }
// check if user is found by email, fail if nil
exists := users.Get([]byte(usr.Email))
@@ -110,6 +116,10 @@ func UpdateUser(usr, updatedUsr *user.User) error {
func DeleteUser(email string) error {
err := store.Update(func(tx *bolt.Tx) error {
b := tx.Bucket([]byte("__users"))
+ if b == nil {
+ return bolt.ErrBucketNotFound
+ }
+
err := b.Delete([]byte(email))
if err != nil {
return err
@@ -129,6 +139,10 @@ func User(email string) ([]byte, error) {
val := &bytes.Buffer{}
err := store.View(func(tx *bolt.Tx) error {
b := tx.Bucket([]byte("__users"))
+ if b == nil {
+ return bolt.ErrBucketNotFound
+ }
+
usr := b.Get([]byte(email))
_, err := val.Write(usr)
@@ -154,6 +168,10 @@ func UserAll() ([][]byte, error) {
var users [][]byte
err := store.View(func(tx *bolt.Tx) error {
b := tx.Bucket([]byte("__users"))
+ if b == nil {
+ return bolt.ErrBucketNotFound
+ }
+
err := b.ForEach(func(k, v []byte) error {
users = append(users, v)
return nil
@@ -230,7 +248,7 @@ func RecoveryKey(email string) (string, error) {
err := store.View(func(tx *bolt.Tx) error {
b := tx.Bucket([]byte("__recoveryKeys"))
if b == nil {
- return errors.New("No database found for checking keys.")
+ return bolt.ErrBucketNotFound
}
_, err := key.Write(b.Get([]byte(email)))