From 68629768cbb7c86fd4b118e7d555450297f3fb8a Mon Sep 17 00:00:00 2001 From: Vidhu Kant Sharma Date: Sun, 29 Jan 2023 20:45:43 +0530 Subject: moved refresh mechanism to package auth --- user/user.go | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) (limited to 'user/user.go') 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 { -- cgit v1.2.3