summaryrefslogtreecommitdiff
path: root/user/user.go
diff options
context:
space:
mode:
authorVidhu Kant Sharma <vidhukant@vidhukant.xyz>2023-01-29 20:45:43 +0530
committerVidhu Kant Sharma <vidhukant@vidhukant.xyz>2023-01-29 20:45:43 +0530
commit68629768cbb7c86fd4b118e7d555450297f3fb8a (patch)
treee5bb06635ddf50bc58e25bae931ac453a28f844a /user/user.go
parent7ee07197f4fc5806e72a1aefd49c7a448c600cf4 (diff)
moved refresh mechanism to package auth
Diffstat (limited to 'user/user.go')
-rw-r--r--user/user.go23
1 files changed, 13 insertions, 10 deletions
diff --git a/user/user.go b/user/user.go
index 30ae333..6fc6163 100644
--- a/user/user.go
+++ b/user/user.go
@@ -18,12 +18,15 @@
package user
import (
+ "errors"
+ "github.com/MikunoNaka/OpenBills-server/database"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/mongo"
- "github.com/MikunoNaka/OpenBills-server/database"
- "golang.org/x/crypto/bcrypt"
+ "golang.org/x/crypto/bcrypt"
)
+var ErrUserNotFound error = errors.New("user does not exist")
+
var db *mongo.Collection = database.DB.Collection("Users")
// per-user config can be shared to DB
@@ -33,19 +36,19 @@ type Config struct {
}
type Session struct {
- Name string `bson:"Name" json:"Name"`
+ Name string `bson:"Name" json:"Name"`
Token string `bson:"Token" json:"Token"`
}
type User struct {
- Id primitive.ObjectID `bson:"_id,omitempty" json:"Id"`
- UserName string `bson:"UserName" json:"UserName"`
- Email string `bson:"Email" json:"Email"`
- Password string `bson:"Password" json:"Password"`
- Config Config `bson:"Config" json:"Config"`
- Sessions []Session `bson:"Sessions" json:"Sessions"`
+ Id primitive.ObjectID `bson:"_id,omitempty" json:"Id"`
+ UserName string `bson:"UserName" json:"UserName"`
+ Email string `bson:"Email" json:"Email"`
+ Password string `bson:"Password" json:"Password"`
+ Config Config `bson:"Config" json:"Config"`
+ Sessions []Session `bson:"Sessions" json:"Sessions"`
// some actions are only available when email is verified
- Verified bool `bson:"Verified" json:"Verified"`
+ Verified bool `bson:"Verified" json:"Verified"`
}
func (u *User) hashPassword() error {